关于 Android 中 3D 拾取的问题(使用 OpenGL ES 2)
我需要一些有关 3D 拾取的帮助。
我正在此处使用它的工作方式。简而言之,我所拥有的是:
normalizedPoint[0] = (x * 2 / screenW) -1;
normalizedPoint[1] = 1 - (y * 2 / screenH);
normalizedPoint[2] = ?
normalizedPoint[3] = ?
对于 2 和 3,我不知道它应该是什么(我把 1, -1 就像引用一样,它不起作用)
然后,对于我的根对象(下面只是 psuedo代码):
matrix = perspective_matrix x model_matrix
inv_matrix = inverse(matrix)
outpoint = inv_matrix x normalizedPoint
这就是我所拥有的,但它不起作用,我收到的 outPoint 甚至不接近我假设点击的点。我已经在网上搜索了一个多星期了。但不知道如何解决。帮助!
I need some help on 3D picking.
I am using the way it works here. In short, what I have is:
normalizedPoint[0] = (x * 2 / screenW) -1;
normalizedPoint[1] = 1 - (y * 2 / screenH);
normalizedPoint[2] = ?
normalizedPoint[3] = ?
for 2 and 3, I have no idea what it should be (I put 1, -1 just like the reference, and it doesn't work)
Then, for my root object (following just psuedo code):
matrix = perspective_matrix x model_matrix
inv_matrix = inverse(matrix)
outpoint = inv_matrix x normalizedPoint
That's what I have, but it doesn't work, the outPoint I receive is not even close to the point I am suppose clicking. I've been searching in web for more than a week. but no idea how to solve it. HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦。我实际上解决了这个问题。
我首先从 glUnproject 的源代码进行修改,使其具有以下内容:
上面的输入将是投影视图视锥体坐标中的点(即屏幕输入)。例如:
将 (30,50) 处的屏幕输入(单击)转换为对象所在的世界坐标。第三个参数
winz
实际上是点击发生在哪个投影平面上,这里0表示投影平面的nearZ。我制作拾取函数的方法是使用上述函数在远剪裁平面和近剪裁平面上取消投影两个点,因此:
一旦我们有了拾取射线,我所做的只是测试拾取射线和拾取射线之间的距离那些“可拾取”对象的“中心”。 (当然,你可以有一些更复杂的测试算法)。
Oh. I actually solved the problem, sort of.
I first, modify from the source code of glUnproject to have the following:
Input to the above would be the point in the Projected View Frustum Coordinates (i.e., screen input). For example:
will translate the screen input (click) at (30,50) to the world coordinate where the object is sitting at. The third parameter,
winz
is actually on which projected plane the click is occured, here, 0 means the nearZ of the projection plane.The way I make picking functions, is by unprojecting two points, using the above function, on the far and near clipping plane, so:
Once we have the picking ray, what I am doing is simply testing the distance between the picking ray and the "center" of those "pickable" objects. (of course, you can have some more sophisticated testing algorithm).