《基于MFC的OpenGL编程》Part 14 Quadrics
Quadrics
Every quadric has a few settings associated with it. We have to create a quadric first and then customize its settings to render the shape we want. The gluNewQuadric function creates a state variable that describes the current drawing style, orientation, lighting mode, texturing mode and the callback functions. Once we use this function to create a new quadric, we can customize the drawing of shapes by changing its state using functions such as
gluQuadricDrawStyle - which selects the type of OpenGL drawing primitives that are used to drw the shape.
gluQuadricOrientation - which controls the direction of the lighting normals.
gluQuadricNormals - which controls the generation of lighting normals.
gluQuadricTexture - which generates texture coordinates automatically for the quadric.
1,在CCY457OpenGLView类中加入下列变量,用来表示二次曲面类型:
GLuint m_Quadric;
2,加入四个控制二次曲面类型的菜单项及其事件处理函数
{//球体
m_Quadric = 0;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateQuadricSphere(CCmdUI* pCmdUI)
{
if(m_Quadric == 0)
pCmdUI->SetRadio(TRUE);
else
pCmdUI->SetRadio(FALSE);
}
void CCY457OpenGLView::OnQuadricCone()
{//圆锥
m_Quadric = 2;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateQuadricCone(CCmdUI* pCmdUI)
{
if(m_Quadric == 2)
pCmdUI->SetRadio(TRUE);
else
pCmdUI->SetRadio(FALSE);
}
void CCY457OpenGLView::OnQuadricCylinder()
{//柱体
m_Quadric = 1;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateQuadricCylinder(CCmdUI* pCmdUI)
{
if(m_Quadric == 1)
pCmdUI->SetRadio(TRUE);
else
pCmdUI->SetRadio(FALSE);
}
void CCY457OpenGLView::OnQuadricDisk()
{//圆盘
m_Quadric = 3;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateQuadricDisk(CCmdUI* pCmdUI)
{
if(m_Quadric == 3)
pCmdUI->SetRadio(TRUE);
else
pCmdUI->SetRadio(FALSE);
}
void CCY457OpenGLView::OnQuadricPartialdisk()
{////半圆盘
m_Quadric = 4;
InvalidateRect(NULL,FALSE);
}
void CCY457OpenGLView::OnUpdateQuadricPartialdisk(CCmdUI* pCmdUI)
{
if(m_Quadric == 4)
pCmdUI->SetRadio(TRUE);
else
pCmdUI->SetRadio(FALSE);
}
3,绘制函数修改如下:
{//绘制函数
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(m_xRot,1.0f,0.0f,0.0f);
glRotatef(m_yRot,0.0f,1.0f,0.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_Texture[0]);
GLUquadricObj* obj;
obj = gluNewQuadric();
gluQuadricNormals(obj, GLU_SMOOTH);
gluQuadricTexture(obj, GL_TRUE);
switch(m_Quadric)
{
case 0: gluSphere(obj, 1, 20, 20);
break;
case 1: gluCylinder(obj, 1, 1, 3, 20, 20);
break;
case 2: gluCylinder(obj, 0.1, 1, 3, 20, 20);
break;
case 3: gluDisk(obj, 0.5, 1, 20, 20);
break;
case 4: gluPartialDisk(obj, 0.5, 1, 20, 20, 10, 180);
break;
}
glDisable(GL_TEXTURE_2D);
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
posted on 2008-11-06 17:12 Phinecos(洞庭散人) 阅读(2778) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述