2023年3月8日 星期三

Yuuta's-week04-Rotation and Translation

 電腦圖學 2023-03-08 Week04

1. 主題: 旋轉 Rotate
2. 實作: glRotatef(角度, x, y, z);
3. 主題: 矩陣 Matrix
4. 利用 mouse motion 來控制

手掌從X軸掃到Y軸時, 會生出拇指Z軸
glRotatef對應角度、X軸、Y軸、Z軸

旋轉茶壺












打光效果

打光後加色彩












公轉/自轉分別




























由下往上讀, 黃色先旋轉才移動到0.6(自轉)
紅色先移到0.6才開始轉, 中心點不同

void display()
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ///清背景
    glPushMatrix(); ///備份矩陣
        glTranslated(0.6, 0, 0);
        glRotatef(angle, 0, 1, 0); ///旋轉 angle 角度
        glColor3f(1, 1, 0);
        glutSolidTeapot(0.3);
    glPopMatrix(); ///還原矩陣
    glPushMatrix(); ///備份矩陣
        glRotatef(angle, 0, 1, 0); ///旋轉 angle 角度
        glTranslated(0.6, 0, 0);
        glColor3f(1, 0, 0);
        glutSolidTeapot(0.3);
    glPopMatrix(); ///還原矩陣
    glutSwapBuffers();
    angle+=0.1;
}

沒有留言:

張貼留言