2016年3月21日 星期一

林暐軒 week05

課堂作業一 :

前往 jsyeh/3dcg10 下載必要素材(windows.zip、data.zip、glut32.dll)

開啟Transformation應用,切換Swap Translate/Rotate




課堂作業二 :

旋轉茶壺




#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);//背景顏色
    glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色

    glPushMatrix();//備份位置
        glRotatef(rotX,0,1,0);//將滑鼠移動的x轉換為rotate-x
        glColor3f(1,0,0);//紅色
        glutSolidTeapot(0.3);//茶壺
    glPopMatrix();//取出位置使用
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;//將滑鼠移動的x轉換為rotate-x
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc , argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("03161042");

    glutDisplayFunc(display);
    glutMotionFunc(motion);//motion函式

    glutMainLoop();


Q1: 什麼是 glPushMatrix? 什麼是 glPopMatrix?

A1: glPushMatrix是備份量值位置(Matrix-translate、rotate、scale的量值) ;           glPopMatrix是取出剛剛備份位置的量值使用

Q2: 什麼是Buffers?什麼是Double?

 A2: Buffers記憶體 ; Double

課堂作業三 :

雙旋轉茶壺




#include <GL/glut.h>
float rotX=0,rotY=0;
void display()
{
    glClearColor(1,1,1,1);//背景顏色
    glClear(GL_COLOR_BUFFER_BIT);//背景漆上顏色

    glPushMatrix();//備份位置
        glRotatef(rotY,1,0,0);//將滑鼠Y的移動量對x軸旋轉
        glRotatef(rotX,0,1,0);//將滑鼠X的移動量對y軸旋轉
        glColor3f(1,0,0);//紅色
        glutSolidTeapot(0.3);//茶壺
    glPopMatrix();//取出位置使用
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;//將滑鼠x的移動量轉換為rotate-x
    rotY=y;//將滑鼠y的移動量轉換為rotate-y
    display();
}
int main(int argc,char**argv)
{
    glutInit(&argc , argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("03161042");

    glutDisplayFunc(display);
    glutMotionFunc(motion);//motion函式
    glutMainLoop();
}


沒有留言:

張貼留言