2018年6月24日 星期日

week05

複習移動旋轉
主題  T_R_T

#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();
}
TRT手臂
#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);

        glTranslatef(0.5, 0.15, 0);
        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();
}

沒有留言:

張貼留言