
首先是先開啟檔案複習上禮拜的旋轉!
已經試著去了解以及嘗試縮放和移動車子。
-------------------------------------------------------------------------------------------------------------------------
以下開始WEEK 5 正課

Translate 在上 rotate下 =正中心旋轉 (由下往上讀) (先旋轉再移動)

Rotate上 translate 下 =圓心旋轉~ (先移動在旋轉~)
---------------------------------------------------------------------------------------------------------------
使用Codeblack
把translate跟rotate 交換 所以會從自轉變成公轉

進化成茶壺機器人
(以下是程式碼)
#include <stdio.h>
#include <GL/glut.h>
float angle=0;///旋轉角度
void motion(int x,int y)///mouse motion拖著移動時,會叫motion()
{
angle=x;///老師用上週比較差的方法,直接把mouse座標,變轉動角度
glutPostRedisplay();///讀畫面重畫
}
void display()///畫面要display時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glutSolidTeapot(0.3);///中間的身體
glPushMatrix();///上右手臂
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下右手肘
glTranslatef(0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();///上左手臂
glTranslatef(-0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();///下左手肘
glTranslatef(-0.5,0.15,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
///printf("%.1f\n",angle);
///angle++;
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("05160133_week05 T-R-T");
glutDisplayFunc(display);
glutMotionFunc(motion);
///glutIdleFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言