Shuffy

不断的学习,不断的思考,才能不断的进步.Let's do better together!
posts - 102, comments - 43, trackbacks - 0, articles - 19

《基于MFC的OpenGL编程》Part 14 Quadrics

Posted on 2010-03-31 20:49 Shuffy 阅读(211) 评论(0)  编辑 收藏 引用 所属分类: MFC,OpenGL
      本文在11篇文章的基础上,为其加入显示各种二次曲面的代码;

      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类中加入下列变量,用来表示二次曲面类型:

    //Quadric
    GLuint m_Quadric;

2,加入四个控制二次曲面类型的菜单项及其事件处理函数

void CCY457OpenGLView::OnQuadricSphere() 
{
//球体
    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,绘制函数修改如下:

void CCY457OpenGLView::RenderScene ()
{
//绘制函数
        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, 12020);
                    
break;
            
case 1:    gluCylinder(obj, 1132020);
                    
break;
            
case 2: gluCylinder(obj, 0.1132020);
                    
break;
            
case 3: gluDisk(obj, 0.512020);
                    
break;
            
case 4: gluPartialDisk(obj, 0.51202010180);
                    
break;
        }
        glDisable(GL_TEXTURE_2D);
}

 

作者:洞庭散人

出处:http://phinecos.cnblogs.com/    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文链接:http://www.cnblogs.com/phinecos/archive/2008/11/06/1328269.html

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理