示例#1
0
        /// <summary>
        /// Solve A * x = b, where b is a column vector. This is more efficient
        /// than computing the inverse in one-shot cases.
        /// </summary>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public FVector3 Solve33(FVector3 b)
        {
            float det = FVector3.Dot(ex, FVector3.Cross(ey, ez));

            if (det != 0.0f)
            {
                det = 1.0f / det;
            }

            return(new FVector3(det * FVector3.Dot(b, FVector3.Cross(ey, ez)),
                                det * FVector3.Dot(ex, FVector3.Cross(b, ez)),
                                det * FVector3.Dot(ex, FVector3.Cross(ey, b))));
        }
示例#2
0
        public static void CreateBillboard(ref FVector3 objectPosition, ref FVector3 cameraPosition,
                                           ref FVector3 cameraUpVector, FVector3?cameraForwardVector, out FMatrix result)
        {
            FVector3 translation = objectPosition - cameraPosition;
            FVector3 backwards, right, up;

            FVector3.Normalize(ref translation, out backwards);
            FVector3.Normalize(ref cameraUpVector, out up);
            FVector3.Cross(ref backwards, ref up, out right);
            FVector3.Cross(ref backwards, ref right, out up);
            result             = Identity;
            result.Backward    = backwards;
            result.Right       = right;
            result.Up          = up;
            result.Translation = translation;
        }
示例#3
0
        public static void CreateWorld(ref FVector3 position, ref FVector3 forward, ref FVector3 up, out FMatrix result)
        {
            FVector3 x, y, z;

            FVector3.Normalize(ref forward, out z);
            FVector3.Cross(ref forward, ref up, out x);
            FVector3.Cross(ref x, ref forward, out y);
            x.Normalize();
            y.Normalize();

            result             = new FMatrix();
            result.Right       = x;
            result.Up          = y;
            result.Forward     = z;
            result.Translation = position;
            result.M44         = 1f;
        }
示例#4
0
        public static void CreateLookAt(ref FVector3 cameraPosition, ref FVector3 cameraTarget, ref FVector3 cameraUpVector,
                                        out FMatrix result)
        {
            // http://msdn.microsoft.com/en-us/library/bb205343(v=VS.85).aspx

            FVector3 vz = FVector3.Normalize(cameraPosition - cameraTarget);
            FVector3 vx = FVector3.Normalize(FVector3.Cross(cameraUpVector, vz));
            FVector3 vy = FVector3.Cross(vz, vx);

            result     = Identity;
            result.M11 = vx.X;
            result.M12 = vy.X;
            result.M13 = vz.X;
            result.M21 = vx.Y;
            result.M22 = vy.Y;
            result.M23 = vz.Y;
            result.M31 = vx.Z;
            result.M32 = vy.Z;
            result.M33 = vz.Z;
            result.M41 = -FVector3.Dot(vx, cameraPosition);
            result.M42 = -FVector3.Dot(vy, cameraPosition);
            result.M43 = -FVector3.Dot(vz, cameraPosition);
        }