Hw01
(A) 移動glTranslatef 旋轉glRotatef 縮放glScalef
從下往上看,一個縮小的車子旋轉(本身在旋轉),移到右邊
縮放glScalef → 旋轉glRotatef → 移動glTranslatef
(B)旋轉glRotatef 移動glTranslatef 縮放glScalef
從下往上看,一個縮小的車子移到右邊,車子旋轉(整個世界再轉,不只是車子轉而已)
縮放glScalef → 移動glTranslatef → 旋轉glRotatef
Hw02
左右旋轉
#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("I LOVE APPLE PIE"); //視窗名稱
glutDisplayFunc(display); //展示
glutMotionFunc(motion);
glutMainLoop();
}
Hw03
1.Buffer 記憶體緩衝區
2.double Buffers
Hw04
上下左右旋轉
#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);///旋轉 角度rotY, 軸(1,0,0)X軸
glRotatef(rotX, 0, 1 ,0);///旋轉 角度rotX, 軸(0,1,0)Y軸
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); ///雙視窗
glutCreateWindow("I LOVE APPLE PIE"); ///視窗名稱
glutDisplayFunc(display); ///展示
glutMotionFunc(motion);
glutMainLoop();
}
glutInitWindowSize(600,600); ///視窗大小
glutInitWindowPosition(700,0);///視窗位置













沒有留言:
張貼留言