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
[395 byte] By [chathuranga] at [2008-2-23]
# 1
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.

Nightmare_BE at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 2
Nightmare_BE wrote:
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.

Thanks very much friend

chathuranga at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 3
look at this link too if anyone looking for similar solution
http://dotnetforums.net/showthread.php?t=88480
chathuranga at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 4

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

Nightmare_BE at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 5
Is this principle also used for 3d shooters? When a mesh(person) is clicked, you have a hit?
PeterKiers at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 6
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.

TheZMan at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 7

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.

TheZMan at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...
# 8
hehe, thx for the info. The only thing I can make out of it, is that I have (and hope will) learn a lot :) But I'm working on it.
PeterKiers at 2007-9-9 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: General...