3DTeapot.cpp
资源名称:Jhy3D.rar [点击查看]
上传用户:eehhbb
上传日期:2022-08-03
资源大小:2550k
文件大小:2k
源码类别:
OpenGL
开发平台:
Visual C++
- // 3DTeapot.cpp: implementation of the C3DTeapot class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Jhy3D.h"
- #include "3DTeapot.h"
- #include "glglut.h"
- #include "Material.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- C3DTeapot::C3DTeapot()
- {
- m_fRoundRadius = 0.4f;
- m_position.m_x=0.0f;
- m_position.m_y=0.0f;
- m_position.m_z=0.0f;
- }
- C3DTeapot::~C3DTeapot()
- {
- }
- void C3DTeapot::DrawWireTeapot()
- {
- if(m_fRoundRadius <= 0)
- {
- return;
- }
- // glMatrixMode(GL_MODELVIEW);
- // glMatrixMode(GL_PROJECTION); //具体操作在onSize函数中
- glColor3f(0.8f,0.3f,0.8f);
- glPushMatrix();
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- glutWireTeapot(m_fRoundRadius);
- glPopMatrix();
- }
- void C3DTeapot::RenderLightSolidTeapot()
- {
- if (m_fRoundRadius <= 0)
- return;
- glMaterialfv(GL_FRONT,GL_AMBIENT,m_matTeapot.m_vAmbient);
- glMaterialfv(GL_FRONT,GL_DIFFUSE,m_matTeapot.m_vDiffuse);
- glMaterialfv(GL_FRONT,GL_SPECULAR,m_matTeapot.m_vSpecular);
- glMaterialf(GL_FRONT,GL_SHININESS,m_matTeapot.m_vShininess);
- glMaterialfv(GL_FRONT,GL_EMISSION,m_matTeapot.m_vEmission);
- glPushMatrix();
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- // glColor3f(0.8f,0.3f,0.8f);
- glutSolidTeapot(m_fRoundRadius);
- glPopMatrix();
- }
- void C3DTeapot::RenderWireTeapot()
- {
- if(m_fRoundRadius <= 0)
- return;
- glColor3f(m_matTeapot.m_vDiffuse[0],m_matTeapot.m_vDiffuse[1],m_matTeapot.m_vDiffuse[2]);
- glPushMatrix();
- glTranslatef(m_position.m_x,m_position.m_y,m_position.m_z);
- // glColor3f(0.8f,0.3f,0.8f);
- glutWireTeapot(m_fRoundRadius);
- glPopMatrix();
- }