
2.口訣:左耳貼近左肩 從下往上讀
第一行是移動
第二行是旋轉
第三行是縮放

3.老師教我們旋轉茶壺以茶壺握把為中心旋轉

#include<GL/glut.h>
float angle=0;//選轉的角度
void motion(int x, int y)///mouse motion脫者移動時會叫motion()
{
angle=x;///老師上周用比較差的方式直接把鼠標變轉動角度
glutPostRedisplay();///請畫面重劃
}
void display()///畫面要DISPLAY時呼叫這個涵式
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);///清洗畫面
glPushMatrix();///備份矩陣
glRotatef(angle,0,0,1);///ROTATE /TRANSLATED/SCALE都會把矩陣改變
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);///移動 茶壺的炳放到面中心
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
4.也可以做出很多茶壺來

#include<GL/glut.h>
float angle=0;//選轉的角度
void motion(int x, int y)///mouse motion脫者移動時會叫motion()
{
angle=x;///老師上周用比較差的方式直接把鼠標變轉動角度
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);
glPushMatrix();
glPushMatrix();
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);
glPushMatrix();
glPushMatrix();
glPushMatrix();
glutSwapBuffers();
glRotatef(angle,0,0,1);///ROTATE /TRANSLATED/SCALE都會把矩陣改變
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);///移動 茶壺的炳放到面中心
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言