GLUT 支持鼠標拖動旋轉的茶壺
[編輯] [转简体] (简体译文)
|
作者:huidong
| 分類:【編程】GLUT
[
2 瀏覽
0 評論
0 贊
0 踩
]
概要
正文
#include <windows.h> #include <GL/glut.h> float angleX = 0.0; float angleY = 0.0; int prevX, prevY; void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { prevX = x; prevY = y; } } void motion(int x, int y) { int dx = x - prevX; int dy = y - prevY; angleY += dx * 0.1; angleX += dy * 0.1; prevX = x; prevY = y; glutPostRedisplay(); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(angleX, 1.0, 0.0, 0.0); glRotatef(angleY, 0.0, 1.0, 0.0); glutWireTeapot(0.5); // 绘制场景内容 glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Mouse Rotation"); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glEnable(GL_DEPTH_TEST); glutMainLoop(); return 0; }