3DPolygon.cpp
资源名称:Jhy3D.rar [点击查看]
上传用户:eehhbb
上传日期:2022-08-03
资源大小:2550k
文件大小:2k
源码类别:
OpenGL
开发平台:
Visual C++
- // 3DPolygon.cpp: implementation of the C3DPolygon class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Jhy3D.h"
- #include "3DPolygon.h"
- #include "Vector3.h"
- #include "glglut.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- C3DPolygon::C3DPolygon()
- {
- m_ptVertices[0].m_x = -1.0f;
- m_ptVertices[0].m_y = 0.0f;
- m_ptVertices[0].m_z = 0.0f;
- m_ptVertices[1].m_x = 0.0f;
- m_ptVertices[1].m_y = 1.0f;
- m_ptVertices[1].m_z = 0.0f;
- m_ptVertices[2].m_x = 1.0f;
- m_ptVertices[2].m_y = 0.0f;
- m_ptVertices[2].m_z = 0.0f;
- m_ptVertices[3].m_x = 0.0f;
- m_ptVertices[3].m_y = 0.3f;
- m_ptVertices[3].m_z = 1.0f;
- m_color = RGB(128,234,222);
- }
- C3DPolygon::~C3DPolygon()
- {
- }
- //填充3D多边形
- void C3DPolygon::DrawSolidPolygonwithOpenGL()
- {
- glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
- glDisable(GL_TEXTURE_2D);
- glBegin(GL_POLYGON);
- glColor3f(0.8,0.8f,0.8f);
- glVertex3f(m_ptVertices[0].m_x,m_ptVertices[0].m_y,m_ptVertices[0].m_z);
- glVertex3f(m_ptVertices[1].m_x,m_ptVertices[1].m_y,m_ptVertices[1].m_z);
- glVertex3f(m_ptVertices[2].m_x,m_ptVertices[2].m_y,m_ptVertices[2].m_z);
- glVertex3f(m_ptVertices[3].m_x,m_ptVertices[3].m_y,m_ptVertices[3].m_z);
- glEnd();
- }
- //绘制线框多边形
- void C3DPolygon::DrawWirePolygonwithOpenGL()
- {
- glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
- glDisable(GL_TEXTURE_2D);
- glBegin(GL_POLYGON);
- glColor3f(0.8,0.8f,0.8f);
- glVertex3f(m_ptVertices[0].m_x,m_ptVertices[0].m_y,m_ptVertices[0].m_z);
- glVertex3f(m_ptVertices[1].m_x,m_ptVertices[1].m_y,m_ptVertices[1].m_z);
- glVertex3f(m_ptVertices[2].m_x,m_ptVertices[2].m_y,m_ptVertices[2].m_z);
- glVertex3f(m_ptVertices[3].m_x,m_ptVertices[3].m_y,m_ptVertices[3].m_z);
- glEnd();
- }