2012-08-28 8 views
1

我畫一個實心球像如下:如何在OpenGL中獲得變換座標?

glPushMatrix(); 
    glScalef(0.015, 0.015, 0.015); 
    glRotatef(90, 1.0, 0.0, 0.0); 
    glTranslatef(0.0, 200, 0.0); 
    glRotatef(-20, 0.0, 0.0, 1.0); 
    glRotatef(-20, 1.0, 0.0, 0.0); 
    glTranslatef(78.75, -110.74, -13.53); 
    glutSolidSphere(4.0f,15,15); 
glPopMatrix(); 

我怎樣才能得到這個實心球的變換座標?

+1

你是新手OpenGL程序員嗎? –

+0

您正在使用原有的「紅皮書」時代OpenGL編程模型,該模型已被更好的技術所取代。正因爲如此,您在互聯網上找到的大多數教程都會向您展示如何以一種已被棄用很久的方式來做事。我建議你得到「OpenGL Shading Language(3rd Edition,2009)」http://tinyurl.com/c5fpaw6它不僅給程序員使用的方法提供了入門知識(使用着色器),它還具有顯示事物過去常用「固定功能」流水線完成,以及如何使用着色器完成等效功能。 –

回答

-1

您可以通過功能glget獲取狀態變量GL_MODELVIEW_MATRIX

它從ModelView堆棧返回當前矩陣。我認爲那是你需要的。

+0

好吧。他想要變換的座標,所以在得到矩陣之後,他必須對球體的座標進行變換。 –

+0

基督徒,你是對的。你能讓我知道如何得到它嗎? –

+0

糾正我,如果我錯了,但我不認爲這會對初學OpenGL程序員有用。 – Oskar

-1

將轉換後的座標放入變量中,則不必檢索變形的形狀座標。

float solidSphereX = whatever; 
float solidSphereY = whatever; 
float solidSphereZ = whatever; 
float solidSphereRotationX = whatever in radians; 
float solidSphereRotationY = whatever in radians; 
float solidSphereRotationZ = whatever in radians; 
... 
glPushMatrix(); 
glRotatef(solidSphereRotationX, solidSphereRotationY, solidSphereRotationZ); 
glTranslatef(solidSphereX, solidSphereY, solidSphereZ); 
glPopMatrix();