Beispiel #1
0
		/// <summary> Sets only 3x3 upper elements of this matrix to that of m1.
		/// The other elements are unchanged.
		/// </summary>
		private void  setRotationScale(Matrix4f m1)
		{
			m00 = m1.m00; m01 = m1.m01; m02 = m1.m02;
			m10 = m1.m10; m11 = m1.m11; m12 = m1.m12;
			m20 = m1.m20; m21 = m1.m21; m22 = m1.m22;
		}
Beispiel #2
0
		/// <summary> Constructs a new matrix with the same values as the Matrix4f parameter.</summary>
		/// <param name="m1">The source matrix.
		/// </param>
		public Matrix4f(Matrix4f m1)
		{
			set_Renamed(m1);
		}
Beispiel #3
0
		/// <summary> Sets the value of this matrix equal to the negation of of the Matrix4f
		/// parameter.
		/// </summary>
		/// <param name="m1">The source matrix
		/// </param>
		public void  negate(Matrix4f m1)
		{
			set_Renamed(m1);
			negate();
		}
Beispiel #4
0
		/// <summary> Performs SVD on this matrix and gets scale and rotation.
		/// Rotation is placed into rot.
		/// </summary>
		/// <param name="rot3">the rotation factor(Matrix3d).
		/// </param>
		/// <param name="rot4">the rotation factor(Matrix4f) only upper 3x3 elements are changed.
		/// </param>
		/// <returns> scale factor
		/// </returns>
		private float SVD(Matrix3f rot3, Matrix4f rot4)
		{
			// this is a simple svd.
			// Not complete but fast and reasonable.
			// See comment in Matrix3d.
			
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			float s = (float) System.Math.Sqrt((m00 * m00 + m10 * m10 + m20 * m20 + m01 * m01 + m11 * m11 + m21 * m21 + m02 * m02 + m12 * m12 + m22 * m22) / 3.0);
			
			// zero-div may occur.
			float t = (s == 0.0f?0.0f:1.0f / s);
			
			if (rot3 != null)
			{
				this.getRotationScale(rot3);
				rot3.mul(t);
			}
			
			if (rot4 != null)
			{
				if (rot4 != this)
					rot4.setRotationScale(this); // private method
				rot4.mulRotationScale(t); // private method
			}
			
			return s;
		}
Beispiel #5
0
		/// <summary> Sets the value of this matrix to the matrix difference of itself
		/// and matrix m1 (this = this - m1). 
		/// </summary>
		/// <param name="m1">the other matrix 
		/// </param>
		public void  sub(Matrix4f m1)
		{
			m00 -= m1.m00; m01 -= m1.m01; m02 -= m1.m02; m03 -= m1.m03;
			m10 -= m1.m10; m11 -= m1.m11; m12 -= m1.m12; m13 -= m1.m13;
			m20 -= m1.m20; m21 -= m1.m21; m22 -= m1.m22; m23 -= m1.m23;
			m30 -= m1.m30; m31 -= m1.m31; m32 -= m1.m32; m33 -= m1.m33;
		}
Beispiel #6
0
		/// <summary> Sets the value of this quaternion to the rotational component of
		/// the passed matrix.
		/// </summary>
		/// <param name="m1">the matrix4f
		/// </param>
		public void  set_Renamed(Matrix4f m1)
		{
			double ww = 0.25 * (m1.m00 + m1.m11 + m1.m22 + m1.m33);
			
			if (ww >= 0)
			{
				if (ww >= EPS2)
				{
					this.w = System.Math.Sqrt(ww);
					ww = 0.25 / this.w;
					this.x = ((m1.m21 - m1.m12) * ww);
					this.y = ((m1.m02 - m1.m20) * ww);
					this.z = ((m1.m10 - m1.m01) * ww);
					return ;
				}
			}
			else
			{
				this.w = 0;
				this.x = 0;
				this.y = 0;
				this.z = 1;
				return ;
			}
			
			this.w = 0;
			ww = (- 0.5) * (m1.m11 + m1.m22);
			if (ww >= 0)
			{
				if (ww >= EPS2)
				{
					this.x = System.Math.Sqrt(ww);
					ww = 1.0 / (2.0 * this.x);
					this.y = (m1.m10 * ww);
					this.z = (m1.m20 * ww);
					return ;
				}
			}
			else
			{
				this.x = 0;
				this.y = 0;
				this.z = 1;
				return ;
			}
			
			this.x = 0;
			ww = 0.5 * (1.0 - m1.m22);
			if (ww >= EPS2)
			{
				this.y = System.Math.Sqrt(ww);
				this.z = (m1.m21) / (2.0 * this.y);
				return ;
			}
			
			this.y = 0;
			this.z = 1;
		}
Beispiel #7
0
		/// <summary> Multiplies the transpose of matrix m1 times the transpose of matrix m2,
		/// and places the result into this.
		/// </summary>
		/// <param name="m1">The matrix on the left hand side of the multiplication
		/// </param>
		/// <param name="m2">The matrix on the right hand side of the multiplication
		/// </param>
		public void  mulTransposeBoth(Matrix4f m1, Matrix4f m2)
		{
			mul(m2, m1);
			transpose();
		}
Beispiel #8
0
		/// <summary> Sets the value of this matrix to sum of itself and matrix m1. </summary>
		/// <param name="m1">the other matrix 
		/// </param>
		public void  add(Matrix4f m1)
		{
			m00 += m1.m00; m01 += m1.m01; m02 += m1.m02; m03 += m1.m03;
			m10 += m1.m10; m11 += m1.m11; m12 += m1.m12; m13 += m1.m13;
			m20 += m1.m20; m21 += m1.m21; m22 += m1.m22; m23 += m1.m23;
			m30 += m1.m30; m31 += m1.m31; m32 += m1.m32; m33 += m1.m33;
		}
Beispiel #9
0
		/// <summary> Multiplies each element of matrix m1 by a scalar and places the result
		/// into this. Matrix m1 is not modified.
		/// </summary>
		/// <param name="scalar">The scalar multiplier.
		/// </param>
		/// <param name="m1">The original matrix.
		/// </param>
		public void  mul(float scalar, Matrix4f m1)
		{
			set_Renamed(m1);
			mul(scalar);
		}
Beispiel #10
0
		/// <summary> Sets the value of this matrix to the result of multiplying itself
		/// with matrix m1. 
		/// </summary>
		/// <param name="m1">the other matrix 
		/// </param>
		public void  mul(Matrix4f m1)
		{
			mul(this, m1);
		}
Beispiel #11
0
		/// <summary> Sets the value of this matrix to the matrix inverse
		/// of the passed matrix m1. 
		/// </summary>
		/// <param name="m1">the matrix to be inverted 
		/// </param>
		public void  invert(Matrix4f m1)
		{
			set_Renamed(m1);
			invert();
		}
Beispiel #12
0
		/// <summary> Sets the value of this matrix to a copy of the
		/// passed matrix m1.
		/// </summary>
		/// <param name="m1">the matrix to be copied
		/// </param>
		public void  set_Renamed(Matrix4f m1)
		{
			m00 = m1.m00; m01 = m1.m01; m02 = m1.m02; m03 = m1.m03;
			m10 = m1.m10; m11 = m1.m11; m12 = m1.m12; m13 = m1.m13;
			m20 = m1.m20; m21 = m1.m21; m22 = m1.m22; m23 = m1.m23;
			m30 = m1.m30; m31 = m1.m31; m32 = m1.m32; m33 = m1.m33;
		}
Beispiel #13
0
		/// <summary> Sets the value of this matrix to the transpose of the argument matrix</summary>
		/// <param name="m1">the matrix to be transposed 
		/// </param>
		public void  transpose(Matrix4f m1)
		{
			// alias-safe
			set_Renamed(m1);
			transpose();
		}
Beispiel #14
0
		/// <summary> Adds a scalar to each component of the matrix m1 and places
		/// the result into this. Matrix m1 is not modified.
		/// </summary>
		/// <param name="scalar">The scalar adder.
		/// </param>
		/// <parm>  m1 The original matrix values. </parm>
		public void  add(float scalar, Matrix4f m1)
		{
			set_Renamed(m1);
			add(scalar);
		}
Beispiel #15
0
		/// <summary> Multiplies the transpose of matrix m1 times matrix m2, and places the
		/// result into this.
		/// </summary>
		/// <param name="m1">The matrix on the left hand side of the multiplication
		/// </param>
		/// <param name="m2">The matrix on the right hand side of the multiplication
		/// </param>
		public void  mulTransposeLeft(Matrix4f m1, Matrix4f m2)
		{
			// alias-safe way.
			set_Renamed(m1.m00 * m2.m00 + m1.m10 * m2.m10 + m1.m20 * m2.m20 + m1.m30 * m2.m30, m1.m00 * m2.m01 + m1.m10 * m2.m11 + m1.m20 * m2.m21 + m1.m30 * m2.m31, m1.m00 * m2.m02 + m1.m10 * m2.m12 + m1.m20 * m2.m22 + m1.m30 * m2.m32, m1.m00 * m2.m03 + m1.m10 * m2.m13 + m1.m20 * m2.m23 + m1.m30 * m2.m33, m1.m01 * m2.m00 + m1.m11 * m2.m10 + m1.m21 * m2.m20 + m1.m31 * m2.m30, m1.m01 * m2.m01 + m1.m11 * m2.m11 + m1.m21 * m2.m21 + m1.m31 * m2.m31, m1.m01 * m2.m02 + m1.m11 * m2.m12 + m1.m21 * m2.m22 + m1.m31 * m2.m32, m1.m01 * m2.m03 + m1.m11 * m2.m13 + m1.m21 * m2.m23 + m1.m31 * m2.m33, m1.m02 * m2.m00 + m1.m12 * m2.m10 + m1.m22 * m2.m20 + m1.m32 * m2.m30, m1.m02 * m2.m01 + m1.m12 * m2.m11 + m1.m22 * m2.m21 + m1.m32 * m2.m31, m1.m02 * m2.m02 + m1.m12 * m2.m12 + m1.m22 * m2.m22 + m1.m32 * m2.m32, m1.m02 * m2.m03 + m1.m12 * m2.m13 + m1.m22 * m2.m23 + m1.m32 * m2.m33, m1.m03 * m2.m00 + m1.m13 * m2.m10 + m1.m23 * m2.m20 + m1.m33 * m2.m30, m1.m03 * m2.m01 + m1.m13 * m2.m11 + m1.m23 * m2.m21 + m1.m33 * m2.m31, m1.m03 * m2.m02 + m1.m13 * m2.m12 + m1.m23 * m2.m22 + m1.m33 * m2.m32, m1.m03 * m2.m03 + m1.m13 * m2.m13 + m1.m23 * m2.m23 + m1.m33 * m2.m33);
		}
Beispiel #16
0
		/// <summary> Sets the value of this matrix to the matrix sum of matrices m1 and m2. </summary>
		/// <param name="m1">the first matrix 
		/// </param>
		/// <param name="m2">the second matrix 
		/// </param>
		public void  add(Matrix4f m1, Matrix4f m2)
		{
			set_Renamed(m1);
			add(m2);
		}
Beispiel #17
0
		/// <summary> Returns true if all of the data members of Matrix4f m1 are
		/// equal to the corresponding data members in this Matrix4f. 
		/// </summary>
		/// <param name="m1">The matrix with which the comparison is made. 
		/// </param>
		/// <returns> true or false 
		/// </returns>
		public bool equals(Matrix4f m1)
		{
			return m1 != null && m00 == m1.m00 && m01 == m1.m01 && m02 == m1.m02 && m03 == m1.m03 && m10 == m1.m10 && m11 == m1.m11 && m12 == m1.m12 && m13 == m1.m13 && m20 == m1.m20 && m21 == m1.m21 && m22 == m1.m22 && m23 == m1.m23 && m30 == m1.m30 && m31 == m1.m31 && m32 == m1.m32 && m33 == m1.m33;
		}
Beispiel #18
0
		/// <summary> Sets the value of this matrix to the matrix difference
		/// of matrices m1 and m2. 
		/// </summary>
		/// <param name="m1">the first matrix 
		/// </param>
		/// <param name="m2">the second matrix 
		/// </param>
		public void  sub(Matrix4f m1, Matrix4f m2)
		{
			// note this is alias safe.
			set_Renamed(m1.m00 - m2.m00, m1.m01 - m2.m01, m1.m02 - m2.m02, m1.m03 - m2.m03, m1.m10 - m2.m10, m1.m11 - m2.m11, m1.m12 - m2.m12, m1.m13 - m2.m13, m1.m20 - m2.m20, m1.m21 - m2.m21, m1.m22 - m2.m22, m1.m23 - m2.m23, m1.m30 - m2.m30, m1.m31 - m2.m31, m1.m32 - m2.m32, m1.m33 - m2.m33);
		}
Beispiel #19
0
		/// <summary> Returns true if the L-infinite distance between this matrix and matrix
		/// m1 is less than or equal to the epsilon parameter, otherwise returns
		/// false. The L-infinite distance is equal to MAX[i=0,1,2,3 ; j=0,1,2,3 ;
		/// abs(this.m(i,j) - m1.m(i,j)]
		/// </summary>
		/// <param name="m1">The matrix to be compared to this matrix
		/// </param>
		/// <param name="epsilon">the threshold value
		/// </param>
		public virtual bool epsilonEquals(Matrix4f m1, float epsilon)
		{
			// why epsilon is float ??
			return System.Math.Abs(m00 - m1.m00) <= epsilon && System.Math.Abs(m01 - m1.m01) <= epsilon && System.Math.Abs(m02 - m1.m02) <= epsilon && System.Math.Abs(m03 - m1.m03) <= epsilon && System.Math.Abs(m10 - m1.m10) <= epsilon && System.Math.Abs(m11 - m1.m11) <= epsilon && System.Math.Abs(m12 - m1.m12) <= epsilon && System.Math.Abs(m13 - m1.m13) <= epsilon && System.Math.Abs(m20 - m1.m20) <= epsilon && System.Math.Abs(m21 - m1.m21) <= epsilon && System.Math.Abs(m22 - m1.m22) <= epsilon && System.Math.Abs(m23 - m1.m23) <= epsilon && System.Math.Abs(m30 - m1.m30) <= epsilon && System.Math.Abs(m31 - m1.m31) <= epsilon && System.Math.Abs(m32 - m1.m32) <= epsilon && System.Math.Abs(m33 - m1.m33) <= epsilon;
		}
Beispiel #20
0
		/// <summary> Sets the value of this axis-angle to the rotational component of
		/// the passed matrix.
		/// If the specified matrix has no rotational component, the value
		/// of this AxisAngle4f is set to an angle of 0 about an axis of (0,1,0).
		/// </summary>
		/// <param name="m1">the matrix4f
		/// </param>
		public void  set_Renamed(Matrix4f m1)
		{
			Matrix3f m3f = new Matrix3f();
			
			m1.get_Renamed(m3f);
			
			x = m3f.m21 - m3f.m12;
			y = m3f.m02 - m3f.m20;
			z = m3f.m10 - m3f.m01;
			double mag = x * x + y * y + z * z;
			
			if (mag > EPS)
			{
				mag = System.Math.Sqrt(mag);
				double sin = 0.5 * mag;
				double cos = 0.5 * (m3f.m00 + m3f.m11 + m3f.m22 - 1.0);
				
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				angle = (float) System.Math.Atan2(sin, cos);
				double invMag = 1.0 / mag;
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				x = (float) (x * invMag);
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				y = (float) (y * invMag);
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				z = (float) (z * invMag);
			}
			else
			{
				x = 0.0f;
				y = 1.0f;
				z = 0.0f;
				angle = 0.0f;
			}
		}
Beispiel #21
0
		/// <summary> Sets the value of this quaternion to the rotational component of
		/// the passed matrix.
		/// </summary>
		/// <param name="m1">the Matrix4f
		/// </param>
		public void  set_Renamed(Matrix4f m1)
		{
			float ww = 0.25f * (m1.m00 + m1.m11 + m1.m22 + m1.m33);
			
			if (ww >= 0)
			{
				if (ww >= EPS2)
				{
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					this.w = (float) System.Math.Sqrt((double) ww);
					ww = 0.25f / this.w;
					this.x = (m1.m21 - m1.m12) * ww;
					this.y = (m1.m02 - m1.m20) * ww;
					this.z = (m1.m10 - m1.m01) * ww;
					return ;
				}
			}
			else
			{
				this.w = 0;
				this.x = 0;
				this.y = 0;
				this.z = 1;
				return ;
			}
			
			this.w = 0;
			ww = (- 0.5f) * (m1.m11 + m1.m22);
			
			if (ww >= 0)
			{
				if (ww >= EPS2)
				{
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					this.x = (float) System.Math.Sqrt((double) ww);
					ww = 1.0f / (2.0f * this.x);
					this.y = m1.m10 * ww;
					this.z = m1.m20 * ww;
					return ;
				}
			}
			else
			{
				this.x = 0;
				this.y = 0;
				this.z = 1;
				return ;
			}
			
			this.x = 0;
			ww = 0.5f * (1.0f - m1.m22);
			
			if (ww >= EPS2)
			{
				//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
				this.y = (float) System.Math.Sqrt((double) ww);
				this.z = m1.m21 / (2.0f * this.y);
				return ;
			}
			
			this.y = 0;
			this.z = 1;
		}