OpenGL Ray Collision Picking

This is an update to the Post I prior made, so you know what happened.

OpenGL Selecting and Picking via the old libraries will become obsolete,  I am not sure why, maybe because it requires drawing the geometry twice, which slows things down.  So I went with Ray cast into scene with two points to detect collisions.  On SudokuGeek this worked fine, except the detection is concave, and so I simplified it since the iphone has limited cpu power.  I went with the lowest detected distance from an object that the ray can collide with.  The hardest part here was getting a unproject function that worked on the iphone sdk.

1. glLoadIdentity() not the Models Matrix
OpenGL picking was frustrating, after much hunting for a solution, I found that I had to load a Identity Matrix for OpenGL picking to work correctly, many people try to load the Object Matrix and unproject that, which is incorrect.  For all platforms! Erhem.

2. Projection / Orthographic Mode affects Unprojecting;
You have to select the correct projection or orthographic projection, the same one you use to draw with to do detection properly.

3. Decide on Ray Sphere collision detection with the picked object.. This also assumes you have made/used a vector3 library which supports float multiplication to make a Ray cast into and towards the object you want to detect.  And a distance function between two points or spheres…

OpenGL is powerful, but with this power also comes requiring full customization.. GLU Unproject function is another library, and OpenGL doesn’t come with it Natively.  iPhone SDK doesn’t have GLU stuff, I know you can find a lib, I looked at this one in fact, but decided no.

In searching, I found another guys website which had doubles defined, the code was studied and made useful for me.
This website gave specifics, much like XNA’s projecting a Ray..  Called Ray Picking.
GNU Library General Public License
Since there is little info on this on the internet, GNU Library GPL allows me to charge a small fee for the modifications I made.
If you want a copy of what I did, you can request it and I’ll charge a small fee and assist as I can.

Essentially I took this code and modified it to work on the iPhone. I condensed down to what I needed. There is enough info to
recreate what I did on many different webpage sites. Contact me for fee’s to get the modified source and how to use it properly. I had
to scour a lot of my books and internet websites on how to get OpenGL Ray Collision to work for me.
Have fun.

You can add me as a friend and contact me on facebook eSpecialized My Phone Number is listed there
Feel free to share this page Bookmark and Share

Leave a Reply

iOS Dev, Reviews, New Apps, Release info and more.

eSpecialized's Developer Blog is using WP-Gravatar

Performance Optimization WordPress Plugins by W3 EDGE

Page optimized by WP Minify WordPress Plugin