Step01:
1. https://jsyeh.org/3dcg10/下載
data.zip->\windows\data\一堆3D模型
windows.zip>解壓>開啟>transformation,exe
glrotatef(角度,X,Y,Z)
第一個:依找安培右手定理,右手比讚,四隻手指決定旋轉方向
Step02:
1.先寫入
#include<GL/glut.h>
void Display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc,char**argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week04_rotate");
glutDisplayFunc(Display);
glutMainLoop();
}
2.加入rotatef()///(角度,X,Y,Z)
glPushMatrix();
glRotatef(90,0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
Step03: 學習motion:讓angle角度變換,隨之能控制物件轉向
1.寫入motion()
int float=0;
void motion(int x,int y){
angle=x;
Display(); //重畫畫面
}
2.在main()寫入
glutMotionFunc(motion);
讓motion()傳回到Main()
Step04:
1.加入mouse() 做定錨
void mouse(int button,int state,int x,int y){
oldX=x;
}
2.修改motion()
angle+=(x-oldX);
x:新點;oldX:舊點
x-oldX:移動多少
沒有留言:
張貼留言