61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
namespace XCEngine
|
|
{
|
|
public static class Physics
|
|
{
|
|
public static bool Raycast(Vector3 origin, Vector3 direction)
|
|
{
|
|
RaycastHit hit;
|
|
return Raycast(origin, direction, out hit, float.MaxValue);
|
|
}
|
|
|
|
public static bool Raycast(Vector3 origin, Vector3 direction, float maxDistance)
|
|
{
|
|
RaycastHit hit;
|
|
return Raycast(origin, direction, out hit, maxDistance);
|
|
}
|
|
|
|
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hit)
|
|
{
|
|
return Raycast(origin, direction, out hit, float.MaxValue);
|
|
}
|
|
|
|
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hit, float maxDistance)
|
|
{
|
|
hit = default(RaycastHit);
|
|
|
|
if (float.IsNaN(maxDistance) || maxDistance <= 0.0f)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (float.IsPositiveInfinity(maxDistance))
|
|
{
|
|
maxDistance = float.MaxValue;
|
|
}
|
|
|
|
bool hasHit = InternalCalls.Physics_Raycast(
|
|
ref origin,
|
|
ref direction,
|
|
maxDistance,
|
|
out ulong hitGameObjectUUID,
|
|
out Vector3 hitPoint,
|
|
out Vector3 hitNormal,
|
|
out float hitDistance,
|
|
out int hitIsTrigger);
|
|
|
|
if (!hasHit)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
hit = new RaycastHit(
|
|
hitGameObjectUUID,
|
|
hitPoint,
|
|
hitNormal,
|
|
hitDistance,
|
|
hitIsTrigger != 0);
|
|
return true;
|
|
}
|
|
}
|
|
}
|