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.Compound:
            {
                CompoundCollider col = collider;
                return(DistanceBetween(col, colliderTransform, capsule, capsuleTransform, maxDistance, out result));
            }

            default:
                result = default;
                return(false);
            }
        }
Esempio n. 2
0
        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.Compound:
            {
                CompoundCollider col = collider;
                return(Raycast(ray, col, colliderTransform, out result));
            }

            default:
                result = default;
                return(false);
            }
        }
        public static bool DistanceBetween(Collider colliderA,
                                           RigidTransform aTransform,
                                           Collider colliderB,
                                           RigidTransform bTransform,
                                           float maxDistance,
                                           out ColliderDistanceResult result)
        {
            switch (colliderA.type)
            {
            case ColliderType.Sphere:
            {
                SphereCollider colA = colliderA;
                return(DistanceBetween(colA, aTransform, colliderB, bTransform, maxDistance, out result));
            }

            case ColliderType.Capsule:
            {
                CapsuleCollider colA = colliderA;
                return(DistanceBetween(colA, aTransform, colliderB, bTransform, maxDistance, out result));
            }

            case ColliderType.Compound:
            {
                CompoundCollider colA = colliderA;
                return(DistanceBetween(colA, aTransform, colliderB, bTransform, maxDistance, out result));
            }

            default:
                result = default;
                return(false);
            }
        }
Esempio n. 4
0
        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());
            }
        }
Esempio n. 5
0
 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;
Esempio n. 6
0
        public static CompoundCollider ScaleCollider(CompoundCollider compound, PhysicsScale scale)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (scale.state == PhysicsScale.State.NonComputable | scale.state == PhysicsScale.State.NonUniform)
            {
                throw new InvalidOperationException("Error: Compound Collider must be scaled with no scale or uniform scale.");
            }
#endif
            compound.scale *= scale.scale.x;
            return(compound);
        }
        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;
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 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.Compound:
             CompoundCollider compound = collider;
             return CalculateAabb(compound, transform);
         default:
             throw new InvalidOperationException("Type not supported yet");
     }
 }
 public static CompoundCollider ScaleCollider(CompoundCollider compound, PhysicsScale scale)
 {
     CheckNoOrUniformScale(scale, ColliderType.Compound);
     compound.scale *= scale.scale.x;
     return(compound);
 }