Пример #1
0
 /// <summary>
 /// Modifies the translational components of this matrix to the values
 /// of the Vector3f argument; the other values of this matrix are not
 /// modified.
 /// </summary>
 /// <remarks>
 /// Modifies the translational components of this matrix to the values
 /// of the Vector3f argument; the other values of this matrix are not
 /// modified.
 /// </remarks>
 /// <param name="trans">the translational component</param>
 public void SetTranslation(Vector3f trans)
 {
     m03 = trans.x;
     m13 = trans.y;
     m23 = trans.z;
 }
Пример #2
0
 /// <summary>
 /// Sets the value of this transform to a scale and translation matrix;
 /// the translation is scaled by the scale factor and all of the matrix
 /// values are modified.
 /// </summary>
 /// <remarks>
 /// Sets the value of this transform to a scale and translation matrix;
 /// the translation is scaled by the scale factor and all of the matrix
 /// values are modified.
 /// </remarks>
 /// <param name="t1">the translation amount</param>
 /// <param name="scale">the scale factor for the matrix</param>
 public void Set(Vector3f t1, float scale)
 {
     this.m00 = scale;
     this.m01 = (float)0.0;
     this.m02 = (float)0.0;
     this.m03 = scale * t1.x;
     this.m10 = (float)0.0;
     this.m11 = scale;
     this.m12 = (float)0.0;
     this.m13 = scale * t1.y;
     this.m20 = (float)0.0;
     this.m21 = (float)0.0;
     this.m22 = scale;
     this.m23 = scale * t1.z;
     this.m30 = (float)0.0;
     this.m31 = (float)0.0;
     this.m32 = (float)0.0;
     this.m33 = (float)1.0;
 }
Пример #3
0
 /// <summary>
 /// Constructs and initializes a Matrix4f from the rotation matrix,
 /// translation, and scale values; the scale is applied only to the
 /// rotational components of the matrix (upper 3x3) and not to the
 /// translational components of the matrix.
 /// </summary>
 /// <remarks>
 /// Constructs and initializes a Matrix4f from the rotation matrix,
 /// translation, and scale values; the scale is applied only to the
 /// rotational components of the matrix (upper 3x3) and not to the
 /// translational components of the matrix.
 /// </remarks>
 /// <param name="m1">the rotation matrix representing the rotational components</param>
 /// <param name="t1">the translational components of the matrix</param>
 /// <param name="s">the scale value applied to the rotational components</param>
 public Matrix4f(Matrix3f m1, Vector3f t1, float s)
 {
     this.m00 = m1.m00 * s;
     this.m01 = m1.m01 * s;
     this.m02 = m1.m02 * s;
     this.m03 = t1.x;
     this.m10 = m1.m10 * s;
     this.m11 = m1.m11 * s;
     this.m12 = m1.m12 * s;
     this.m13 = t1.y;
     this.m20 = m1.m20 * s;
     this.m21 = m1.m21 * s;
     this.m22 = m1.m22 * s;
     this.m23 = t1.z;
     this.m30 = 0.0f;
     this.m31 = 0.0f;
     this.m32 = 0.0f;
     this.m33 = 1.0f;
 }
Пример #4
0
 /// <summary>
 /// Sets the value of this matrix from the rotation expressed by
 /// the rotation matrix m1, the translation t1, and the scale factor.
 /// </summary>
 /// <remarks>
 /// Sets the value of this matrix from the rotation expressed by
 /// the rotation matrix m1, the translation t1, and the scale factor.
 /// The translation is not modified by the scale.
 /// </remarks>
 /// <param name="m1">the rotation component</param>
 /// <param name="t1">the translation component</param>
 /// <param name="scale">the scale component</param>
 public void Set(Matrix3f m1, Vector3f t1, float scale)
 {
     this.m00 = m1.m00 * scale;
     this.m01 = m1.m01 * scale;
     this.m02 = m1.m02 * scale;
     this.m03 = t1.x;
     this.m10 = m1.m10 * scale;
     this.m11 = m1.m11 * scale;
     this.m12 = m1.m12 * scale;
     this.m13 = t1.y;
     this.m20 = m1.m20 * scale;
     this.m21 = m1.m21 * scale;
     this.m22 = m1.m22 * scale;
     this.m23 = t1.z;
     this.m30 = 0.0;
     this.m31 = 0.0;
     this.m32 = 0.0;
     this.m33 = 1.0;
 }
Пример #5
0
 /// <summary>
 /// Sets the value of this matrix to a translate matrix with
 /// the passed translation value.
 /// </summary>
 /// <remarks>
 /// Sets the value of this matrix to a translate matrix with
 /// the passed translation value.
 /// </remarks>
 /// <param name="v1">the translation amount</param>
 public void Set(Vector3f v1)
 {
     this.m00 = (float)1.0;
     this.m01 = (float)0.0;
     this.m02 = (float)0.0;
     this.m03 = v1.x;
     this.m10 = (float)0.0;
     this.m11 = (float)1.0;
     this.m12 = (float)0.0;
     this.m13 = v1.y;
     this.m20 = (float)0.0;
     this.m21 = (float)0.0;
     this.m22 = (float)1.0;
     this.m23 = v1.z;
     this.m30 = (float)0.0;
     this.m31 = (float)0.0;
     this.m32 = (float)0.0;
     this.m33 = (float)1.0;
 }
Пример #6
0
 /// <summary>Retrieves the translational components of this matrix.</summary>
 /// <remarks>Retrieves the translational components of this matrix.</remarks>
 /// <param name="trans">the vector that will receive the translational component</param>
 public void Get(Vector3f trans)
 {
     trans.x = m03;
     trans.y = m13;
     trans.z = m23;
 }
Пример #7
0
 /// <summary>
 /// Copies the matrix values in the specified column into the vector
 /// parameter.
 /// </summary>
 /// <remarks>
 /// Copies the matrix values in the specified column into the vector
 /// parameter.
 /// </remarks>
 /// <param name="column">the matrix column</param>
 /// <param name="v">the vector into which the matrix row values will be copied</param>
 public void GetColumn(int column, Vector3f v)
 {
     if (column == 0)
     {
         v.x = m00;
         v.y = m10;
         v.z = m20;
     }
     else
     {
         if (column == 1)
         {
             v.x = m01;
             v.y = m11;
             v.z = m21;
         }
         else
         {
             if (column == 2)
             {
                 v.x = m02;
                 v.y = m12;
                 v.z = m22;
             }
             else
             {
                 throw new IndexOutOfRangeException("Matrix3d getColumn");
             }
         }
     }
 }
Пример #8
0
 /// <summary>Constructs and initializes a Vector3f from the specified Vector3f.</summary>
 /// <remarks>Constructs and initializes a Vector3f from the specified Vector3f.</remarks>
 /// <param name="v1">the Vector3f containing the initialization x y z data</param>
 public Vector3f(Vector3f v1)
     : base(v1)
 {
 }
Пример #9
0
 /// <summary>
 /// Constructs and initializes an AxisAngle4f from the specified
 /// axis and angle.
 /// </summary>
 /// <remarks>
 /// Constructs and initializes an AxisAngle4f from the specified
 /// axis and angle.
 /// </remarks>
 /// <param name="axis">the axis</param>
 /// <param name="angle">the angle of rotation in radians</param>
 /// <since>vecmath 1.2</since>
 public AxisAngle4f(Vector3f axis, float angle)
 {
     this.x = axis.x;
     this.y = axis.y;
     this.z = axis.z;
     this.angle = angle;
 }
Пример #10
0
 /// <summary>Computes the dot product of this vector and vector v1.</summary>
 /// <remarks>Computes the dot product of this vector and vector v1.</remarks>
 /// <param name="v1">the other vector</param>
 /// <returns>the dot product of this vector and v1</returns>
 public float Dot(Vector3f v1)
 {
     return (this.x * v1.x + this.y * v1.y + this.z * v1.z);
 }
Пример #11
0
 /// <summary>Sets the value of this vector to the normalization of vector v1.</summary>
 /// <remarks>Sets the value of this vector to the normalization of vector v1.</remarks>
 /// <param name="v1">the un-normalized vector</param>
 public void Normalize(Vector3f v1)
 {
     float norm;
     norm = (float)(1.0 / Math.Sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z));
     this.x = v1.x * norm;
     this.y = v1.y * norm;
     this.z = v1.z * norm;
 }
Пример #12
0
 /// <summary>Sets this vector to be the vector cross product of vectors v1 and v2.</summary>
 /// <remarks>Sets this vector to be the vector cross product of vectors v1 and v2.</remarks>
 /// <param name="v1">the first vector</param>
 /// <param name="v2">the second vector</param>
 public void Cross(Vector3f v1, Vector3f v2)
 {
     float x;
     float y;
     x = v1.y * v2.z - v1.z * v2.y;
     y = v2.x * v1.z - v2.z * v1.x;
     this.z = v1.x * v2.y - v1.y * v2.x;
     this.x = x;
     this.y = y;
 }
Пример #13
0
 /// <summary>
 /// Returns the angle in radians between this vector and the vector
 /// parameter; the return value is constrained to the range [0,PI].
 /// </summary>
 /// <remarks>
 /// Returns the angle in radians between this vector and the vector
 /// parameter; the return value is constrained to the range [0,PI].
 /// </remarks>
 /// <param name="v1">the other vector</param>
 /// <returns>the angle in radians in the range [0,PI]</returns>
 public float Angle(Vector3f v1)
 {
     double vDot = this.Dot(v1) / (this.Length() * v1.Length());
     if (vDot < -1.0)
     {
         vDot = -1.0;
     }
     if (vDot > 1.0)
     {
         vDot = 1.0;
     }
     return ((float)(Math.Acos(vDot)));
 }
Пример #14
0
 /// <summary>
 /// Transforms the normal parameter by this transform and places the value
 /// back into normal.
 /// </summary>
 /// <remarks>
 /// Transforms the normal parameter by this transform and places the value
 /// back into normal.  The fourth element of the normal is assumed to be zero.
 /// </remarks>
 /// <param name="normal">the input normal to be transformed.</param>
 public void Transform(Vector3f normal)
 {
     float x;
     float y;
     x = (float)(m00 * normal.x + m01 * normal.y + m02 * normal.z);
     y = (float)(m10 * normal.x + m11 * normal.y + m12 * normal.z);
     normal.z = (float)(m20 * normal.x + m21 * normal.y + m22 * normal.z);
     normal.x = x;
     normal.y = y;
 }
Пример #15
0
 /// <summary>
 /// Transforms the normal parameter by this transform and places the value
 /// back into normal.
 /// </summary>
 /// <remarks>
 /// Transforms the normal parameter by this transform and places the value
 /// back into normal.  The fourth element of the normal is assumed to be zero.
 /// </remarks>
 /// <param name="normal">the input normal to be transformed.</param>
 public void Transform(Vector3f normal)
 {
     float x;
     float y;
     x = m00 * normal.x + m01 * normal.y + m02 * normal.z;
     y = m10 * normal.x + m11 * normal.y + m12 * normal.z;
     normal.z = m20 * normal.x + m21 * normal.y + m22 * normal.z;
     normal.x = x;
     normal.y = y;
 }
Пример #16
0
 /// <summary>
 /// Sets the value of this AxisAngle4f to the specified
 /// axis and angle.
 /// </summary>
 /// <remarks>
 /// Sets the value of this AxisAngle4f to the specified
 /// axis and angle.
 /// </remarks>
 /// <param name="axis">the axis</param>
 /// <param name="angle">the angle of rotation in radians</param>
 /// <since>vecmath 1.2</since>
 public void Set(Vector3f axis, float angle)
 {
     this.x = axis.x;
     this.y = axis.y;
     this.z = axis.z;
     this.angle = angle;
 }
Пример #17
0
 /// <summary>
 /// Performs an SVD normalization of this matrix to calculate
 /// the rotation as a 3x3 matrix, the translation, and the scale.
 /// </summary>
 /// <remarks>
 /// Performs an SVD normalization of this matrix to calculate
 /// the rotation as a 3x3 matrix, the translation, and the scale.
 /// None of the matrix values are modified.
 /// </remarks>
 /// <param name="m1">the normalized matrix representing the rotation</param>
 /// <param name="t1">the translation component</param>
 /// <returns>the scale component of this transform</returns>
 public float Get(Matrix3f m1, Vector3f t1)
 {
     double[] tmp_rot = new double[9];
     // scratch matrix
     double[] tmp_scale = new double[3];
     // scratch matrix
     GetScaleRotate(tmp_scale, tmp_rot);
     m1.m00 = (float)tmp_rot[0];
     m1.m01 = (float)tmp_rot[1];
     m1.m02 = (float)tmp_rot[2];
     m1.m10 = (float)tmp_rot[3];
     m1.m11 = (float)tmp_rot[4];
     m1.m12 = (float)tmp_rot[5];
     m1.m20 = (float)tmp_rot[6];
     m1.m21 = (float)tmp_rot[7];
     m1.m22 = (float)tmp_rot[8];
     t1.x = m03;
     t1.y = m13;
     t1.z = m23;
     return ((float)Matrix3d.Max3(tmp_scale));
 }
Пример #18
0
 /// <summary>
 /// Constructs and initializes a Matrix4f from the quaternion,
 /// translation, and scale values; the scale is applied only to the
 /// rotational components of the matrix (upper 3x3) and not to the
 /// translational components.
 /// </summary>
 /// <remarks>
 /// Constructs and initializes a Matrix4f from the quaternion,
 /// translation, and scale values; the scale is applied only to the
 /// rotational components of the matrix (upper 3x3) and not to the
 /// translational components.
 /// </remarks>
 /// <param name="q1">the quaternion value representing the rotational component</param>
 /// <param name="t1">the translational component of the matrix</param>
 /// <param name="s">the scale value applied to the rotational components</param>
 public Matrix4f(Quat4f q1, Vector3f t1, float s)
 {
     m00 = (float)(s * (1.0 - 2.0 * q1.y * q1.y - 2.0 * q1.z * q1.z));
     m10 = (float)(s * (2.0 * (q1.x * q1.y + q1.w * q1.z)));
     m20 = (float)(s * (2.0 * (q1.x * q1.z - q1.w * q1.y)));
     m01 = (float)(s * (2.0 * (q1.x * q1.y - q1.w * q1.z)));
     m11 = (float)(s * (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.z * q1.z));
     m21 = (float)(s * (2.0 * (q1.y * q1.z + q1.w * q1.x)));
     m02 = (float)(s * (2.0 * (q1.x * q1.z + q1.w * q1.y)));
     m12 = (float)(s * (2.0 * (q1.y * q1.z - q1.w * q1.x)));
     m22 = (float)(s * (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.y * q1.y));
     m03 = t1.x;
     m13 = t1.y;
     m23 = t1.z;
     m30 = 0.0f;
     m31 = 0.0f;
     m32 = 0.0f;
     m33 = 1.0f;
 }
Пример #19
0
        /// <summary>Sets the specified row of this matrix3f to the Vector provided.</summary>
        /// <remarks>Sets the specified row of this matrix3f to the Vector provided.</remarks>
        /// <param name="row">the row number to be modified (zero indexed)</param>
        /// <param name="v">the replacement row</param>
        public void SetRow(int row, Vector3f v)
        {
            switch (row)
            {
                case 0:
                {
                    this.m00 = v.x;
                    this.m01 = v.y;
                    this.m02 = v.z;
                    break;
                }

                case 1:
                {
                    this.m10 = v.x;
                    this.m11 = v.y;
                    this.m12 = v.z;
                    break;
                }

                case 2:
                {
                    this.m20 = v.x;
                    this.m21 = v.y;
                    this.m22 = v.z;
                    break;
                }

                default:
                {
                    throw new IndexOutOfRangeException("Matrix3f setRow");
                }
            }
        }
Пример #20
0
 /// <summary>
 /// Sets the value of this matrix from the rotation expressed
 /// by the quaternion q1, the translation t1, and the scale s.
 /// </summary>
 /// <remarks>
 /// Sets the value of this matrix from the rotation expressed
 /// by the quaternion q1, the translation t1, and the scale s.
 /// </remarks>
 /// <param name="q1">the rotation expressed as a quaternion</param>
 /// <param name="t1">the translation</param>
 /// <param name="s">the scale value</param>
 public void Set(Quat4f q1, Vector3f t1, float s)
 {
     this.m00 = (s * (1.0f - 2.0f * q1.y * q1.y - 2.0f * q1.z * q1.z));
     this.m10 = (s * (2.0f * (q1.x * q1.y + q1.w * q1.z)));
     this.m20 = (s * (2.0f * (q1.x * q1.z - q1.w * q1.y)));
     this.m01 = (s * (2.0f * (q1.x * q1.y - q1.w * q1.z)));
     this.m11 = (s * (1.0f - 2.0f * q1.x * q1.x - 2.0f * q1.z * q1.z));
     this.m21 = (s * (2.0f * (q1.y * q1.z + q1.w * q1.x)));
     this.m02 = (s * (2.0f * (q1.x * q1.z + q1.w * q1.y)));
     this.m12 = (s * (2.0f * (q1.y * q1.z - q1.w * q1.x)));
     this.m22 = (s * (1.0f - 2.0f * q1.x * q1.x - 2.0f * q1.y * q1.y));
     this.m03 = t1.x;
     this.m13 = t1.y;
     this.m23 = t1.z;
     this.m30 = (float)0.0;
     this.m31 = (float)0.0;
     this.m32 = (float)0.0;
     this.m33 = (float)1.0;
 }
Пример #21
0
 /// <summary>Copies the matrix values in the specified row into the vector parameter.
 /// 	</summary>
 /// <remarks>Copies the matrix values in the specified row into the vector parameter.
 /// 	</remarks>
 /// <param name="row">the matrix row</param>
 /// <param name="v">the vector into which the matrix row values will be copied</param>
 public void GetRow(int row, Vector3f v)
 {
     if (row == 0)
     {
         v.x = m00;
         v.y = m01;
         v.z = m02;
     }
     else
     {
         if (row == 1)
         {
             v.x = m10;
             v.y = m11;
             v.z = m12;
         }
         else
         {
             if (row == 2)
             {
                 v.x = m20;
                 v.y = m21;
                 v.z = m22;
             }
             else
             {
                 throw new IndexOutOfRangeException("Matrix3d getRow");
             }
         }
     }
 }
Пример #22
0
 /// <summary>
 /// Sets the value of this matrix from the rotation expressed
 /// by the quaternion q1, the translation t1, and the scale s.
 /// </summary>
 /// <remarks>
 /// Sets the value of this matrix from the rotation expressed
 /// by the quaternion q1, the translation t1, and the scale s.
 /// </remarks>
 /// <param name="q1">the rotation expressed as a quaternion</param>
 /// <param name="t1">the translation</param>
 /// <param name="s">the scale value</param>
 public void Set(Quat4f q1, Vector3f t1, float s)
 {
     this.m00 = s * (1.0 - 2.0 * q1.y * q1.y - 2.0 * q1.z * q1.z);
     this.m10 = s * (2.0 * (q1.x * q1.y + q1.w * q1.z));
     this.m20 = s * (2.0 * (q1.x * q1.z - q1.w * q1.y));
     this.m01 = s * (2.0 * (q1.x * q1.y - q1.w * q1.z));
     this.m11 = s * (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.z * q1.z);
     this.m21 = s * (2.0 * (q1.y * q1.z + q1.w * q1.x));
     this.m02 = s * (2.0 * (q1.x * q1.z + q1.w * q1.y));
     this.m12 = s * (2.0 * (q1.y * q1.z - q1.w * q1.x));
     this.m22 = s * (1.0 - 2.0 * q1.x * q1.x - 2.0 * q1.y * q1.y);
     this.m03 = t1.x;
     this.m13 = t1.y;
     this.m23 = t1.z;
     this.m30 = 0.0;
     this.m31 = 0.0;
     this.m32 = 0.0;
     this.m33 = 1.0;
 }