如何做检测对象在OpenGL的Android? [英] how to do Object detection in opengl Android?
问题描述
我已经开始与OpenGL ES的Android的,因为2周,尝试3D的例子后,我在obect检测stuckup。
点¯x之间基本上映射,屏幕y坐标为X,Y,三维空间和副Z A反之亦然。
I've started with OpenGl es for Android since 2 weeks and after trying 3D examples I'm stuckup at obect detection. Basically mapping between x,y coordinates of screen to x,y,z of 3d space and vice a versa.
我碰到:
GLU.gluProject(物objx,objY,objZ,型号,modelOffset,项目,projectOffset,查看,viewOffset,赢,winOffset);
GLU.gluUnProject(WINX,酒味,winZ,型号,modelOffset,项目,projectOffset,查看,viewOffset,OBJ,objOffset);
但我无法理解的我如何准确使用它们
在此先感谢,如果你可以用合适的例子详细说明。 :)
Thanks in advance if you can elaborate with suitable example. :)
推荐答案
好吧,如果你有你的矩阵准备好了,你可以这样做:
Well, if you have your matrices ready, you can do this:
float[] modelView = float[16];
float[] projection = float[16];
float[] view = {0, 0, 640, 480}; // viewport
float x = mouseX, y = mouseY, z = -1;
// those are the inputs
float[] pos = new float[4];
GLU.gluUnProject(x, y, z,
modelView, 0,
projection, 0,
world.view().get_size(), 0,
pos, 0);
System.out.println("position of mouse in 3D is (" + pos[0] + ", " + pos[1] + ", " + pos[2] + ")");
如果你要选择的对象,你可以调用gluUnProject()两次,第一次与Z = -1和Z = 1。这让你在远近飞机鼠标位置一次。减去他们获得一个视图方向,使用第一个为原点,并且已经得到了自己一个很好的光线追踪任务(对象选择)。
If you want to select objects, you call gluUnProject() twice, once with z = -1 and once with z = 1. That gives you mouse positions at the near and far planes. Subtract them to get a view direction, use the first as an origin, and you have got yourself a nice raytracing task (object selection).
这篇关于如何做检测对象在OpenGL的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!