Beispiel #1
0
 public FPlane(FPlane Plane)
 {
     this.X = Plane.X;
     this.Y = Plane.Y;
     this.Z = Plane.Z;
     this.D = Plane.D;
 }
 public FMirrorMatrix(FPlane plane)
 {
     InMatrix = new Matrix4(
         new Vector4(-2f * plane.X * plane.X + 1f, -2f * plane.Y * plane.X, -2f * plane.Z * plane.X, 0.0f).Normalized(),
         new Vector4(-2f * plane.X * plane.Y, -2f * plane.Y * plane.Y + 1f, -2f * plane.Z * plane.Y, 0.0f).Normalized(),
         new Vector4(-2f * plane.X * plane.Z, -2f * plane.Y * plane.Z, -2f * plane.Z * plane.Z + 1f, 0.0f).Normalized(),
         new Vector4(2f * plane.X * plane.D, 2f * plane.Y * plane.D, 2f * plane.Z * plane.D, 1.0f)
         );
 }
 public ConvexVolume(FPlane leftPlane, FPlane rightPlane, FPlane topPlane, FPlane bottomPlane, FPlane nearPlane, FPlane farPlane)
 {
     LeftPlane        = leftPlane;
     RightPlane       = rightPlane;
     TopPlane         = topPlane;
     BottomPlane      = bottomPlane;
     NearPlane        = nearPlane;
     FarPlane         = farPlane;
     relativePosition = RelativePosition.BEYOND_PLANE;
 }
Beispiel #4
0
        public override Vector3 GetNormalToIntersectedPosition(Vector3 position)
        {
            // Gather six planes, find the closest plane to incoming position
            // As we know plane equation Ax + By + Cz + D = 0
            // we must substitute in place of xyz incoming position and check when D is near a zero value

            Vector3 localSpaceExtent   = GetLocalSpaceExtent();
            Vector3 localSpacePosition = GetLocalSpaceOrigin();
            Vector3 tangentX           = GetTangetX();
            Vector3 tangentY           = GetTangetY();
            Vector3 tangentZ           = GetTangetZ();

            // find edge vertices for each plane of bounding box
            Vector3[] vertices = new Vector3[]
            {
                new Vector3(localSpacePosition.X + localSpaceExtent.X, localSpacePosition.Y, localSpacePosition.Z),
                new Vector3(localSpacePosition.X - localSpaceExtent.X, localSpacePosition.Y, localSpacePosition.Z),
                new Vector3(localSpacePosition.X, localSpacePosition.Y + localSpaceExtent.Y, localSpacePosition.Z),
                new Vector3(localSpacePosition.X, localSpacePosition.Y - localSpaceExtent.Y, localSpacePosition.Z),
                new Vector3(localSpacePosition.X, localSpacePosition.Y, localSpacePosition.Z + localSpaceExtent.Z),
                new Vector3(localSpacePosition.X, localSpacePosition.Y, localSpacePosition.Z - localSpaceExtent.Z)
            };

            for (Int32 i = 0; i < vertices.Length; i++)
            {
                vertices[i] = Vector3.TransformPosition(vertices[i], TransformationMatrix);
            }

            FPlane[] boundPlanes = new FPlane[6]
            {
                new FPlane(vertices[1], -tangentX), new FPlane(vertices[3], -tangentY), new FPlane(vertices[5], -tangentZ),
                new FPlane(vertices[0], tangentX), new FPlane(vertices[2], tangentY), new FPlane(vertices[4], tangentZ)
            };

            float  d            = float.MaxValue;
            FPlane closestPlane = null;

            foreach (FPlane plane in boundPlanes)
            {
                float distance = Vector3.Dot((Vector3)plane, position) - plane.D;
                if (Math.Abs(distance) < Math.Abs(d))
                {
                    closestPlane = plane;
                    d            = Math.Abs(distance);
                }
            }

            return((Vector3)closestPlane);
        }
 public ConvexVolume(Vector3 leftPoint, Vector3 leftNormal,
                     Vector3 rightPoint, Vector3 rightNormal,
                     Vector3 topPoint, Vector3 topNormal,
                     Vector3 bottomPoint, Vector3 bottomNormal,
                     Vector3 nearPoint, Vector3 nearNormal,
                     Vector3 farPoint, Vector3 farNormal)
 {
     LeftPlane        = new FPlane(leftPoint, leftNormal);
     RightPlane       = new FPlane(rightPoint, rightNormal);
     TopPlane         = new FPlane(topPoint, topNormal);
     BottomPlane      = new FPlane(bottomPoint, bottomNormal);
     NearPlane        = new FPlane(nearPoint, nearNormal);
     FarPlane         = new FPlane(farPoint, farNormal);
     relativePosition = RelativePosition.BEYOND_PLANE;
 }
Beispiel #6
0
        public override Vector3 GetNormalToIntersectedPosition(Vector3 position)
        {
            // Gather six planes, find the closest plane to incoming position
            // As we know plane equation Ax + By + Cz + D = 0
            // we must substitute in place of xyz incoming position and check when D is near a zero value

            Vector3 tangentSpaceExtent   = GetExtent();
            Vector3 tangentSpacePosition = GetOrigin();
            Vector3 tangentX             = GetTangetX();
            Vector3 tangentY             = GetTangetY();
            Vector3 tangentZ             = GetTangetZ();

            // find edge vertices for each plane of bounding box
            Vector3 edgeRight   = tangentSpacePosition + (tangentX * tangentSpaceExtent.X);
            Vector3 edgeLeft    = tangentSpacePosition - (tangentX * tangentSpaceExtent.X);
            Vector3 edgeUp      = tangentSpacePosition + (tangentY * tangentSpaceExtent.Y);
            Vector3 edgeDown    = tangentSpacePosition - (tangentY * tangentSpaceExtent.Y);
            Vector3 edgeForward = tangentSpacePosition + (tangentZ * tangentSpaceExtent.Z);
            Vector3 edgeBack    = tangentSpacePosition - (tangentZ * tangentSpaceExtent.Z);

            FPlane[] boundPlanes = new FPlane[6]
            {
                new FPlane(edgeLeft, -tangentX), new FPlane(edgeDown, -tangentY), new FPlane(edgeBack, -tangentZ),
                new FPlane(edgeRight, tangentX), new FPlane(edgeUp, tangentY), new FPlane(edgeForward, tangentZ)
            };

            float  d            = float.MaxValue;
            FPlane closestPlane = null;

            foreach (FPlane plane in boundPlanes)
            {
                float distance = Vector3.Dot((Vector3)plane, position) - plane.D;
                if (Math.Abs(distance) < Math.Abs(d))
                {
                    closestPlane = plane;
                    d            = Math.Abs(distance);
                }
            }

            return((Vector3)closestPlane);
        }
        public ConvexVolume(Matrix4 ViewProjectionMatrix)
        {
            // Right clipping plane.
            RightPlane = new FPlane(new Vector4(ViewProjectionMatrix.M14 - ViewProjectionMatrix.M11, ViewProjectionMatrix.M24 - ViewProjectionMatrix.M21, ViewProjectionMatrix.M34 - ViewProjectionMatrix.M31, ViewProjectionMatrix.M44 - ViewProjectionMatrix.M41));
            // Left clipping plane.
            LeftPlane = new FPlane(new Vector4(ViewProjectionMatrix.M14 + ViewProjectionMatrix.M11, ViewProjectionMatrix.M24 + ViewProjectionMatrix.M21, ViewProjectionMatrix.M34 + ViewProjectionMatrix.M31, ViewProjectionMatrix.M44 + ViewProjectionMatrix.M41));
            // Bottom clipping plane.
            BottomPlane = new FPlane(new Vector4(ViewProjectionMatrix.M14 + ViewProjectionMatrix.M12, ViewProjectionMatrix.M24 + ViewProjectionMatrix.M22, ViewProjectionMatrix.M34 + ViewProjectionMatrix.M32, ViewProjectionMatrix.M44 + ViewProjectionMatrix.M42));
            // Top clipping plane.
            TopPlane = new FPlane(new Vector4(ViewProjectionMatrix.M14 - ViewProjectionMatrix.M12, ViewProjectionMatrix.M24 - ViewProjectionMatrix.M22, ViewProjectionMatrix.M34 - ViewProjectionMatrix.M32, ViewProjectionMatrix.M44 - ViewProjectionMatrix.M42));
            // Far clipping plane.
            FarPlane = new FPlane(new Vector4(ViewProjectionMatrix.M14 - ViewProjectionMatrix.M13, ViewProjectionMatrix.M24 - ViewProjectionMatrix.M23, ViewProjectionMatrix.M34 - ViewProjectionMatrix.M33, ViewProjectionMatrix.M44 - ViewProjectionMatrix.M43));
            // Near clipping plane.
            NearPlane = new FPlane(new Vector4(ViewProjectionMatrix.M13, ViewProjectionMatrix.M23, ViewProjectionMatrix.M33, ViewProjectionMatrix.M43));

            // This is not always necessary...
            for (Int32 i = 0; i < 6; i++)
            {
                Vector3 Normalized = new Vector3(this[i].X, this[i].Y, this[i].Z).Normalized();
                this[i] = new FPlane(new Vector4(Normalized, this[i].D));
            }
        }