2016年3月22日 星期二

Week 05_胡安俊

旋轉+移動

移動 glTranslatef
旋轉glRotatef
縮放glScalef



swap



旋轉是沿著中心點轉
左右邊在轉

C
mouse轉動

#include<GL/glut.h>
void motion(int x,int y)
{

}
void display()
{
     glClearColor(0,0,1,1);
     glClear(GL_COLOR_BUFFER_BIT);

     glColor3f(1,0,0);

     glutSolidTeapot(0.3);

     glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DEPTH);
    glutCreateWindow("hello3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();


}
左右轉動



Buffer :


Double :


階層旋轉、移動
#include<GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotX,1,0,0);
         glRotatef(rotY,0,1,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);
    glutCreateWindow("hello 3D");
    glutDisplayFunc(display);

    glutMotionFunc(motion);

    glutMainLoop();

}





沒有留言:

張貼留言