opengl实现鼠标取点的问题,左键右键两个不同的点 void myMouse(int button, int state, int x, int y) {

应该怎么改啊... 应该怎么改啊 展开
 我来答
匿名用户
2016-06-05
展开全部
#include #include void myinit(void){ glClearColor(0.0, 0.0, 0.0, 0.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glDepthRange(0.0, 1.0); /* The default z mapping */}GLfloat tx = 0.0f, ty = 0.0f, tz = 0.0f;void drawsphere(GLenum mode){glPushMatrix();glTranslatef( tx, ty, tz-90.0f);glutWireSphere(1.0,10,10);glPopMatrix();}void idle(void){if( tx < 20.0f )tx += 0.2f;else if( ty < 20.0f )ty += 0.2f;else if ( tx < 40.0f && ty < 40.0f ){tx += 0.2f;ty += 0.2f;}else{tx = ty = 0.0f;}glutPostRedisplay();}void display(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.0f,1.0f,1.0f); glPushMatrix(); glBegin(GL_LINES); glVertex3f( -50.0f,0.0f,-80.0f); glVertex3f( 50.0f, 0.0f, -80.0f); glVertex3f(0.0f, -50.0f,-80.0f); glVertex3f(0.0f,50.0f, -80.0f); glEnd(); glPopMatrix(); drawsphere(GL_RENDER); glutSwapBuffers();}void myReshape(int w, int h){glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0, (GLfloat) 1.0, 1.0, 100.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef (-3.0, -3.0, -8.0);}static voidkey(unsigned char k, int x, int y){ switch (k) { case 27: /* Escape */ exit(0); break; default: return; } glutPostRedisplay();}intmain(int argc, char **argv){ glutInitWindowSize(200, 200); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInit(&argc, argv); glutCreateWindow(argv[0]); myinit(); glutReshapeFunc(myReshape); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(key); glutMainLoop(); return 0; /* ANSI C requires main to return int. */}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式