下載windows.zip data.zip glut32.dll

先移動 再旋轉

先旋轉 再移動


#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion(int x, int y)///mouse motion 移動時,會較motion()
{
angle=x;///直接把mouse座標, 變轉動角度
glutPostRedisplay();
}
void display()///呼叫函式
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glRotatef(angle, 0, 0, 1);///rotate/translate/scale會改變矩陣
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();
}


沒有留言:
張貼留言