3DPolygon.cpp
上传用户:eehhbb
上传日期:2022-08-03
资源大小:2550k
文件大小:2k
源码类别:

OpenGL

开发平台:

Visual C++

  1. // 3DPolygon.cpp: implementation of the C3DPolygon class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Jhy3D.h"
  6. #include "3DPolygon.h"
  7. #include "Vector3.h"
  8. #include "glglut.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. #define new DEBUG_NEW
  13. #endif
  14. //////////////////////////////////////////////////////////////////////
  15. // Construction/Destruction
  16. //////////////////////////////////////////////////////////////////////
  17. C3DPolygon::C3DPolygon()
  18. {
  19. m_ptVertices[0].m_x = -1.0f;
  20. m_ptVertices[0].m_y = 0.0f;
  21. m_ptVertices[0].m_z = 0.0f;
  22. m_ptVertices[1].m_x = 0.0f;
  23. m_ptVertices[1].m_y = 1.0f;
  24. m_ptVertices[1].m_z = 0.0f;
  25. m_ptVertices[2].m_x = 1.0f;
  26. m_ptVertices[2].m_y = 0.0f;
  27. m_ptVertices[2].m_z = 0.0f;
  28. m_ptVertices[3].m_x = 0.0f;
  29. m_ptVertices[3].m_y = 0.3f;
  30. m_ptVertices[3].m_z = 1.0f;
  31. m_color = RGB(128,234,222);
  32. }
  33. C3DPolygon::~C3DPolygon()
  34. {
  35. }
  36. //填充3D多边形
  37. void C3DPolygon::DrawSolidPolygonwithOpenGL()
  38. {
  39. glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  40. glDisable(GL_TEXTURE_2D);
  41. glBegin(GL_POLYGON);
  42.     glColor3f(0.8,0.8f,0.8f);
  43. glVertex3f(m_ptVertices[0].m_x,m_ptVertices[0].m_y,m_ptVertices[0].m_z);
  44.     glVertex3f(m_ptVertices[1].m_x,m_ptVertices[1].m_y,m_ptVertices[1].m_z);
  45. glVertex3f(m_ptVertices[2].m_x,m_ptVertices[2].m_y,m_ptVertices[2].m_z);
  46. glVertex3f(m_ptVertices[3].m_x,m_ptVertices[3].m_y,m_ptVertices[3].m_z);
  47. glEnd();
  48.  
  49. }
  50. //绘制线框多边形
  51. void C3DPolygon::DrawWirePolygonwithOpenGL()
  52. {
  53. glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
  54. glDisable(GL_TEXTURE_2D);
  55. glBegin(GL_POLYGON);
  56.     glColor3f(0.8,0.8f,0.8f);
  57. glVertex3f(m_ptVertices[0].m_x,m_ptVertices[0].m_y,m_ptVertices[0].m_z);
  58.     glVertex3f(m_ptVertices[1].m_x,m_ptVertices[1].m_y,m_ptVertices[1].m_z);
  59. glVertex3f(m_ptVertices[2].m_x,m_ptVertices[2].m_y,m_ptVertices[2].m_z);
  60. glVertex3f(m_ptVertices[3].m_x,m_ptVertices[3].m_y,m_ptVertices[3].m_z);
  61. glEnd();
  62. }