Exemplo n.º 1
0
        public static Boolean GetCollision(SphereCollision collidableA, RingCollision collidableB, out Vector3 position,
                                           out Vector3 normal)
        {
            // first let's get the collision parameters from the Plane Collision.
            SphereOnPlaneCollision.GetCollision(collidableA, collidableB, out var planeCollision, out var planeNormal,
                                                out var scale1, out var scale2);

            // Now get distance from our origin to the point planeCollision

            // transformation matrix 1
            var tm1 = collidableA.Parent.ScaleMatrix * collidableA.Parent.RotationMatrix;

            // transformation matrix 2
            var tm2 = collidableB.Parent.ScaleMatrix * collidableB.Parent.RotationMatrix;

            var sv1 = Vector3.Transform(collidableB.SpanVector1, tm2);
            var sv2 = Vector3.Transform(collidableB.SpanVector2, tm2);

            var distanceOnPlane = (scale1 * sv1 + scale2 * sv2).Length();

            var ringNorm = (scale1 * scale1 + scale2 * scale2) * collidableB.Radius;

            var ringScale1 = scale1 / ringNorm;
            var ringScale2 = scale2 / ringNorm;

            position = collidableB.Position + Vector3.Transform(collidableB.Origin, tm2) + ringScale1 * sv1 + ringScale2 * sv2;

            normal = collidableA.Position - position;
            var collide = normal.Length() < collidableA.Radius + collidableB.InnerRadius;

            normal.Normalize();

            return(collide);
        }
Exemplo n.º 2
0
        public static Boolean GetCollision(SphereCollision collidableA, BoundPlaneCollision collidableB, out Vector3 position,
                                           out Vector3 normal, out float scale1, out float scale2)
        {
            if (SphereOnPlaneCollision.GetCollision(collidableA, collidableB, out position, out normal, out scale1, out scale2))
            {
                //Console.WriteLine($"SOBPC @{collidableB.Position + collidableB.Origin} + {scale1} * {collidableB.SpanVector1} + {scale2} * {collidableB.SpanVector2} = {position}");


                return(collidableB.Restriction(scale1, scale2));
            }

            return(false);
        }