看 Transformation.exe 改順序
事前準備:
至 jsyeh.org/3dcg10 下載
1.windows.zip 2.data.zip 3.glut32.dll
未改順序前:
改變順序:
glTranslatef(); <===> glRotatef();
glRotatef(); <===> glTranslatef();
左右邊自轉 <===> 右邊車子繞畫面中心
§滑鼠右鍵按一下,出現選單後,按下螢光筆畫的選項
改順序後:
口訣:左耳貼左肩,由上往下讀

茶壺旋轉:
複習:較差的方法
#include <GL/glut.h>
float angle = 0;
void motion(int x,int y){
angle = x;
glutPostRedisplay();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
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");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
茶壺手臂:
在display()內新增:
glPushMatrix(); ///上手臂
glTranslatef(0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix(); ///下手肘
glTranslatef(0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
完整程式碼:
#include <GL/glut.h>float angle = 0;
void motion(int x,int y){
angle = x;
glutPostRedisplay();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(-0.5,0.16,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.45,-0.08,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week05");
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言