如何在opengl Android中进行对象检测?

发布于 2024-10-28 13:00:55 字数 462 浏览 1 评论 0原文

我已经开始使用 Android 版 OpenGL 了 2 周,在尝试了 3D 示例之后,我在对象检测方面遇到了困难。 基本上将屏幕的 x,y 坐标映射到 3d 空间的 x,y,z,反之亦然。

我遇到了:

GLU.gluProject(objX, objY, objZ, model, modelOffset, project, projectOffset, view, viewOffset, win, winOffset);

GLU.gluUnProject(winX, winY, winZ 、 model、modelOffset、project、projectOffset、view、viewOffset、obj、objOffset);

但我无法理解如何准确使用它们

如果您能用合适的例子详细说明,请提前致谢。 :)

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.

I came across :

GLU.gluProject(objX, objY, objZ, model, modelOffset, project, projectOffset, view, viewOffset, win, winOffset);

GLU.gluUnProject(winX, winY, winZ, model, modelOffset, project, projectOffset, view, viewOffset, obj, objOffset);

but i failed to understand that How do I use them exactly?

Thanks in advance if you can elaborate with suitable example. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无边思念无边月 2024-11-04 13:00:55

好吧,如果你准备好了矩阵,你可以这样做:

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。这样你就可以得到鼠标在近处和近处的位置。远位面。减去它们以获得视图方向,使用第一个作为原点,您就完成了一个很好的光线跟踪任务(对象选择)。

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] + ")");

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文