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
- Use gluUnProject to find the x,y cordinates on the near plane in the world cordinate system
- Use gluUnProject to find the x,y cordinates on the far plane in the world cordinate system
- Subtract the vector obtained in 2 from the vector obtained in 1 to obtain the direction vector
- Normalize the direction vector to obtain the unit vector
- 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)
Comments
Post a Comment