Perfunctoriness 2015-07-03 00:49 采纳率: 0%
浏览 2339
已结题

关于Opengl建立的立体图形来利用鼠标来进行控制其旋转的问题

在vs2010里面我建立了open gl 后,添加了一个其自动旋转的三维立体图形,其代码如下

#include

GLfloat xRotated, yRotated, zRotated;

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,-4.0);
glRotatef(xRotated,1.0,0.0,0.0);
glRotatef(yRotated,0.0,1.0,0.0);
glRotatef(zRotated,0.0,0.0,1.0);
//glScalef(2.0,1.0,1.0);
glutWireCube(1.5);
glFlush(); //Finish rendering
glutSwapBuffers();
}

void Reshape(int x, int y)
{
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);

glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); //Use the whole window for rendering
}
static int times = 0;
void Idle(void)
{
times++;
if(times >30000)
times = 0;

if(times %30000 == 0)
{
     xRotated += 0.3;
     yRotated += 0.1;
     zRotated += -0.4;
     Display();
 }

}

int main (int argc, char **argv)
{
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //For animations you should use double buffering
glutInitWindowSize(300,300);
//Create a window with rendering context and everything else we need
glutCreateWindow("Cube example");
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
xRotated = yRotated = zRotated = 0.0;
glClearColor(0.5,0.5,0.0,0.0);
//Assign the two used Msg-routines
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutIdleFunc(Idle);
//Let GLUT get the msgs
glutMainLoop();
return 0;
}
现如今想在这个代码的基础上可以用鼠标控制他的旋转。求源代码,望各位帮帮忙。最好附有效果图。谢谢各位。

  • 写回答

1条回答 默认 最新

  • devmiao 2015-07-18 07:09
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示