나는이 마우스 따기 작업에서 내 머리카락을 잡아 당깁니다. 문제가 내 레이 계산 또는 내 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;
}
외설처럼하지 전혀 일하고 있지는 않지만 매우 부정확 한 것처럼 보입니다. 모델은 매우 단순한 구체입니다. 어떤 도움이나 통찰력이라도 대단히 감사하겠습니다! 감사합니다.
카메라 위치, 구면 중심 및 반지름의 값은 무엇입니까? 구가 카메라에서 멀리 떨어져 있으면 (10 진수 왼쪽의 많은 위치처럼) 광선 방향을 설정하는 동안 부동 소수점 정확도가 작용할 수 있습니다. 이것이 적용될 수 있다고 생각된다면, 레이를 더 나은 기회를주기 위해 farSourse의 Z 값으로 10을 사용하려고 시도하십시오 (짧은 권총 배럴 대신에 긴 라이플 배럴로 총을 겨냥하는 것과 같음). –