2015年5月28日 星期四

關關關關關關關關關關關關關關

做一個茶壺旋轉
 他會自己旋轉
 可以利用滑鼠拖曳旋轉
 中間貼個茶壺 看器來就像在壺嘴上旋轉
#include <GL/glut.h>
float angle=0 ,oldX=0, oldY=0;
void display()
{
    {
        GLfloat pos[] = {0, 0, -1, 0};
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
        glEnable(GL_LIGHT0);
        glEnable(GL_LIGHTING);
    }
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0.45, 0.14, 0);
        glRotatef(angle, 0, 0, 1);
        glTranslatef(0.45, -0.1, 0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSolidTeapot(0.3);
    glFlush();
}
void timer(int t)
{
    glutTimerFunc(20, timer,0);
    ///angle++;
    glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
    if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void motion(int x, int y)
{
    angle += (x -oldX);
    oldX = x;
}
int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("TRT 3D");
    glutDisplayFunc(display);
    glutTimerFunc(20, timer, 0);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}


沒有留言:

張貼留言