Line of sight not working for animations

Topics: Developer Forum
Sep 11, 2007 at 3:47 PM
Edited Sep 11, 2007 at 3:49 PM
I’m trying to create a line of sight algorithm that allows the user to select a mesh with the mouse. So I have it working fine when there is no animation, but as soon as I try to run an animation nothing works. I guess what I’m asking is what world matrix do I need to apply to viewport.Unproject() so my line of sight ray is in the same space as the mesh I’m testing against? And this needs to happen while the model is animated.

I have been playing around with functions like: AnimationController.GetCurrentBoneTransform() and ModelAnimator.GetAbsoluteTransform() but I don’t think I’m using them right or not multiplying them in the right order or something. The following is the piece of code I’m working on:

...
Ray ray;
for (int i = 0; i < model.Meshes.Count; i++)
{
mesh = model.Meshes[i];
meshTransform = Matrix.Identity;

if (_controller != null)
{
//_modelAnimator.GetAbsoluteTransform()
BonePose p = _modelAnimator.BonePoses[mesh.ParentBone.Parent.Index];
meshTransform = _controller.GetCurrentBoneTransform(p);
}

//Every thing works fine if I have the correct World matrix.
//Gets the line of sight ray using Viewport.Unproject(): CalculateCursorRay(camera projection, camera view, world)
ray = game.GameCursor.CalculateCursorRay(cam.Projection, _cam.View, meshTransform);
...