-
DX8 - Mouses and Meshes
Hi
I am using DX8 and am trying to determine if the mouse cursor is 'over' a mesh. I can imagine that this is possible using the bounding box of a mesh, however, I would like pixel perfect results. Is there any way of doing this please and if so what functions would be used?
Thanks in advance
Dan
-
Calculate the ray from screen space into world space (google), and then see if that ray intersects any of the triangles in the mesh. Use a sort of heirarchial sysytem of tests... first a bound sphere test. If a hit, test the BB, if yes, check each triangle. Google to find out intersection tests for each =).
Z.
-
Z
Thanks Z I was thinking along similar lines. The problem I am having is where does the ray go from / to. I know u can use the D3DXIntersect or D3DXMesh Intersect (something like that) to check for intersection with a mesh. I also know u can use D3DVec3Unproject to convert the mouse cursor position to world space.
U then make a ray from the unprojected position of the mouse to ??????????, see my problem!
With the lens flare problem the ray was from the camera to the sun but in this case there seems to be no way of determining the start/end pos of the ray.
NO luck on google so far on this one.
Any ideas
Thanks Dan
-
Simple enough. In screen coordinates, the ray starts at (mouse_x, mouse_y, 0.0), and ends at (mouse_x, mouse_y, 1.0). Simply transform both of those, and you find a line segment stretching from the point clicked on the near clip plane that stretches to the far clip plane. Subtract these vectors to find the direction, and you have your ray.
Z.