打開Transformation
(1)以車子為中心點

glTranslatef(x,y,z)
x:鏡頭水平移動 y:鏡頭垂直移動 z:鏡頭前後移動

glRotatef(a,b,c,d)
a:360度旋轉 bcd旋轉的方向

glScalef
x:鏡頭水平縮放 y:鏡頭垂直縮放 z:鏡頭前後縮放

課堂2
按滑鼠右鍵,選擇[x]Swap translate/rotate得到以下畫面
(2)以整個空間為中心點

課堂3
#include <GL/Glut.h>
float rotX=0;
void display()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,0,1,0);
glColor3f(1,1,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();
}

#include <GL/Glut.h>
float rotX=0,rotY=0;
void display()
{
glClearColor(0,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(rotX,0,1,0);
glRotatef(rotY,1,0,0);
glColor3f(1,1,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(800,0);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}

沒有留言:
張貼留言