2019年5月3日 星期五

麵包超人-week11



在物件上加上關節 然後可以用滑鼠控制他
以下是上圖的程式碼
#include <GL/glut.h>
float angle=0;///NOW
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(255,255,255);///白色的
    glutSolidTeapot( 0.3 );///身體
    glPushMatrix();///右邊手臂
        glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///右手臂

        glPushMatrix();///右邊手臂
            glTranslatef(0.2, 0, 0);///(3) 掛在身體的右肩
            glRotatef(angle, 0,0,1);///(2) 旋轉
            glTranslatef(0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

            glColor3f(1,0,0);///紅色的
            glutSolidTeapot( 0.15 );///右手臂
            glPopMatrix();
    glPopMatrix();

    glPushMatrix();///左邊手臂
        glTranslatef(-0.2, 0, 0);///(3) 掛在身體的左肩
        glRotatef(angle, 0,0,1);///(2) 旋轉
        glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

        glColor3f(1,0,0);///紅色的
        glutSolidTeapot( 0.15 );///左手臂

        glPushMatrix();///左邊手臂
            glTranslatef(-0.2, 0, 0);///(3) 掛在身體的左肩
            glRotatef(angle, 0,0,1);///(2) 旋轉
            glTranslatef(-0.15, 0,0);///(1) 把茶壼柄,移動到畫面的中心,當旋轉軸

            glColor3f(1,0,0);///紅色的
            glutSolidTeapot( 0.15 );///左手臂
            glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    ///angle++;///NOW
}
void motion(int x, int y)
{
    angle=x;
    display();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
    glutCreateWindow("week11 TRT");
    glutIdleFunc(display);///NOW
    glutDisplayFunc(display);
    glutMotionFunc(motion);

    glutMainLoop();
}

沒有留言:

張貼留言