Ejemplo n.º 1
0
 /// <summary>
 /// Constructs the vector from another one.
 /// </summary>
 public Vector3D(Vector3D v)
 {
     this.X = v.X;
     this.Y = v.Y;
     this.Z = v.Z;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the cross product of two vectors.
 /// </summary>
 public static Vector3D Cross(Vector3D v1, Vector3D v2)
 {
     return new Vector3D(
         (v1.Y * v2.Z) - (v1.Z * v2.Y),
         (v1.Z * v2.X) - (v1.X * v2.Z),
         (v1.X * v2.Y) - (v1.Y * v2.X));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the dot product of two vectors.
 /// </summary>
 public static double Dot(Vector3D v1, Vector3D v2)
 {
     return (v1.X * v2.X) + (v1.Y * v2.Y) + (v1.Z * v2.Z);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Multiplies two quaternions together.
        /// </summary>
        public static Quaternion operator *(Quaternion q1, Quaternion q2)
        {
            // Ignore nulls
            if(q1 == null) return null;

            if(q2 == null) return null;

            // Create vectors from the values
            Vector3D v1 = new Vector3D(q1.X, q1.Y, q1.Z);
            Vector3D v2 = new Vector3D(q2.X, q2.Y, q2.Z);

            double angle = ((q1.W * q2.W) - Vector3D.Dot(v1, v2));

            Vector3D cross = Vector3D.Cross(v1, v2);

            v1 *= q2.W;
            v2 *= q1.W;

            Quaternion result = new Quaternion(angle,
                (v1.X + v2.X + cross.X),
                (v1.Y + v2.Y + cross.Y),
                (v1.Z + v2.Z + cross.Z));

            return result;
        }