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

OpenGL

开发平台:

Visual C++

  1. // 3DTeapot.cpp: implementation of the C3DTeapot class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Jhy3D.h"
  6. #include "3DTeapot.h"
  7. #include "glglut.h"
  8. #include "Material.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. C3DTeapot::C3DTeapot()
  18. {
  19. m_fRoundRadius = 0.4f;
  20. m_position.m_x=0.0f;
  21. m_position.m_y=0.0f;
  22. m_position.m_z=0.0f;
  23. }
  24. C3DTeapot::~C3DTeapot()
  25. {
  26. }
  27. void C3DTeapot::DrawWireTeapot()
  28. {
  29. if(m_fRoundRadius <= 0)
  30. {
  31. return;
  32. }
  33. // glMatrixMode(GL_MODELVIEW);
  34. // glMatrixMode(GL_PROJECTION); //具体操作在onSize函数中
  35. glColor3f(0.8f,0.3f,0.8f);
  36. glPushMatrix();
  37. glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
  38. glutWireTeapot(m_fRoundRadius);
  39. glPopMatrix();
  40. }
  41. void C3DTeapot::RenderLightSolidTeapot()
  42. {
  43. if (m_fRoundRadius <= 0)
  44. return;
  45. glMaterialfv(GL_FRONT,GL_AMBIENT,m_matTeapot.m_vAmbient);
  46. glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matTeapot.m_vDiffuse);
  47. glMaterialfv(GL_FRONT,GL_SPECULAR,m_matTeapot.m_vSpecular);
  48. glMaterialf(GL_FRONT,GL_SHININESS,m_matTeapot.m_vShininess);
  49. glMaterialfv(GL_FRONT,GL_EMISSION,m_matTeapot.m_vEmission);
  50. glPushMatrix();
  51. glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
  52. // glColor3f(0.8f,0.3f,0.8f);
  53. glutSolidTeapot(m_fRoundRadius);
  54. glPopMatrix();
  55. }
  56. void C3DTeapot::RenderWireTeapot()
  57. {
  58. if(m_fRoundRadius <= 0)
  59. return;
  60. glColor3f(m_matTeapot.m_vDiffuse[0],m_matTeapot.m_vDiffuse[1],m_matTeapot.m_vDiffuse[2]);
  61. glPushMatrix();
  62. glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
  63. // glColor3f(0.8f,0.3f,0.8f);
  64. glutWireTeapot(m_fRoundRadius);
  65. glPopMatrix();
  66. }