예제 #1
0
 public static Vector Cross(Vector v1, Vector v2)
 {
     return new Vector( (v1.y * v2.z) - (v1.z * v2.y),
                        (v1.z * v2.x) - (v1.x * v2.z),
                        (v1.x * v2.y) - (v1.y * v2.x)
                      );
 }
예제 #2
0
 public static Vector operator *(Vector v1, double factor)
 {
     Vector result = new Vector( v1.x * factor,
                                 v1.y * factor,
                                 v1.z * factor
                                );
     return result;
 }
예제 #3
0
 public static double Dot(Vector v1, Vector v2)
 {
     return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
 }
예제 #4
0
        public static Quaternion operator *(Quaternion q1, Quaternion q2)
        {
            if(q1 == null) return null;

            if(q2 == null) return null;

            Vector v1 = new Vector(q1.x, q1.y, q1.z);
            Vector v2 = new Vector(q2.x, q2.y, q2.z);

            double angle = ((q1.w * q2.w) - Vector.Dot(v1, v2));

            Vector cross = Vector.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;
        }