Beispiel #1
0
        /// <summary>
        /// Creates a world matrix pointing from a position to a target with the given up vector.
        /// </summary>
        /// <param name="position">Position of the transform.</param>
        /// <param name="forward">Forward direction of the transformation.</param>
        /// <param name="upVector">Up vector which is crossed against the forward vector to compute the transform's basis.</param>
        /// <param name="worldSystemMatrix4x4">World matrix.</param>
        public static void CreateWorldRH(ref System.Numerics.Vector3 position, ref System.Numerics.Vector3 forward, ref System.Numerics.Vector3 upVector, out System.Numerics.Matrix4x4 worldSystemMatrix4x4)
        {
            System.Numerics.Vector3 z;
            float length = forward.Length();
            Vector3Ex.Divide(ref forward, -length, out z);
            System.Numerics.Vector3 x;
            Vector3Ex.Cross(ref upVector, ref z, out x);
            x.Normalize();
            System.Numerics.Vector3 y;
            Vector3Ex.Cross(ref z, ref x, out y);

            worldSystemMatrix4x4.M11 = x.X;
            worldSystemMatrix4x4.M12 = x.Y;
            worldSystemMatrix4x4.M13 = x.Z;
            worldSystemMatrix4x4.M14 = 0f;
            worldSystemMatrix4x4.M21 = y.X;
            worldSystemMatrix4x4.M22 = y.Y;
            worldSystemMatrix4x4.M23 = y.Z;
            worldSystemMatrix4x4.M24 = 0f;
            worldSystemMatrix4x4.M31 = z.X;
            worldSystemMatrix4x4.M32 = z.Y;
            worldSystemMatrix4x4.M33 = z.Z;
            worldSystemMatrix4x4.M34 = 0f;

            worldSystemMatrix4x4.M41 = position.X;
            worldSystemMatrix4x4.M42 = position.Y;
            worldSystemMatrix4x4.M43 = position.Z;
            worldSystemMatrix4x4.M44 = 1f;
        }
Beispiel #2
0
 /// <summary>
 /// Computes a convex shape description for a TransformableShape.
 /// </summary>
 ///<param name="vA">First local vertex in the triangle.</param>
 ///<param name="vB">Second local vertex in the triangle.</param>
 ///<param name="vC">Third local vertex in the triangle.</param>
 ///<param name="collisionMargin">Collision margin of the shape.</param>
 /// <returns>Description required to define a convex shape.</returns>
 public static ConvexShapeDescription ComputeDescription(System.Numerics.Vector3 vA, System.Numerics.Vector3 vB, System.Numerics.Vector3 vC, float collisionMargin)
 {
     ConvexShapeDescription description;
     description.EntityShapeVolume.Volume = System.Numerics.Vector3.Cross(vB - vA, vC - vA).Length() * collisionMargin; // ratherapproximate.
     description.EntityShapeVolume.VolumeDistribution = new Matrix3x3();
     description.MinimumRadius = collisionMargin;
     description.MaximumRadius = collisionMargin + Math.Max(vA.Length(), Math.Max(vB.Length(), vC.Length()));
     description.CollisionMargin = collisionMargin;
     return description;
 }
Beispiel #3
0
        /// <summary>
        /// Creates a view matrix pointing looking in a direction with a given up vector.
        /// </summary>
        /// <param name="position">Position of the camera.</param>
        /// <param name="forward">Forward direction of the camera.</param>
        /// <param name="upVector">Up vector of the camera.</param>
        /// <param name="viewSystem.Numerics.Matrix4x4">Look at matrix.</param>
        public static void CreateViewRH(ref System.Numerics.Vector3 position, ref System.Numerics.Vector3 forward, ref System.Numerics.Vector3 upVector, out System.Numerics.Matrix4x4 viewSystemMatrix4x4)
        {
            System.Numerics.Vector3 z;
            float length = forward.Length();
            Vector3Ex.Divide(ref forward, -length, out z);
            System.Numerics.Vector3 x;
            Vector3Ex.Cross(ref upVector, ref z, out x);
            x.Normalize();
            System.Numerics.Vector3 y;
            Vector3Ex.Cross(ref z, ref x, out y);

            viewSystemMatrix4x4.M11 = x.X;
            viewSystemMatrix4x4.M12 = y.X;
            viewSystemMatrix4x4.M13 = z.X;
            viewSystemMatrix4x4.M14 = 0f;
            viewSystemMatrix4x4.M21 = x.Y;
            viewSystemMatrix4x4.M22 = y.Y;
            viewSystemMatrix4x4.M23 = z.Y;
            viewSystemMatrix4x4.M24 = 0f;
            viewSystemMatrix4x4.M31 = x.Z;
            viewSystemMatrix4x4.M32 = y.Z;
            viewSystemMatrix4x4.M33 = z.Z;
            viewSystemMatrix4x4.M34 = 0f;
            Vector3Ex.Dot(ref x, ref position, out viewSystemMatrix4x4.M41);
            Vector3Ex.Dot(ref y, ref position, out viewSystemMatrix4x4.M42);
            Vector3Ex.Dot(ref z, ref position, out viewSystemMatrix4x4.M43);
            viewSystemMatrix4x4.M41 = -viewSystemMatrix4x4.M41;
            viewSystemMatrix4x4.M42 = -viewSystemMatrix4x4.M42;
            viewSystemMatrix4x4.M43 = -viewSystemMatrix4x4.M43;
            viewSystemMatrix4x4.M44 = 1f;
        }