my solution about picking an object in opengl, but .........

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

my solution about picking an object in opengl, but .........

Postby sunnychu220 » Fri Jan 16, 2009 8:30 am

This is my thought, first get the screen coordinats of the 3d vextex, then check the touch screen point is in the shadow of the object on the screen。 To to this, we need to get the projected coordinate of a 3d point on the screen.
And I encountered a problem.
In opengl, this is simple:
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
gluProject(x1, y1, 0, modelview, projection, viewport, &winX, &winY, &winZ);

But in opengl es,there is no fuction “glGetDoublev”, So how can I get the matrix of modelview and projection?
sunnychu220
Freshman
Freshman
 
Posts: 5
Joined: Thu Jan 15, 2009 7:52 am

Top

Postby mortefer » Fri Jan 16, 2009 7:17 pm

I digged that question a bit - and didn't anything, so my answer is you cannot have current modelview matrix (at least with ES 1.0, ES 1.1 - once it's reliable - will be able to do that).
You can try to do the following: you know the position of the camera (set up using gluLookAt or smth similar), the size of the surface (you receive width and height whe surface is created) and FOV (u specified it for the projection matrix). Basing on that you can calculate a distance to an "imaginable" plane that represents your screen (this is plain trigonometry). After that you can calculate a ray that starts from the camera position and goes through the point you've clicked on the screen. Having this ray you can check if it goes through any of your polygons (try googlesearching for "Ray-Polygon intersection"). This might be a slow technique so you should consider limiting the objects you gonna check for intersections, throw away objects that are not in the frustum of the camera and so on.
This is basically how i do it, since no ModelView matrix is avail.
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Postby mortefer » Fri Jan 16, 2009 7:23 pm

On the other hand you can create a fake frustum (with FOV of 1 degree for example) and check what objects appear inside it (optimize the procedure by using bounding boxes of the objects, not all vertices). The great tutorial I started with can be found here
mortefer
Experienced Developer
Experienced Developer
 
Posts: 54
Joined: Sat Dec 20, 2008 11:24 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests