Week04 閻覃的上課筆記
三個重要英文單詞
旋轉 Rotate
移動 Translate
縮放 Scale
測試移動函式
通過測試程式可以得出三個參數的含義。

移動茶壺
主要函式:
1//清空畫面2extern void glClear(GLbitfield mask)3//mask使用以下常量即可456//將矩陣入棧出棧(備份還原)7extern void glPushMatrix(void)8extern void glPopMatrix(void)9//移動茶壺10extern void glTranslatef(GLfloat x, GLfloat y, GLfloat z)程式碼:
1static void display(void) {23 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);4 glPushMatrix();5 {6 glTranslatef(_x, 0, 0);7 glutSolidTeapot(0.3);8 }9 glPopMatrix();10 glutSwapBuffers();//交換雙緩存區11}
用滑鼠移動茶壺(Translate)
原理和上週控制小精靈的嘴巴一樣。
不過,這裡要進行坐標系統的變換。
1float mouseX,mouseY;23static void display(void) {45 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);6 glPushMatrix();7 {8 glTranslatef((mouseX-250) / 250.0f,-(mouseY-250) / 250.0f, 0);9 //坐標系統的變換10 glutSolidTeapot(0.3);11 }12 glPopMatrix();13 glutSwapBuffers();//交換雙緩存區14}1516void motion(int x, int y) {17 mouseX = x;18 mouseY = y;19 glutPostRedisplay();//重畫畫面20}用滑鼠縮放茶壺(Scale)
重要函式:
1extern void glScalef(GLfloat x, GLfloat y, GLfloat z)2//縮放程式碼中將原來的glTranslatef替換為glScalef就可以了。
運行后會發現,什麼鬼東西?

沒有留言:
張貼留言