步驟1:先將windows資料夾中的Transformation.exe開啟

步驟2:測試移動(Translate)、旋轉(Rotate)、縮放(Scale)

步驟3:滑鼠右鍵點Swap並觀察前後的差別

觀察結果:在還沒Swap之前務中心點維持在物體(車子)中心
Swap後中心點變成在攝影機的中心點

課堂作業2:
步驟1:將以下紅色的程式碼放入之前做茶壺的程式碼中
#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的量值)
glRotated(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);
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

Q1:什麼是glPushMatrix();
glPopMatrix();
Ans:glPushMatrix():是將資料丟進函式進行改變
glPopMatrix():是將程式輸出使用
Q2:什麼是Buffers?
Double?
Ans:Buffer:怕圖不完整要先進行一是測試處理
Double:多做一次讓圖更加完整
課堂作業3:
如果想要同時進行X,Y軸的轉動可以寫成這樣:
#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotated(rotX, 0,1,0);//X的移動量,讓他對Y軸轉
glRotated(rotY, 1,0,0);//Y的移動量,讓他對X軸轉
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(700,700);glutInitWindowPosition(600,0);//hello 3D的視窗設定
glutCreateWindow("hello 3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言