public static bool Raycast(Ray ray, Collider collider, RigidTransform colliderTransform, out RaycastResult result) { switch (collider.type) { case ColliderType.Sphere: { SphereCollider col = collider; return(Raycast(ray, col, colliderTransform, out result)); } case ColliderType.Capsule: { CapsuleCollider col = collider; return(Raycast(ray, col, colliderTransform, out result)); } case ColliderType.Box: { BoxCollider col = collider; return(Raycast(ray, col, colliderTransform, out result)); } case ColliderType.Compound: { CompoundCollider col = collider; return(Raycast(ray, col, colliderTransform, out result)); } default: result = default; return(false); } }
public static Aabb CalculateAabb(Collider collider, RigidTransform transform) { switch (collider.type) { case ColliderType.Sphere: SphereCollider sphere = collider; return(CalculateAabb(sphere, transform)); case ColliderType.Capsule: CapsuleCollider capsule = collider; return(CalculateAabb(capsule, transform)); case ColliderType.Box: BoxCollider box = collider; return(CalculateAabb(box, transform)); case ColliderType.Compound: CompoundCollider compound = collider; return(CalculateAabb(compound, transform)); default: ThrowUnsupportedType(); return(new Aabb()); } }
public static bool Raycast(Ray ray, CompoundCollider compound, RigidTransform compoundTransform, out RaycastResult result) { result = default; result.distance = float.MaxValue; bool hit = false; var rayInCompoundSpace = Ray.TransformRay(math.inverse(compoundTransform), ray); var scaledRay = new Ray(rayInCompoundSpace.start / compound.scale, rayInCompoundSpace.end / compound.scale); ref var blob = ref compound.compoundColliderBlob.Value;
public static Aabb CalculateAabb(CompoundCollider compound, RigidTransform transform) { var local = compound.compoundColliderBlob.Value.localAabb; float3 c = (local.min + local.max) / 2f; BoxCollider box = new BoxCollider(c, local.max - c); return(CalculateAabb(Physics.ScaleCollider(box, new PhysicsScale(compound.scale)), transform)); }
public static bool DistanceBetween(CompoundCollider compound, RigidTransform compoundTransform, SphereCollider sphere, RigidTransform sphereTransform, float maxDistance, out ColliderDistanceResult result) { bool hit = false; result = default; result.distance = float.MaxValue; ref var blob = ref compound.compoundColliderBlob.Value;
public static bool ColliderCast(SphereCollider sphereToCast, RigidTransform castStart, float3 castEnd, CompoundCollider targetCompound, RigidTransform targetCompoundTransform, out ColliderCastResult result) { bool hit = false; result = default; result.distance = float.MaxValue; ref var blob = ref targetCompound.compoundColliderBlob.Value;
public static Aabb CalculateAabb(CompoundCollider compound, RigidTransform transform) { var local = compound.compoundColliderBlob.Value.localAabb; float3 c = (local.min + local.max) / 2f; //BoxCollider box = new BoxCollider(c, local.max - c); //return CalculateAabb(box, transform); float3 extents = local.max - c; var rotMatrix = new float3x3(transform.rot); var worldExtents = LatiosMath.RotateExtents(extents, rotMatrix); var worldCenter = math.transform(transform, c); return(new Aabb(worldCenter - worldExtents, worldCenter + worldExtents)); }
public static bool DistanceBetween(Collider collider, RigidTransform colliderTransform, CapsuleCollider capsule, RigidTransform capsuleTransform, float maxDistance, out ColliderDistanceResult result) { switch (collider.type) { case ColliderType.Sphere: { SphereCollider col = collider; return(DistanceBetween(col, colliderTransform, capsule, capsuleTransform, maxDistance, out result)); } case ColliderType.Capsule: { CapsuleCollider col = collider; return(DistanceBetween(col, colliderTransform, capsule, capsuleTransform, maxDistance, out result)); } case ColliderType.Box: { BoxCollider col = collider; return(DistanceBetween(col, colliderTransform, capsule, capsuleTransform, maxDistance, out result)); } case ColliderType.Compound: { CompoundCollider col = collider; return(DistanceBetween(col, colliderTransform, capsule, capsuleTransform, maxDistance, out result)); } default: result = default; return(false); } }
public static bool ColliderCast(Collider colliderToCast, RigidTransform castStart, float3 castEnd, CapsuleCollider targetCapsule, RigidTransform targetCapsuleTransform, out ColliderCastResult result) { switch (colliderToCast.type) { case ColliderType.Sphere: { SphereCollider col = colliderToCast; return(ColliderCast(col, castStart, castEnd, targetCapsule, targetCapsuleTransform, out result)); } case ColliderType.Capsule: { CapsuleCollider col = colliderToCast; return(ColliderCast(col, castStart, castEnd, targetCapsule, targetCapsuleTransform, out result)); } case ColliderType.Box: { BoxCollider col = colliderToCast; return(ColliderCast(col, castStart, castEnd, targetCapsule, targetCapsuleTransform, out result)); } case ColliderType.Compound: { CompoundCollider col = colliderToCast; return(ColliderCast(col, castStart, castEnd, targetCapsule, targetCapsuleTransform, out result)); } default: result = default; return(false); } }
public static CompoundCollider ScaleCollider(CompoundCollider compound, PhysicsScale scale) { CheckNoOrUniformScale(scale, ColliderType.Compound); compound.scale *= scale.scale.x; return(compound); }