Friday, February 24, 2012

iPhone opengl es: Touch detection


I have been messing around with opengl es on the iphone and right now I have some cubes on the screen. Currently I am trying to detect touches on these cubes. After a lot of searching on google this is what I have so far



  1. Use gluUnProject to find the x,y cordinates on the near plane in the world cordinate system

  2. Use gluUnProject to find the x,y cordinates on the far plane in the world cordinate system

  3. Subtract the vector obtained in 2 from the vector obtained in 1 to obtain the direction vector

  4. Normalize the direction vector to obtain the unit vector

  5. Iterate through all the trianlges and use the ray-triangle intersection to check if the ray intersects this triangle



I think my mistake is in step 5. I have a feeling I am supposed to transform my triangles by the modelview matrix? Is my assumption correct? If yes any clues how to transform a triangle (an array of 3 floats) by the modelview matrix (an array of 16 floats)

No comments:

Post a Comment