2018年3月30日 星期五

Week05 階層轉動

2018-3-30(春假補課) week 05 電腦圖學
(1)複習:T.R.S-------mouse/motion
(2)主題:T-R-T轉動
(3)主題:階層轉動
(4)矩陣
(5)回作業



(1)打開老師給的程式碼觀察兩種旋轉方式,分別是自轉和公轉
自轉
公轉
    (2)打開OpenGL,更改50-54行程式碼,將glRotated(a,0,0,1)和glTranslated(-2.4,1.2,-6)互換位置

(3)可以轉動的茶壺

#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///Now:備份矩陣
    glRotatef(angle, 0,0,1);///Now:轉動
    glutSolidTeapot(0.3);
    glPopMatrix();///Now:還原矩陣
    glutSwapBuffers();
}
void motion(int x, int y)
{
    angle=x;///Now: 改變角度
    glutPostRedisplay();///Now: 請 重畫畫面
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Week05 TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///Now:
    glutMainLoop();
}


(4)增加兩行程式碼讓茶壺可以做倒水的動作























沒有留言:

張貼留言