2018年3月30日 星期五

Week05 夏玉庭

複習上週的東西 用Transformation看旋轉. 移動
從 http://jsyeh.org/3dcg10 下載 data.zip、windows.zip、gult32.dll 三個檔案,然後將 windows.zip 解壓縮,再將 glut32.dll 丟進去,開啟 Transformation.exe

T.R.S 轉動 
方法1: 口訣(由下往上看)
glTranslate(...)
glRotate(...)
glScale(...)
glBegin(...)


















 

glRotate(...)
glTranslate(...)
glScale(...)
glBegin(...)




















方法2: 跑程式
改50-54行(左上球)
讓球可以繞著中心轉動
   glPushMatrix();
        glRotated(a,0,0,1);///轉動,樓下的...
        glTranslated(-2.4,1.2,-6);///整個移到左下角
        glutSolidSphere(1,slices,stacks);
   glPopMatrix();

   ///把其他都變成白色
   glColor3d(1,1,1);
   glPushMatrix();
        glTranslated(0,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidCone(1,1,slices,stacks);

   glPopMatrix();









方法3: 
#include <GL/glut.h>
float angle=0;///Now: 讓茶壼自動轉動的角度
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glColor3f(1,0,0); glutSolidTeapot(0.3);///中間的紅色茶壺
        glPushMatrix();///Now4:右手臂
            glTranslatef(0.4,0.13,0);///Now:(3)最後掛上去
            glRotatef(angle, 0,0,1);///(2)Now2:再轉它(樓下全部)
            glTranslatef(0.45,-0.10,0);///Now2:把茶壺柄放到正中間,等等才能轉
            glColor3f(0,1,0); glutSolidTeapot(0.3);///綠色的
            glPushMatrix();///Now4:右手肘
                glTranslatef(0.4,0.13,0);///Now:(3)最後掛上去
                glRotatef(angle, 0,0,1);///(2)Now2:再轉它(樓下全部)
                glTranslatef(0.45,-0.10,0);///Now2:把茶壺柄放到正中間,等等才能轉
                glColor3f(0,1,0); glutSolidTeapot(0.3);///綠色的
            glPushMatrix();
        glPopMatrix();
        glPushMatrix();///Now4:左手臂
            glTranslatef(-0.4,0.13,0);///Now:(3)最後掛上去
            glRotatef(angle, 0,0,1);///(2)Now2:再轉它(樓下全部)
            glTranslatef(-0.45,-0.10,0);///Now2:把茶壺柄放到正中間,等等才能轉
            glColor3f(0,1,0); glutSolidTeapot(0.3);///綠色的
            glPushMatrix();///Now4:左手肘
                glTranslatef(-0.4,0.13,0);///Now:(3)最後掛上去
                glRotatef(angle, 0,0,1);///(2)Now2:再轉它(樓下全部)
                glTranslatef(-0.45,-0.10,0);///Now2:把茶壺柄放到正中間,等等才能轉
                glColor3f(0,1,0); glutSolidTeapot(0.3);///綠色的
            glPushMatrix();
        glPopMatrix();
    glPopMatrix();
    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();

}


沒有留言:

張貼留言