私はこのマウスピッキングのものの上に私の髪を引っ張っています。問題は、私のレイの計算や、私のBoundingSpheresにある場合、私は知らないが、とにかくここに私の線計算のためのコードです:XNAマウスのピッキングに関する問題
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;
}
にISNようではありませんまったく働いていませんが、それは非常に不正確なようです。モデルは球だけで、とてもシンプルです。どのような助けや洞察力があれば幸いです。 ありがとう!
あなたのcameraPosition、球の中心、および半径の値はどのような値ですか?球がカメラから十分離れている場合(小数点以下の多くの場所など)、光線の方向を設定しながら浮動小数点精度が有効になります。これが当てはまると思われる場合は、レイをより良いチャンスにするためにfarSourseのZ値として10を使用してみてください(短いピストルバレルの代わりに長いライフルバレルで銃を目指すなど)。 –