Пример #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 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);
        }
Пример #3
0
        protected void CreatePlanes(H1Vector3 InNormal, H1Vector3 InPosition, float InExtent)
        {
            H1Vector3 Origin = new H1Vector3(0, 0, 0);

            // generate first plane
            H1Vector3 PointOnPlane0 = InPosition + InNormal * InExtent;

            // calculate distance from origin
            float DistanceOnPlane0 = H1Vector3.Dot(PointOnPlane0 - Origin, InNormal);

            Planes[0] = new H1Plane(InNormal, DistanceOnPlane0);

            // generate second plane
            H1Vector3 PointOnPlane1 = InPosition - InNormal * InExtent;

            float DistanceOnPlane1 = H1Vector3.Dot(PointOnPlane1 - Origin, InNormal);

            Planes[1] = new H1Plane(InNormal, DistanceOnPlane1);
        }