Exemplo n.º 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))));
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        public static FMatrix CreateLookAt(FVector3 cameraPosition, FVector3 cameraTarget, FVector3 cameraUpVector)
        {
            FMatrix ret;

            CreateLookAt(ref cameraPosition, ref cameraTarget, ref cameraUpVector, out ret);
            return(ret);
        }
Exemplo n.º 6
0
 public static void CreateFromAxisAngle(ref FVector3 axis, float angle, out FMatrix result)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public static FMatrix CreateFromAxisAngle(FVector3 axis, float angle)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 public static void CreateConstrainedBillboard(ref FVector3 objectPosition, ref FVector3 cameraPosition,
                                               ref FVector3 rotateAxis, FVector3?cameraForwardVector,
                                               FVector3?objectForwardVector, out FMatrix result)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public static FMatrix CreateConstrainedBillboard(FVector3 objectPosition, FVector3 cameraPosition,
                                                  FVector3 rotateAxis, Nullable <FVector3> cameraForwardVector,
                                                  Nullable <FVector3> objectForwardVector)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Set this matrix to all zeros.
 /// </summary>
 public void SetZero()
 {
     ex = FVector3.Zero;
     ey = FVector3.Zero;
     ez = FVector3.Zero;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Construct this matrix using columns.
 /// </summary>
 /// <param name="c1">The c1.</param>
 /// <param name="c2">The c2.</param>
 /// <param name="c3">The c3.</param>
 public Mat33(FVector3 c1, FVector3 c2, FVector3 c3)
 {
     ex = c1;
     ey = c2;
     ez = c3;
 }
Exemplo n.º 12
0
 /// Perform the cross product on two vectors.
 public static FVector3 Cross(FVector3 a, FVector3 b)
 {
     return(new FVector3(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X));
 }
Exemplo n.º 13
0
 /// Perform the dot product on two vectors.
 public static float Dot(FVector3 a, FVector3 b)
 {
     return(a.X * b.X + a.Y * b.Y + a.Z * b.Z);
 }
Exemplo n.º 14
0
 /// Multiply a matrix times a vector.
 public static FVector3 Mul(Mat33 A, FVector3 v)
 {
     return(v.X * A.ex + v.Y * A.ey + v.Z * A.ez);
 }