示例#1
0
 /// <summary>
 /// Performs the dot product of two vectors.
 /// </summary>
 /// <param name="vec">The first vector.</param>
 /// <param name="vec2">The second vector.</param>
 /// <returns>The dot product.</returns>
 public static double Dot(Vec3D vec, Vec3D vec2)
 {
     return vec.X * vec2.X + vec.Y * vec2.Y + vec.Z * vec2.Z;
 }
示例#2
0
 /// <summary>
 /// Performs the cross product of two vectors.
 /// </summary>
 /// <param name="vec">The first vector.</param>
 /// <param name="vec2">The second vector.</param>
 /// <returns>The cross product.</returns>
 public static Vec3D Cross(Vec3D vec, Vec3D vec2)
 {
     return new Vec3D((vec.Y * vec2.Z) - (vec.Z * vec2.Y), (vec.Z * vec2.X) - (vec.X * vec2.Z), (vec.X * vec2.Y) - (vec.Y * vec2.X));
 }
示例#3
0
 /// <summary>
 /// Returns a translation matrix with the given offset.
 /// </summary>
 /// <param name="offset">The offset.</param>
 /// <returns>The translation matrix.</returns>
 public static Matrix4 Translation(Vec3D offset)
 {
     return new Matrix4(1, 0, 0, offset.X,
                        0, 1, 0, offset.Y,
                        0, 0, 1, offset.Z,
                        0, 0, 0, 1);
 }
示例#4
0
 /// <summary>
 /// Returns a scale matrix with the given scale.
 /// </summary>
 /// <param name="scale">The scale vector.</param>
 /// <returns>The scale matrix.</returns>
 public static Matrix4 Scale(Vec3D scale)
 {
     return new Matrix4(scale.X,       0,       0, 0,
                              0, scale.Y,       0, 0,
                              0,       0, scale.Z, 0,
                              0,       0,       0, 1);
 }
示例#5
0
 /// <summary>
 /// Returns a quaternion that rotates the given angle around the given axis.
 /// </summary>
 /// <param name="axis">The axis to rotate about.</param>
 /// <param name="angle">The amount to rotate.</param>
 /// <returns>The quaternion.</returns>
 public static Quaternion AxisAngle(Vec3D axis, double angle)
 {
     double sin = Math.Sin(angle / 2);
     return new Quaternion(axis.X * sin, axis.Y * sin, axis.Z * sin, Math.Cos(angle / 2));
 }
示例#6
0
 /// <summary>
 /// Scales the quaternion by the given scalar.
 /// </summary>
 /// <param name="quat">The quat.</param>
 /// <param name="val">The value.</param>
 /// <returns>The product quat.</returns>
 public static Quaternion operator *(Quaternion quat, double val)
 {
     double angle = 2 * Math.Acos(quat.W);
     Vec3D axis = new Vec3D(quat.X, quat.Y, quat.Z) / Math.Sqrt(1 - quat.W * quat.W);
     angle *= val;
     return AxisAngle(axis, angle);
 }