一.前往→ http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/→ 下載data、win32、glut32.dll三項
解壓縮windows壓縮檔並打開
將glut32.dll移入windows資料夾內
將data解壓至windows資料夾內
(圖見Week03)
開啟Transformation,調整glTranslate(平移)的值
glTranslate(0,0,0)=glTranslate(X軸,Y軸,Z軸)
調整glRotatef(旋轉)的值
glRotatef(0,0,0)=glRotatef(旋轉)
調整glScalef(縮放)的值
glScalef(0,0,0)=glScalef(縮放)
比較三者順序的差異
01.透過平移/旋轉/縮放
假設原先都為初始設定值,那麼原先就是原地旋轉,glTranslate平移順序在第一位時,無論移動到哪,皆為原地旋轉。


02.旋轉/平移/縮放
三個數值的順序進行調整,會產生不同方式的旋轉
假設原先都為初始設定值,那麼原先就是原地旋轉,如果調整glRotatef(旋轉)的值在進行旋轉,會從原地旋轉變成大圓圈旋轉,離原本中心越遠旋轉的圈越大。


二.mouse與旋轉
給茶壺這個圖形用滑鼠進行控制旋轉

#include<GL/glut.h>
float rotX=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); //備份Matrix (Matrix裡有translate,rotate, scale的量值)
glRotatef(rotX,0,1,0);
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix(); //還原Matrix (回到剛剛push時的樣子)
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
display(); //glutPostRedisplay();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); //double buffers兩倍記憶體
glutCreateWindow("hello");//視窗名稱
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

#include<GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); //備份Matrix (Matrix裡有translate,rotate, scale的量值)
glRotatef(rotY,1,0,0); //Y的移動量,讓他對X軸轉
glRotatef(rotX,0,1,0); //X的移動量,讓他對Y軸轉
glColor3f(1,0,0);
glutSolidTeapot(0.3);
glPopMatrix(); //還原Matrix (回到剛剛push時的樣子)
glutSwapBuffers();
}
void motion(int x,int y)
{
rotX=x;
rotY=y; //同時拿來用
display(); //glutPostRedisplay();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); //double buffers兩倍記憶體
glutInitWindowSize(300,300);glutInitWindowPosition(600,0);
glutCreateWindow("hello");//視窗名稱
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言