2018年3月26日 星期一

Week 05 ADDONE notes

1)複習移動、旋轉
2)T-R-T特定軸轉
3)階層性旋轉
4)矩陣


茶壺公轉 (繞茶壺把手轉)
#include <GL/glut.h>
float angle=0;
void motion(int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(angle,0,0,1);
        glTranslatef(0.45,-0.08,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week05 TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
     glutMainLoop();
}
左右手相反轉

左右手同時向上 向下
#include <GL/glut.h>
float angle=0;
void motion(int x,int y)
{
    angle=x;
    glutPostRedisplay();
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glutSolidTeapot(0.3);
    glPushMatrix();//右上手臂
        glTranslatef(0.5,0.15,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.45,-0.08,0);
        glutSolidTeapot(0.3);

        glPushMatrix();//右下手肘
            glTranslatef(0.5,0.15,0);
            glRotatef(angle,0,0,1);
            glTranslatef(0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();

     glPopMatrix();

      glPushMatrix();//左上手臂
        glTranslatef(-0.5,0.15,0);
        glRotatef(-angle,0,0,1);
        glTranslatef(-0.45,-0.08,0);
        glutSolidTeapot(0.3);

        glPushMatrix();//左下手肘
            glTranslatef(-0.5,0.15,0);
            glRotatef(-angle,0,0,1);
            glTranslatef(-0.45,-0.08,0);
            glutSolidTeapot(0.3);
        glPopMatrix();

    glPopMatrix();

    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week05 TRT");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
     glutMainLoop();
}



沒有留言:

張貼留言