2019年4月25日 星期四

瞎78打-7

( 1 ) 期中考 : OpenGL 必備10函式
( 2 ) 複習 : 移動 , 旋轉 , 縮放
( 3 ) 主題 : T -  R - T 旋轉 ( 改變旋轉軸 )
( 4 ) 主題 : glut
-----------------------------------------------------------




茶壺加入圓筒當手:


#include <GL/glut.h>
 float angle=0;
 void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslated(0,0.5,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glPushMatrix();
        //關節的步驟
        glTranslated(0.5,0.625,0); //(3) 把它掛在你要放的地方
        glRotatef(angle, 0,0,1);  // (1) 先有轉動,但怪怪的
        glTranslated(0.6,0,0);  //(2) 要更早去移動旋轉中心

        glRotatef(-90, 0,1,0); //圓筒旋轉90度
        glutSolidCone(0.2,0.6,30,30);  //產生圓筒
    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");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}
結果:

沒有留言:

張貼留言