我正在把这头老鼠的头发拉出来。我不知道问题出在我的Ray计算或我的BoundingSpheres中,无论如何这里是我的光线计算的代码:
public Ray CalculateRay(InputManager input)
{
Vector3 nearSource = new Vector3(input.CurrentMousePosition, 0f);
Vector3 farSource = new Vector3(input.CurrentMousePosition, 1f);
Vector3 nearPoint = Engine.Device.Viewport.Unproject(nearSource, _projectionMatrix,
_viewMatrix, Matrix.Identity);
Vector3 farPoint = Engine.Device.Viewport.Unproject(farSource,
_projectionMatrix, _viewMatrix, Matrix.Identity);
Vector3 direction = farPoint - nearPoint;
direction.Normalize();
return new Ray(nearPoint, direction);
}
和交叉检查:
public bool RayIntersectsModel()
{
foreach (ModelMesh mesh in _model.Meshes)
{
BoundingSphere sphere = mesh.BoundingSphere;
sphere.Center = _position;
Ray ray = Engine.Camera.CalculateRay(Engine.Input);
if (sphere.Intersects(ray) != null)
{
return true;
}
}
return false;
}
它不像它根本不起作用,但它似乎非常不准确......或者其他东西。模型只是球体,非常简单。任何帮助或见解将不胜感激! 谢谢!
答案 0 :(得分:0)
好吧,当我改变我的边界球时,我首先应用了世界矩阵,然后是骨骼变换。这似乎把边界球放在了错误的地方。将其切换为首先应用骨骼转换然后世界矩阵就这样做了。