how to detect a 3d sub mesh where the mouse is on
I'm trying to model a application where a 3d object is loaded from a .x file and I need to get the user input specifying which part of the object the user clicked on.
something like image map in 2d..... I need it in a 3d object (where it can be rotated...etc)
does anyone have ideas how to map between 3d sub meshes and get on which sub msh the user clicked on
Thanks in advance
U can use the ray intersect methods for this.
These function return information about the face intersected with the ray.
Look at the mesh function in the SDK docs, there are several ray intersection function.
I think u should only unproject vectors to do fustrum culling and stuff.
For mouse on mesh i would use the camera information.
You set your view transform using camera position (vEye) and camera target (vLookAt)
So i guess it would be better if u substract the camera target and position to use as ray for the intersect. u should also normalize the ray direction (result of substract). Using the far and near plane, hasnt any use i think cause a ray intersect will check if the ray is before or behind the object u want to intersect.
| |
vDir = Microsoft.DirectX.Vector3.Subtract(vLookat, vEye) vDir.normalize() If mesh.Intersect(vEye, vDir, ClosestHit) = True Then ... end if
|
NO, you absolutly need to use unproject as in the sample given above. The mouse coordinates are in screen space. Your mesh is most likely in object space. So you need to unproject through the projection matrix (giving you camera space), the view matrix (giving you world space) and the world (giving you object space) before you can use mesh.intersect.
It could be that one or more of those matrices is identity, but odds are if that is the case you understand the purpose of all those matrices well enough that you wouldn't be asking this question.
Yes pretty much, though in a 3rd person shooter you have to take into account the position of walls etc, to make sure you didn't succesfully shoot someone behind an object. Also using the screen coordinates is only useful for the player character. Other characters shooting each other need to set up their own ray to project and you can obviously do all of that in world space, requiring only a projections from world into object space for the mesh.intersection.