Archived

This topic is now archived and is closed to further replies.

Chupacabra

Getting x,y pos in 3D

Recommended Posts

Hi, first of all this is not a "picking" problem where I want to select an object. Basically I am drawing a plane in 3D and I want to be able to click this plane and get the x and y coordinate of the plane on which I clicked. I don''t care about the z coordinate since the z coordinate is the same everywhere. I''ve tried gluUnproject but it doesn''t seem to give me what I want. Think diablo in 3D where you click on a certain point and the character moves there.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sounds like a simple ray -> plane intersection test. Create a ray IN VIEW space with the origin being the x,y of the mose click on the screen traveling strait out the z axis.

Transform this ray TO WORLDSPACE. This should make the ray originate from the camera/avatar/whatever object traveling to your plane of interest. Do a ray/plane intersection test to determine where they intersect.

TRANSFORM this point TO OBJECT SPACE. This should be the x,y that you want.

Share this post


Link to post
Share on other sites
Thanks alot for the help, worked like a charm. Except that I had to take call gluUnproject with parameter (SCREEN_HEIGHT - HIWORD(lParam)) in order to get the correct Y value. Took a while to figure that out.

Share this post


Link to post
Share on other sites