如何在Android OpenGL ES中实现立方体的颜色选择
我已经在 Android OpenGL ES 中实现了一个可以通过手势旋转的立方体。现在我想实现的是,当我点击立方体上的某个地方时,它可以知道哪个面被触摸并做出一些响应。
我在网上搜索了一下,发现颜色选择是一个好方法,这里有一些教程: http: //www.lighthouse3d.com/opengl/picking/index.php?color1
但我仍然觉得这对我来说很难。
如何为每个面分配不同的颜色?
如何从后台缓冲区读取鼠标单击的像素?
谁能告诉我更多详细信息?多谢!
如果您不介意,请给我留下一个电子邮件地址,我可以将我所做的工作发送给您。谢谢 :)
I have already implemented a cube which can rotate by gestures in Android OpenGL ES. Now I want to implement that when I click somewhere on the cube, it can tell which face has been touched and make some response.
I searched the Internet and find color picking a good way, here are some tutorials: http://www.lighthouse3d.com/opengl/picking/index.php?color1
But I still find it difficult for me.
How to assigned each face a different color?
How to read the pixel where the mouse was clicked from the back buffer?
Can anyone show me some more details? Thanks a lot!
If you don't mind, leave me an email address and I can send you the work I have done. Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个评论是,通过分析向世界投射光线几乎总是更快。撇开评论不谈...
您可以为每个面指定不同的颜色以进行拾取,就像任何其他类型的渲染一样,无论是通过更改传递给
glColorPointer
的内容(如果使用 ES 1)还是通过切换到单个像素、单色纹理或通过任何其他方式。如果您启用了照明,请务必将其禁用。您可以使用glReadPixels从帧缓冲区读回颜色。在触摸屏设备上,您可能想要抓取一个 20x20 像素区域并选择其中最常出现的颜色或类似的颜色,因为手指不是很精确。
The first comment is that it's almost always faster to do this analytically — by casting a ray into the world. That comment aside...
You'd assign each face a different colour for picking just like for any other sort of rendering, whether by changing what you pass to
glColorPointer
(if using ES 1) or by switching to a single pixel, single coloured texture or by any other means. If you have lighting enabled, be sure to disable it.You can use
glReadPixels
to read a colour back from a frame buffer. On a touch-screen device you probably want to grab, say, a 20x20 pixel area and pick whichever colour appears most often in it, or something like, that because fingers aren't very precise.