示例#1
0
        static uint BoxAndHalfSpace(H1Box InBox, H1Plane InPlane, ref H1CollisionDetectResult OutResult)
        {
            if (!H1PrimitiveIntersection.Intersect(InBox, InPlane))
            {
                return(0);
            }

            foreach (H1Vector3 BoxVertex in BoxVertices)
            {
                // calculate transformed box vertex
                H1Vector3 TransformedBoxVertex = H1Vector3.Transform(BoxVertex * InBox.HalfSize, InBox.Transform);

                // calculate the distance from the plane
                float VertexDistance = H1Vector3.Dot(TransformedBoxVertex, InPlane.Normal);

                // compare this to the plane's distance
                if (VertexDistance <= InPlane.Distance)
                {
                    // create the contact data
                    H1CollisionContact Contact = new H1CollisionContact();
                    Contact.ContactPoint  = InPlane.Normal;
                    Contact.ContactPoint *= (VertexDistance - InPlane.Distance);
                    Contact.ContactPoint += TransformedBoxVertex;

                    Contact.ContactNormal = InPlane.Normal;
                    Contact.Penetration   = InPlane.Distance - VertexDistance;

                    OutResult.Contacts.Add(Contact);
                }
            }

            return(Convert.ToUInt32(OutResult.Contacts.Count));
        }
 public static float TransformToAxis(H1Box InBox, H1Vector3 InAxis)
 {
     // think of quater-box (halfsize) end point projecting to InAxis
     // which gives maximum distance(by math.abs) toward axis from box
     return(InBox.HalfSize.X * Math.Abs(H1Vector3.Dot(InAxis, InBox.Transform.Axis0))
            + InBox.HalfSize.Y * Math.Abs(H1Vector3.Dot(InAxis, InBox.Transform.Axis1))
            + InBox.HalfSize.Z * Math.Abs(H1Vector3.Dot(InAxis, InBox.Transform.Axis2)));
 }
        public static bool Intersect(H1Box InBox, H1Plane InPlane)
        {
            // work out the projected radius of the box onto the plane direction
            float ProjectedRadius = TransformToAxis(InBox, InPlane.Normal);

            // work out how far the box is from the origin
            H1Vector3 BoxPosition = InBox.Transform.Axis3;
            float     BoxDistance = H1Vector3.Dot(InPlane.Normal, BoxPosition) - ProjectedRadius;

            // check for the intersection
            return(BoxDistance <= InPlane.Distance);
        }