1.旋轉&轉動
教材 jsyeh.org/3dcg10下載:data win32 glut32.dll

解壓縮data win32 把data glut32.dll放入window資料夾
執行Transformation

縮放

旋轉

移動

2.mouse轉動
Buffer 繪圖暫存記憶體空間
DoubleBuffer兩倍記憶體空間

兩個記憶體互相繪圖輸出到螢幕上
code block 程式實作
#include <GL\glut.h>
float rotX=0;
void display()
{
glClearColor(0, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX, 0, 1, 0);
glColor3f( 1, 0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX = x;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

增加Y軸旋轉和修改視窗大小跟位置
#include <GL\glut.h>float rotX=0, rotY=0;
void display()
{
glClearColor(0, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotY, 1, 0, 0);
glRotatef(rotX, 0, 1, 0);
glColor3f( 1, 0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
rotX = x;
rotY = y;
display();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(600,600);
glutInitWindowPosition(650,0);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

沒有留言:
張貼留言