Ray intersection, Ray anything acctually, OpenGL-ES?
Is this possible to do with OpenGL-ES?
Im trying to make a quite simple 3D game in android with the use of OpenGL-ES. Now im stuck on the part where i think that using a ray to get the coordinates of a point on the surface of a sphere depending on 2D touch coordinates, would be the best way.
Im fairly new to 3D programming and openGL overall but all the tutorials iv'e found on the internet on how to achive this is by using methods Open开发者_C百科GL-ES don't support.
I guess using the inverse of my perspective projection transform is how it's supposed to be, but i hav'e now clue how to get that.
(Im setting up my perspective to 45 degrees with GLU.gluPerspective)
I have recently come across this as well as part of my bachelor-thesis. I haven't found a direct way to do this with opengl. What I have done is I have taken the x and y coordinates of the touch point. I then created two 3D points, one with the z-value 1 and one with z=-1. This gives you two different coordinates. And then you just take the inverse of your transformation matrix just as you guessed. If you manage the matrix yourself that shouldn't be too hard. If you let OpenGL manage the matrix you should be able to get the inversed matrix by calling gluUnproject (http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml). This will give you two points in object coordinates, now you have your ray, and now you can intersect this ray with all the objects you want to. (Here is an extensive list of intersection algorithms between different objects with code examples: http://www.realtimerendering.com/intersections.html)
Just in case you're interested: As part of my bachelor thesis I am creating a 3D Rendering Engine that should take a lot of this work away from the developer. It's still work in progress, but if you're interested, you can take a look: https://github.com/Chnoch/Bachelor-Thesis PM me if you'd like more information
精彩评论