3DBox.cpp
资源名称:Jhy3D.rar [点击查看]
上传用户:eehhbb
上传日期:2022-08-03
资源大小:2550k
文件大小:6k
源码类别:
OpenGL
开发平台:
Visual C++
- // 3DBox.cpp: implementation of the C3DBox class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "jhy3d.h"
- #include "3DBox.h"
- #include "Material.h"
- #include "glglut.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- C3DBox::C3DBox()
- {
- }
- C3DBox::~C3DBox()
- {
- }
- void C3DBox::Draw3dBox()
- {
- glBegin(GL_QUADS); // 开始绘制立方体
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- /*
- glNormal3f(0.0f,1.0f,0.0f);
- glVertex3f( 0.7f, 0.5f,-0.5f); // 四边形的右上顶点 (顶面)
- glVertex3f(-0.7f, 0.5f,-0.5f); // 四边形的左上顶点 (顶面)
- glVertex3f(-0.7f, 0.5f, 0.5f); // 四边形的左下顶点 (顶面)
- glVertex3f( 0.7f, 0.5f, 0.5f); // 四边形的右下顶点 (顶面)
- glNormal3f(0.0f,-1.0f,0.0f);
- glVertex3f( 0.7f,-0.5f, 0.5f); // 四边形的右上顶点(底面)
- glVertex3f(-0.7f,-0.5f, 0.5f); // 四边形的左上顶点(底面)
- glVertex3f(-0.7f,-0.5f,-0.5f); // 四边形的左下顶点(底面)
- glVertex3f( 0.7f,-0.5f,-0.5f); // 四边形的右下顶点(底面)
- glNormal3f(0.0f,0.0f,1.0f);
- glVertex3f( 0.7f, 0.5f, 0.5f); // 四边形的右上顶点(前面)
- glVertex3f(-0.7f, 0.5f, 0.5f); // 四边形的左上顶点(前面)
- glVertex3f(-0.7f,-0.5f, 0.5f); // 四边形的左下顶点(前面)
- glVertex3f( 0.7f,-0.5f, 0.5f); // 四边形的右下顶点(前面)
- glNormal3f(0.0f,0.0f,-1.0f);
- glVertex3f( 0.7f,-0.5f,-0.5f); // 四边形的右上顶点(后面)
- glVertex3f(-0.7f,-0.5f,-0.5f); // 四边形的左上顶点(后面)
- glVertex3f(-0.7f, 0.5f,-0.5f); // 四边形的左下顶点(后面)
- glVertex3f( 0.7f, 0.5f,-0.5f); // 四边形的右下顶点(后面)
- glNormal3f(-1.0f,0.0f,0.0f);
- glVertex3f(-0.7f, 0.5f, 0.5f); // 四边形的右上顶点(左面)
- glVertex3f(-0.7f, 0.5f,-0.5f); // 四边形的左上顶点(左面)
- glVertex3f(-0.7f,-0.5f,-0.5f); // 四边形的左下顶点(左面)
- glVertex3f(-0.7f,-0.5f, 0.5f); // 四边形的右下顶点(左面)
- glNormal3f(1.0f,0.0f,0.0f);
- glVertex3f( 0.7f, 0.5f,-0.5f); // 四边形的右上顶点(右面)
- glVertex3f( 0.7f, 0.5f, 0.5f); // 四边形的左上顶点(右面)
- glVertex3f( 0.7f,-0.5f, 0.5f); // 四边形的左下顶点(右面)
- glVertex3f( 0.7f,-0.5f,-0.5f); // 四边形的右下顶点(右面)
- glEnd(); // 立方体绘制结束
- */
- glNormal3f(0.0f,1.0f,0.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[1].m_z);// 四边形的右上顶点(顶面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[1].m_z);// 四边形的左上顶点(顶面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[0].m_z); // 四边形的左下顶点(顶面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[0].m_z);// 四边形的右下顶点(顶面)
- glNormal3f(0.0f,-1.0f,0.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f( m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的右上顶点(底面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的左上顶点(底面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的左下顶点(底面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的右下顶点(底面)
- glNormal3f(0.0f,0.0f,1.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[0].m_z); // 四边形的右上顶点(前面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[0].m_z); // 四边形的左上顶点(前面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的左下顶点(前面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的右下顶点(前面)
- glNormal3f(0.0f,0.0f,-1.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的右上顶点(后面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的左上顶点(后面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[1].m_z); // 四边形的左下顶点(后面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[1].m_z); // 四边形的右下顶点(后面)
- glNormal3f(-1.0f,0.0f,0.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[0].m_z); // 四边形的右上顶点(左面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[0].m_y,m_vBox[1].m_z); // 四边形的左上顶点(左面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的左下顶点(左面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[1].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的右下顶点(左面)
- glNormal3f(1.0f,0.0f,0.0f);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[1].m_z); // 四边形的右上顶点(右面)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[0].m_y,m_vBox[0].m_z); // 四边形的左上顶点(右面)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[0].m_z); // 四边形的左下顶点(右面)
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(m_vBox[0].m_x,m_vBox[1].m_y,m_vBox[1].m_z); // 四边形的右下顶点(右面)
- glEnd(); // 立方体绘制结束
- }
- void C3DBox::RenderLightSolid3dBox()
- {
- glMaterialfv(GL_FRONT,GL_AMBIENT,m_matBox.m_vAmbient);
- glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matBox.m_vDiffuse);
- glMaterialfv(GL_FRONT,GL_SPECULAR,m_matBox.m_vSpecular);
- glMaterialf(GL_FRONT,GL_SHININESS,m_matBox.m_vShininess);
- glMaterialfv(GL_FRONT,GL_EMISSION,m_matBox.m_vEmission);
- glPushMatrix();
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- Draw3dBox();
- glPopMatrix();
- }