2011-12-18 34 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