Archived

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

Graaf

mouse coordinates in 3d area

Recommended Posts

Graaf    122
Hi Guys, I''m just wondering how you would transform a mouse click on screen (x,y) into your 3d world and vice versa? For example, a model is drawn in front of you and when you click on it, some statistics appear. The question basically is, how can I determin that the location where you click with your mouse a model is drawn or not.Is there any way to map from the mouse click points to your 3d world to check if there''s a model in drawn?

Share this post


Link to post
Share on other sites
kmsixpence    134
This worked well in dx7 when i worked on my iso engine but what I did is create another drawing surface and render each object in a single color. Then just test when the mouse clicks what color they clicked on.

Share this post


Link to post
Share on other sites
CrazedGenius    156
yuo can also project the point as a ray that goes from the camera into the 3D scene and see what intersects that ray.

The color way works well in OpenGL (haven''t tried in DX), but performance is greatly improved if you can set things up to only render the pixel where the pointer is.

Share this post


Link to post
Share on other sites
C-Junkie    1099
I believe there was an example of how to do this in the DirectX 8.0 SDK. A little tiger rotated around and it highlited the triangle the mouse was pointing at.

Look at that program''s source

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You can use the D3DXIntersect() function from the D3DX utility library. It tests if a ray intersects a mesh. If the ray intersects more than one object pick the nearest one (D3DXIntersect() returns the distance). To speed up things you can use D3DXBoxBoundProbe() or D3DXSphereBoundProbe() as a "dirty" test to see if the ray intersects the object''s bounding box or sphere.

Share this post


Link to post
Share on other sites