Transformations - Translation, Rotation and Scaling
Translation is nothing but moving along an arbitrary axis. Rotation is spinning about an arbitrary axis. Scaling is increase or decrease in size along an arbitrary axis. One important point to remember is that OpenGL uses a right hand coordinate system where Z-ve goes into the Screen. An object said to be undergoing a transformation could be undergoing a translation, rotation and/or scaling. Understanding how different types of transformations work together is very important.
本文將對地球進行建模,讓其圍繞著太陽,此外它還會有月球伴隨,而在下文中將會加入對鼠標和鍵盤的事件響應機制。
繪制代碼
void CCY457OpenGLView::RenderScene ()
{//繪制函數
//Draw Sun
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(6,1.0f,0.0f,0.0f);
glutWireSphere(1.0f,20,20);
//Draw Planet
glPushMatrix();
glTranslatef(-1.2f,-0.5f,-2.0f);
glRotatef(6,1.0f,0.0f,0.0f);
glutWireSphere(0.5f,20,20);
//Draw Moon
glPushMatrix();
glTranslatef(-1.2f,-0.5f,-2.0f);
glRotatef(6,1.0f,0.0f,0.0f);
glutWireSphere(0.05f,20,20);
glPopMatrix();
glPopMatrix();
}
原文鏈接:
http://www.cnblogs.com/phinecos/archive/2008/11/05/1327417.html