2016年3月22日 星期二

Week 05 李明融

縮放、移動、旋轉

以車為中心旋轉







點右鍵


"Swap translate/rotate









車繞著中心轉










移到右邊旋轉







車子移動並圍繞中心旋轉






物件旋轉
開啟code blocks
GLUT Project

打入程式碼


#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();
}







茶壺360度旋轉

#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);
    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(700,0);
    glutCreateWindow("hello3D");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}








沒有留言:

張貼留言