openGL物体如何实现不通过事件响应旋转物体 20
想做一个地月模型演示图,发现网上全是用鼠标或键盘控制的物体旋转,请问,如何实现物体的自动旋转,给一点思路,谢谢!...
想做一个地月模型演示图,发现网上全是用鼠标或键盘控制的物体旋转,请问,如何实现物体的自动旋转,给一点思路,谢谢!
展开
展开全部
首先在windows下获取鼠标按下/抬起/移动的消息
然后再进行判断
如果鼠标按下且移动
则进行glTranslatef/gluLookat操作
左键按下时使glRotatef里的变量相应改变。我是这样做的,不过右键也响应啦,呵呵,参考一下:)
void ArrowKeys(int key, int x, int y)
{
if (key == GLUT_KEY_LEFT) // rotate in the negative z
MyImage.zRot -= 5.0f;
if (key == GLUT_KEY_RIGHT) // rotate in the positive z
MyImage.zRot += 5.0f;
if (key == GLUT_KEY_UP) // rotate in the negative x
MyImage.xRot -= 5.0f;
if (key == GLUT_KEY_DOWN) // rotate in the postive x
MyImage.xRot += 5.0f;
if (key == GLUT_KEY_PAGE_UP) // rotate in the negative y
MyImage.yRot -= 5.0f;
if (key == GLUT_KEY_PAGE_DOWN) // rotate in the postive y
MyImage.yRot += 5.0f;
// Check x,y and z rotation values to keep 0-355
if (MyImage.xRot > 356.0f)
MyImage.xRot = 0.0f;
if (MyImage.xRot < 0.0f)
MyImage.xRot = 355.0f;
if (MyImage.yRot > 356.0f)
MyImage.yRot = 0.0f;
if (MyImage.yRot < 0.0f)
MyImage.yRot = 355.0f;
if (MyImage.zRot > 356.0f)
MyImage.zRot = 0.0f;
if (MyImage.zRot < 0.0f)
MyImage.zRot = 355.0f;
// Refresh the window
glutPostRedisplay();
}
// Do any needed rotation
glRotatef(MyImage.xRot, 1.0f, 0.0f, 0.0f);
glRotatef(MyImage.yRot, 0.0f, 1.0f, 0.0f);
glRotatef(MyImage.zRot, 0.0f, 0.0f, 1.0f);
然后再进行判断
如果鼠标按下且移动
则进行glTranslatef/gluLookat操作
左键按下时使glRotatef里的变量相应改变。我是这样做的,不过右键也响应啦,呵呵,参考一下:)
void ArrowKeys(int key, int x, int y)
{
if (key == GLUT_KEY_LEFT) // rotate in the negative z
MyImage.zRot -= 5.0f;
if (key == GLUT_KEY_RIGHT) // rotate in the positive z
MyImage.zRot += 5.0f;
if (key == GLUT_KEY_UP) // rotate in the negative x
MyImage.xRot -= 5.0f;
if (key == GLUT_KEY_DOWN) // rotate in the postive x
MyImage.xRot += 5.0f;
if (key == GLUT_KEY_PAGE_UP) // rotate in the negative y
MyImage.yRot -= 5.0f;
if (key == GLUT_KEY_PAGE_DOWN) // rotate in the postive y
MyImage.yRot += 5.0f;
// Check x,y and z rotation values to keep 0-355
if (MyImage.xRot > 356.0f)
MyImage.xRot = 0.0f;
if (MyImage.xRot < 0.0f)
MyImage.xRot = 355.0f;
if (MyImage.yRot > 356.0f)
MyImage.yRot = 0.0f;
if (MyImage.yRot < 0.0f)
MyImage.yRot = 355.0f;
if (MyImage.zRot > 356.0f)
MyImage.zRot = 0.0f;
if (MyImage.zRot < 0.0f)
MyImage.zRot = 355.0f;
// Refresh the window
glutPostRedisplay();
}
// Do any needed rotation
glRotatef(MyImage.xRot, 1.0f, 0.0f, 0.0f);
glRotatef(MyImage.yRot, 0.0f, 1.0f, 0.0f);
glRotatef(MyImage.zRot, 0.0f, 0.0f, 1.0f);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询