在OpenGL中选择一个对象

编程入门 行业动态 更新时间:2024-10-26 10:40:11
本文介绍了在OpenGL中选择一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我画一个立方体和一个球体.我加载立方体的名称,但不加载球体的名称.当我通过光标选择球体时,程序将显示多维数据集的名称.像这样的代码:

I draw one cube and one sphere. I load the cube''s name but don''t load the sphere''s name. When I select the sphere by cursor, The program shows the cube''s name. The code like this:

glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translate the whole scene out and into view glTranslatef(-80.0f, 0.0f, -300.0f); // Initialize the names stack glInitNames(); glPushName(0); // Set material color, Yellow // Cube glRGB(255, 255, 0); glLoadName(CUBE); glutSolidCube(75.0f); // Draw Sphere glRGB(128,0,0); glTranslatef(120.0f, 0.0f, 0.0f); glutSolidSphere(50.0f, 15, 15); glRGB(128,0,0); glTranslatef(0.0f, -80.0f, 0.0f); glutSolidSphere(20.0f, 15, 15); // Restore the matrix state glPopMatrix(); // Modelview matrix

推荐答案

您能不能这样尝试? 在这里,CUBE名称被赋予glutSolidCube,而SPHERES名称被赋予球体绘图. 现在,您将在屏幕上拾取球体对象时得到SPHERES. Could you please try like this. Here CUBE name is given to glutSolidCube and SPHERES name is given to sphere drawing. Now you will get SPHERES on picking sphere objects in screen. // Set material color, Yellow // Cube glRGB(255, 255, 0); // Set Drawing object name to CUBE glLoadName(CUBE); glutSolidCube(75.0f); // Set Drawing object name to SPHERES glLoadName(SPHERES); // Draw Sphere glRGB(128,0,0); glTranslatef(120.0f, 0.0f, 0.0f); glutSolidSphere(50.0f, 15, 15); // Other drawing..........

更多推荐

在OpenGL中选择一个对象

本文发布于:2023-10-17 06:15:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   OpenGL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!