2011-12-18 56 views
0

我希望你可以帮我一个小问题...静态圈在OpenGL

我知道如何画一个圆,这不是一个问题 - 在这里是在C#代码

void DrawEllipse() 
{ 
    GL.Color3(0.5, 0.6, 0.2); 
    float x, y, z; 
    double t; 
    GL.Begin(BeginMode.Points); 
    for (t = 0; t <= 360; t += 0.25) 
    { 
     x = (float)(3*Math.Sin(t)); 
     y = (float)(3*Math.Cos(t)); 
     z = (float)0; 
     GL.Vertex3(x, y, z); 
    } 
    GL.End(); 

} 

但有一个问题 - 当我旋转'Gl.Rotate(角度,轴)',然后重画一个圆 - 是的,它仍然是3D中的圆,但我想在屏幕上有一个圆圈 - 我的意思是静态圆在3D物体中旋转......这可能吗?如何修复代码?

+0

我现在,谢谢你的帮助;-) – 159753 2011-12-18 10:30:00

回答

0

就绘制在照相机前的位置! 使用pushMatrix()popMatrix()

或者你可以画pushMatrix()popMatrix()之间的其他事情。然后绘制圆圈。

+0

也许这是一个很好的帮助把DrawEllipse()放在代码的不同部分,非常感谢:-) – 159753 2011-12-18 10:27:44

1

你想画一个圆圈2D在3D场景的顶部创建一个HUD或类似的?如果你是,那么你应该研究2D的OpenGL,glOrtho并在场景中使用多个视口。周围有此这里讨论: http://www.gamedev.net/topic/388298-opengl-hud/

+0

thx,我现在拥有它:) – 159753 2011-12-18 10:29:35

0

HUD(抬头显示器):http://en.wikipedia.org/wiki/HUD_(video_gaming

void setupScene() 
{ 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 

    // set the perspective 
    glFrustum(...) // or glu's perspective 
} 


void loop() 
{ 
    // main scene 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    glViewport (...) 
    // push the camera position into GL_MODELVIEW 
    // (i.e. the inverse matrix of its object position) 

    // draw your normal 3D objects 


    // switch to 2D projection (for the HUD) 
    glMatrixMode(GL_PROJECTION); 
    glPushMatrix(); 
    glLoadIdentity(); 
    glOrtho(....) 

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    // draw the objects onto the HUD 

    // switch back to 3d projection (i.e. restore GL_PROJECTION) 
    // glEnable (GL_DEPTH_TEST); 
    glMatrixMode(GL_PROJECTION); 
    glPopMatrix(); 
    // glMatrixMode(GL_MODELVIEW); 

    // swap buffers 
} 

注释代码是可选的,这取决于你怎么办到底。把它作为提示。

+0

它意味着将DrawEllipse(或圆圈)放在代码的不同部分,我试图找到位置,并且我成功了,感谢您的帮助和想法;-) – 159753 2011-12-18 10:29:25