2016年3月22日 星期二

Week 05 曾子豪

作業1.

到教材 jsyeh.org/3dcg10
下載 [source][data][win32][glut32.dll檔案>Transformation
去做交換Swap,判斷 Translatef 與 Rotatef 轉動的差別

Translatef 是軸的原點為轉動的中心


Rotatef 是以物件為轉動的中心點


作業2.

可以用滑鼠轉動得茶壺



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

作業3.

glPushMatrix();//置入資料並且固定
glPopMatrix();//輸出資料可改變
Buffers:記憶體緩衝,使圖片完整

作業4.

可透過滑鼠讓水壺繞x.y軸旋轉。
#include <GL/glut.h>
float rotX=0, rotY=0;
void display()
{
    glClearColor(0,0,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glRotatef(rotY,1,0,0); ///旋轉 角度rotY, 軸(1,0,0) x軸
        glRotatef(rotX,0,1,0); ///旋轉 角度rotY, 軸(0,1,0) y軸
        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("Hello 3D");

    glutMotionFunc(motion);
    glutDisplayFunc(display);
    ///glutMouseFunc(mouse);

    glutMainLoop();
}



沒有留言:

張貼留言