1.主題:旋轉Rotation
120.125.89.81 老師IPRotate 旋轉
glRotatef(a,x,y,z);
2.實作:glRotatef()
到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/--> 下載: windows.zip, data.zip, glut32.dll (week03
執行 Transformation.exe 檔案
glTranslatef(x,y,z); //移動
glRotatef(a,x,y,z); //旋轉
a:角度 ,x:左右軸 ,y:上下軸 ,z:前後軸
glScalef(x,y,z); //縮放
-
開啟GLUT程式 (week01
進入transmission zero 網站,下載"freeglut 3.0.0 MinGW Package"在 CodeBlocks 開啟GLUTproject
寫自動轉程式:
#include <GL/glut.h>
float angle=0; //now!角度
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_COLOR_BUFFER_BIT);///清除殘影
glPushMatrix(); //備份矩陣
glRotatef(angle,0,1,0); //now!旋轉,對y軸
glutSolidTeapot(0.3);
glPopMatrix(); //還原矩陣
glutSwapBuffers();
angle+=3; //now!
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display); //now! Idle 沒事,就重畫
glutMainLoop();
}
-
3.滑鼠 轉.(自動 轉
#include <GL/glut.h>#include <stdio.h>
float angle=0; //now!角度
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_COLOR_BUFFER_BIT);//清除殘影
glPushMatrix(); //備份矩陣
glRotatef(angle,0,1,0);//now!旋轉,對y軸
glutSolidTeapot(0.3);
glPopMatrix(); //還原矩陣
glutSwapBuffers();
}
void motion(int x,int y){
angle=x; ///now!滑鼠
display(); ///now!馬上更新
}
void mouse(int button,int state,int x,int y){
printf("%d %d %d %d\n",button,state,x,y);
}
int main(int argc,char**argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 rotate");
glutDisplayFunc(display);
glutIdleFunc(display);//now! Idle 沒事,就重畫
glutMotionFunc(motion);///now!滑鼠滑動
glutMouseFunc(mouse);///now!滑鼠點放
glutMainLoop();
}
沒有留言:
張貼留言