在一个OpenGL多检测用户触摸 [英] Detect user's touches over an OpenGL square

查看:128
本文介绍了在一个OpenGL多检测用户触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/2487710/how-do-i-determine-what-is-touched-in-3d-space-from-the-screen">How我确定什么是感动从屏幕3D空间?

我开发一个Android应用程序。我还与OpenGL图形。

I'm developing an Android application. I'm also working with OpenGL graphics.

我在屏幕上绘制一个正方形,我想,让用户将它移动时,他接触过它。换句话说,用户应该能够移动广场,当他把他的手指在广场上。如果他接触外的广场上没有任何反应。

I have a square drawn on the screen and I want to let user move it when he touches over it. In other words, user should be able to move square when he puts his finger on the square. If he touches outside the square nothing happens.

我如何可以检测用户触摸了多?

How can I detect when user touches over square?

感谢。

推荐答案

在其他的答案中提供的采摘和挑选教程这里不适用;除其他glSelectBuffer和glRenderMode不是OpenGL ES的组成部分。

The picking and selection tutorials supplied in other answers aren't applicable here; amongst other glSelectBuffer and glRenderMode aren't part of OpenGL ES.

有,正如其他地方一样,主要有两个方法。你可以找出如何在触摸映射到场景和数学测试对象。如果你方是平的,好像你是在2D绘图,那么你可以做到这一点很容易。

There are, as stated elsewhere, essentially two approaches. You can figure out how the touch maps into your scene and test your objects mathematically. If your square is flat on, as though you were drawing it in 2d, then you can achieve that quite easily.

另外,你可以做一些事情基本上就像在捡,但适合下的OpenGL ES提供的功能。例如,清除现场,黑色和绘制方形的蓝色。使用glReadPixels得到的触摸位置的颜色值。如果它是蓝色,然后触摸在广场上。这可能是一个更昂贵的方法来测试,因为这意味着现场的附加平局,但它意味着你没有执行任何额外的数学或其他code超出了GL用品。

Alternatively, you can do something essentially like picking but adapted for the functionality available under OpenGL ES. For example, clear your scene to black and draw your square in solid blue. Use glReadPixels to get the colour value at the touch location. If it's blue then the touch is on the square. This is probably a more expensive way to test because it means an additional draw of the scene, but it means that you don't have to implement any additional maths or other code beyond what GL supplies.

只有轻微的事情要记住的是,OpenGL的使用寻址像素处处以同样的方式 - (0,0)是左下角,正Y上升,并正x那张离开了。所以,无论轴你有你的触摸坐标相,你需要做的glReadPixels之前把它们是相对于这一点。

The only slight thing to keep in mind is that OpenGL uses the same way of addressing pixels everywhere — (0, 0) is the bottom left, positive y goes up and positive x goes left. So whatever axes you have your touch coordinates relative to, you need to transform them to be relative to that before doing the glReadPixels.

这篇关于在一个OpenGL多检测用户触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆