How to make object discovery in opengl android?

I started with OpenGl es for Android from 2 weeks, and after I tried to use 3D examples, I focus on detecting obect. Basically the display between the x, y coordinates of the screen in x, y, z of three-dimensional space and vice 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 did not understand that How to use them exactly ?

Thanks in advance if you can develop a suitable example. :)

+4
source share
1 answer

Well, if you have ready-made matrices, 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. This gives you mouse positions in the near and far planes. Subtract them to get the viewing direction, use the first one as the source, and you have a good trace task (selecting an object).

+2
source

Source: https://habr.com/ru/post/1345876/


All Articles