(1)旋轉 移動
(2)mouse 旋轉
(3)階層式旋轉
(4)階層式移動
網址輸入jsyeh.org/3dcg10
下載 glut.dll和windows.zip和data.zip
解壓縮window 把全部放入同一個資料夾
玩玩看其中一個(transformation)
按右鍵reset可以重新
可以試試看如果位置調換有什麼不一樣:
rotate(旋轉)
rotate(旋轉)
translate(移動)
旋轉在移動之前,會因為汽車寬度越大,而影響旋轉的半徑會越大;寬度越小,而影響的半徑會越小
旋轉在移動之前,會因為汽車寬度越大,而影響旋轉的半徑會越大;寬度越小,而影響的半徑會越小
translate(移動)
rotate(旋轉)
移動在旋轉前,汽車是在原地旋轉
移動在旋轉前,汽車是在原地旋轉
----------
打開openGL

freeglut>lib 複製

複製網址

到code blocks開心專案後
貼上程式碼

#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 3D");
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 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
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 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



沒有留言:
張貼留言