2019年4月25日 星期四

Week 10 T-R-T旋轉(改變旋轉軸)

1.開啟http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

2.Examples下載win32、data

3.other examples下載glut32.dll

4.解壓縮windows資料夾

5.將data壓縮檔打開(不要解壓縮),直接拖曳到windows資料夾中

6.將glut32.dll放入windows資料夾中

7.打開Transformation.exe即可使用


試glRotatef(角度,x軸,y軸,z軸);




Translatef(自轉)(攝影機轉) Rotatef(公轉)(繞著車子轉)





程式碼:

#include<GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0,0.5,0);///這是往上移動的茶壺
        glutSolidTeapot(0.3);///This is a Teapot
    glPopMatrix();
    glPushMatrix();

    glPopMatrix();

    glPushMatrix();
        glTranslatef(0.50,0.625,0);///(3)把它掛在你要放的地方
        glRotatef(angle,0,0,1);///(1)先有個轉動,但怪怪的
        glTranslatef(0.6,0,0);///(2)要更早去移動旋轉中心

        glRotatef(-90,0,1,0);///(0)轉動90度的Cone
        glutSolidCone(0.2,0.6,30,30);///直直的Cone
    glPopMatrix();
    glutSwapBuffers();
}

void motion(int x,int y)
{
    angle=x;
    display();
}

int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week10 TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}




沒有留言:

張貼留言