Пример #1
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="camera"></param>
		public override void NotifyCurrentCamera( Camera camera )
		{
			base.NotifyCurrentCamera( camera );


			///Fake orientation toward camera
			Vector3 zVec = ParentNode.DerivedPosition - camera.DerivedPosition;
			zVec.Normalize();

			Vector3 fixedAxis = camera.DerivedOrientation * Vector3.UnitY;

			Vector3 xVec = fixedAxis.Cross( zVec );
			xVec.Normalize();

			Vector3 yVec = zVec.Cross( xVec );
			yVec.Normalize();

			Quaternion oriQuat = Quaternion.FromAxes( xVec, yVec, zVec );

			fakeOrientation = oriQuat.ToRotationMatrix();

			Quaternion q = ParentNode.DerivedOrientation.UnitInverse * oriQuat;
			Matrix3 tempMat = q.ToRotationMatrix();

			Matrix4 rotMat = Matrix4.Identity;
			rotMat = tempMat;
			rotMat.Translation = new Vector3( 0.5f, 0.5f, 0.5f );

			unit.TextureMatrix = rotMat;
		}
Пример #2
0
 /// <summary>
 ///		Used to subtract two matrices.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Subtract( Matrix3 left, Matrix3 right )
 {
     return left - right;
 }
Пример #3
0
 /// <summary>
 /// Multiplies all the items in the Matrix3 by a scalar value.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="scalar"></param>
 /// <returns></returns>
 public static Matrix3 Multiply( Real scalar, Matrix3 matrix )
 {
     return scalar * matrix;
 }
Пример #4
0
 /// <summary>
 ///		matrix * vector [3x3 * 3x1 = 3x1]
 /// </summary>
 /// <param name="vector"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Vector3 Multiply( Matrix3 matrix, Vector3 vector )
 {
     return matrix * vector;
 }
Пример #5
0
 /// <summary>
 /// Multiply (concatenate) two Matrix3 instances together.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Multiply( Matrix3 left, Matrix3 right )
 {
     return left * right;
 }
Пример #6
0
        /// <summary>
        /// Negates all the items in the Matrix.
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static Matrix3 operator -( Matrix3 matrix )
        {
            Matrix3 result = new Matrix3();

            result.m00 = -matrix.m00;
            result.m01 = -matrix.m01;
            result.m02 = -matrix.m02;
            result.m10 = -matrix.m10;
            result.m11 = -matrix.m11;
            result.m12 = -matrix.m12;
            result.m20 = -matrix.m20;
            result.m21 = -matrix.m21;
            result.m22 = -matrix.m22;

            return result;
        }
Пример #7
0
        /// <summary>
        /// Multiplies all the items in the Matrix3 by a scalar value.
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="scalar"></param>
        /// <returns></returns>
        public static Matrix3 operator *( Real scalar, Matrix3 matrix )
        {
            Matrix3 result = new Matrix3();

            result.m00 = matrix.m00 * scalar;
            result.m01 = matrix.m01 * scalar;
            result.m02 = matrix.m02 * scalar;
            result.m10 = matrix.m10 * scalar;
            result.m11 = matrix.m11 * scalar;
            result.m12 = matrix.m12 * scalar;
            result.m20 = matrix.m20 * scalar;
            result.m21 = matrix.m21 * scalar;
            result.m22 = matrix.m22 * scalar;

            return result;
        }
Пример #8
0
 /// <summary>
 /// Multiply (concatenate) two Matrix3 instances together.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Multiply(Matrix3 left, Matrix3 right)
 {
     return(left * right);
 }
Пример #9
0
 /// <summary>
 /// Negates all the items in the Matrix.
 /// </summary>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Matrix3 Negate(Matrix3 matrix)
 {
     return(-matrix);
 }
Пример #10
0
 /// <summary>
 ///		Used to subtract two matrices.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Subtract(Matrix3 left, Matrix3 right)
 {
     return(left - right);
 }
Пример #11
0
 /// <summary>
 ///		Used to add two matrices together.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Add(Matrix3 left, Matrix3 right)
 {
     return(left + right);
 }
Пример #12
0
 /// <summary>
 /// Multiplies all the items in the Matrix3 by a scalar value.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="scalar"></param>
 /// <returns></returns>
 public static Matrix3 Multiply(Real scalar, Matrix3 matrix)
 {
     return(scalar * matrix);
 }
Пример #13
0
 /// <summary>
 /// Multiplies all the items in the Matrix3 by a scalar value.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="scalar"></param>
 /// <returns></returns>
 public static Matrix3 Multiply(Matrix3 matrix, Real scalar)
 {
     return(matrix * scalar);
 }
Пример #14
0
 /// <summary>
 ///		matrix * vector [3x3 * 3x1 = 3x1]
 /// </summary>
 /// <param name="vector"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Vector3 Multiply(Matrix3 matrix, Vector3 vector)
 {
     return(matrix * vector);
 }
Пример #15
0
 /// <summary>
 ///		vector * matrix [1x3 * 3x3 = 1x3]
 /// </summary>
 /// <param name="vector"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Vector3 Multiply(Vector3 vector, Matrix3 matrix)
 {
     return(vector * matrix);
 }
Пример #16
0
		//        /// <summary>
		//        ///
		//        /// </summary>
		//        /// <param name="op"></param>
		//        public override void GetRenderOperation(RenderOperation op) {
		//            Vector3[] r = new Vector3[8];
		//
		//            r = this.Corners;
		//
		//            r[0] = GetCorner(FrustumPlane.Far,FrustumPlane.Left,FrustumPlane.Bottom);
		//            r[1] = GetCorner(FrustumPlane.Far,FrustumPlane.Left,FrustumPlane.Top);
		//            r[2] = GetCorner(FrustumPlane.Far,FrustumPlane.Right,FrustumPlane.Top);
		//            r[3] = GetCorner(FrustumPlane.Far,FrustumPlane.Right,FrustumPlane.Bottom);
		//
		//            r[4] = GetCorner(FrustumPlane.Near,FrustumPlane.Right,FrustumPlane.Top);
		//            r[5] = GetCorner(FrustumPlane.Near,FrustumPlane.Left,FrustumPlane.Top);
		//            r[6] = GetCorner(FrustumPlane.Near,FrustumPlane.Left,FrustumPlane.Bottom);
		//            r[7] = GetCorner(FrustumPlane.Near,FrustumPlane.Right,FrustumPlane.Bottom);
		//
		//            this.Corners = r;
		//
		//            UpdateView();
		//
		//            //TODO: VERTEX BUFFER STUFF
		//        }

		/// <summary>
		///
		/// </summary>
		/// <param name="pp1"></param>
		/// <param name="pp2"></param>
		/// <param name="pp3"></param>
		/// <returns></returns>
		private Vector3 GetCorner( FrustumPlane pp1, FrustumPlane pp2, FrustumPlane pp3 )
		{
			Plane p1 = _planes[ (int)pp1 ];
			Plane p2 = _planes[ (int)pp1 ];
			Plane p3 = _planes[ (int)pp1 ];

			Matrix3 mdet;

			mdet.m00 = p1.Normal.x;
			mdet.m01 = p1.Normal.y;
			mdet.m02 = p1.Normal.z;
			mdet.m10 = p2.Normal.x;
			mdet.m11 = p2.Normal.y;
			mdet.m12 = p2.Normal.z;
			mdet.m20 = p3.Normal.x;
			mdet.m21 = p3.Normal.y;
			mdet.m22 = p3.Normal.z;

			float det = mdet.Determinant;

			if ( det == 0 )
			{
				//TODO: Unsure. The C++ just returned
				return Vector3.Zero; //some planes are parallel.
			}

			var mx = new Matrix3( -p1.D, p1.Normal.y, p1.Normal.z, -p2.D, p2.Normal.y, p2.Normal.z, -p3.D, p3.Normal.y,
			                      p3.Normal.z );

			float xdet = mx.Determinant;

			var my = new Matrix3( p1.Normal.x, -p1.D, p1.Normal.z, p2.Normal.x, -p2.D, p2.Normal.z, p3.Normal.x, -p3.D,
			                      p3.Normal.z );

			float ydet = my.Determinant;

			var mz = new Matrix3( p1.Normal.x, p1.Normal.y, -p1.D, p2.Normal.x, p2.Normal.y, -p2.D, p3.Normal.x, p3.Normal.y,
			                      -p3.D );

			float zdet = mz.Determinant;

			var r = new Vector3();
			r.x = xdet/det;
			r.y = ydet/det;
			r.z = zdet/det;

			return r;
		}
Пример #17
0
	    /// <summary>
	    /// Moves the node along arbitrary axes.
	    /// </summary>
	    /// <remarks>
	    ///	This method translates the node by a vector which is relative to
	    ///	a custom set of axes.
	    ///	</remarks>
	    /// <param name="axes">3x3 Matrix containg 3 column vectors each representing the
	    ///	X, Y and Z axes respectively. In this format the standard cartesian axes would be expressed as:
	    ///		1 0 0
	    ///		0 1 0
	    ///		0 0 1
	    ///		i.e. The Identity matrix.
	    ///	</param>
	    /// <param name="move">Vector relative to the supplied axes.</param>
	    /// <param name="relativeTo"></param>
	    public virtual void Translate( Matrix3 axes, Vector3 move, TransformSpace relativeTo )
		{
			Vector3 derived = axes * move;
			Translate( derived, relativeTo );
		}
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="matrix"></param>
        public static Quaternion FromRotationMatrix(Matrix3 matrix)
        {
            // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
            // article "Quaternion Calculus and Fast Animation".

            var result = Quaternion.Zero;

            var trace = matrix.m00 + matrix.m11 + matrix.m22;

            Real root = 0.0f;

            if (trace > 0.0f)
            {
                // |this.w| > 1/2, may as well choose this.w > 1/2
                root     = Utility.Sqrt(trace + 1.0f); // 2w
                result.w = 0.5f * root;

                root = 0.5f / root; // 1/(4w)

                result.x = (matrix.m21 - matrix.m12) * root;
                result.y = (matrix.m02 - matrix.m20) * root;
                result.z = (matrix.m10 - matrix.m01) * root;
            }
            else
            {
                // |result.w| <= 1/2

                var i = 0;
                if (matrix.m11 > matrix.m00)
                {
                    i = 1;
                }
                if (matrix.m22 > matrix[i, i])
                {
                    i = 2;
                }

                var j = next[i];
                var k = next[j];

                root = Utility.Sqrt(matrix[i, i] - matrix[j, j] - matrix[k, k] + 1.0f);

#if AXIOM_SAFE_ONLY
                var pi = 0.5f * root;
                root = 0.5f / root;
                var pw = (matrix[k, j] - matrix[j, k]) * root;
                var pj = (matrix[j, i] + matrix[i, j]) * root;
                var pk = (matrix[k, i] + matrix[i, k]) * root;
                result = i == 0
                                         ? new Quaternion(pw, pi, pj, pk)
                                         : i == 1
                                               ? new Quaternion(pw, pk, pi, pj)
                                               : new Quaternion(pw, pj, pk, pi);
#else
                unsafe
                {
                    var apkQuat = &result.x;

                    apkQuat[i] = 0.5f * root;
                    root       = 0.5f / root;

                    result.w = (matrix[k, j] - matrix[j, k]) * root;

                    apkQuat[j] = (matrix[j, i] + matrix[i, j]) * root;
                    apkQuat[k] = (matrix[k, i] + matrix[i, k]) * root;
                }
#endif
            }

            return(result);
        }
Пример #19
0
        /// <summary>
        /// Multiply (concatenate) two Matrix3 instances together.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static Matrix3 operator *( Matrix3 left, Matrix3 right )
        {
            Matrix3 result = new Matrix3();

            result.m00 = left.m00 * right.m00 + left.m01 * right.m10 + left.m02 * right.m20;
            result.m01 = left.m00 * right.m01 + left.m01 * right.m11 + left.m02 * right.m21;
            result.m02 = left.m00 * right.m02 + left.m01 * right.m12 + left.m02 * right.m22;

            result.m10 = left.m10 * right.m00 + left.m11 * right.m10 + left.m12 * right.m20;
            result.m11 = left.m10 * right.m01 + left.m11 * right.m11 + left.m12 * right.m21;
            result.m12 = left.m10 * right.m02 + left.m11 * right.m12 + left.m12 * right.m22;

            result.m20 = left.m20 * right.m00 + left.m21 * right.m10 + left.m22 * right.m20;
            result.m21 = left.m20 * right.m01 + left.m21 * right.m11 + left.m22 * right.m21;
            result.m22 = left.m20 * right.m02 + left.m21 * right.m12 + left.m22 * right.m22;

            return result;
        }
Пример #20
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="matrix"></param>
		public static Quaternion FromRotationMatrix( Matrix3 matrix )
		{
			// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
			// article "Quaternion Calculus and Fast Animation".

			Quaternion result = Quaternion.Zero;

			Real trace = matrix.m00 + matrix.m11 + matrix.m22;

			Real root = 0.0f;

			if ( trace > 0.0f )
			{
				// |this.w| > 1/2, may as well choose this.w > 1/2
				root = Utility.Sqrt( trace + 1.0f );  // 2w
				result.w = 0.5f * root;

				root = 0.5f / root;  // 1/(4w)

				result.x = ( matrix.m21 - matrix.m12 ) * root;
				result.y = ( matrix.m02 - matrix.m20 ) * root;
				result.z = ( matrix.m10 - matrix.m01 ) * root;
			}
			else
			{
				// |result.w| <= 1/2

				int i = 0;
				if ( matrix.m11 > matrix.m00 )
					i = 1;
				if ( matrix.m22 > matrix[ i, i ] )
					i = 2;

				int j = next[ i ];
				int k = next[ j ];

				root = Utility.Sqrt( matrix[ i, i ] - matrix[ j, j ] - matrix[ k, k ] + 1.0f );

				unsafe
				{
					Real* apkQuat = &result.x;

					apkQuat[ i ] = 0.5f * root;
					root = 0.5f / root;

					result.w = ( matrix[ k, j ] - matrix[ j, k ] ) * root;

					apkQuat[ j ] = ( matrix[ j, i ] + matrix[ i, j ] ) * root;
					apkQuat[ k ] = ( matrix[ k, i ] + matrix[ i, k ] ) * root;
				}
			}

			return result;
		}
Пример #21
0
        /// <summary>
        ///		Used to subtract two matrices.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static Matrix3 operator -( Matrix3 left, Matrix3 right )
        {
            Matrix3 result = new Matrix3();

            for( int row = 0; row < 3; row++ )
            {
                for( int col = 0; col < 3; col++ )
                {
                    result[ row, col ] = left[ row, col ] - right[ row, col ];
                }
            }

            return result;
        }
Пример #22
0
		internal void SetGpuParameter( Matrix3 matWorldInvRotation )
		{
			if ( this._params != null )
			{
				//TODO
			}
		}
Пример #23
0
 /// <summary>
 ///		Used to add two matrices together.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static Matrix3 Add( Matrix3 left, Matrix3 right )
 {
     return left + right;
 }
Пример #24
0
		/// <summary>
		/// Gets a 3x3 rotation matrix from this Quaternion.
		/// </summary>
		/// <returns></returns>
		public Matrix3 ToRotationMatrix()
		{
			var rotation = new Matrix3();

			var tx = 2.0f*this.x;
			var ty = 2.0f*this.y;
			var tz = 2.0f*this.z;
			var twx = tx*this.w;
			var twy = ty*this.w;
			var twz = tz*this.w;
			var txx = tx*this.x;
			var txy = ty*this.x;
			var txz = tz*this.x;
			var tyy = ty*this.y;
			var tyz = tz*this.y;
			var tzz = tz*this.z;

			rotation.m00 = 1.0f - ( tyy + tzz );
			rotation.m01 = txy - twz;
			rotation.m02 = txz + twy;
			rotation.m10 = txy + twz;
			rotation.m11 = 1.0f - ( txx + tzz );
			rotation.m12 = tyz - twx;
			rotation.m20 = txz - twy;
			rotation.m21 = tyz + twx;
			rotation.m22 = 1.0f - ( txx + tyy );

			return rotation;
		}
Пример #25
0
 /// <summary>
 ///		vector * matrix [1x3 * 3x3 = 1x3]
 /// </summary>
 /// <param name="vector"></param>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Vector3 Multiply( Vector3 vector, Matrix3 matrix )
 {
     return vector * matrix;
 }
Пример #26
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="xAxis"></param>
		/// <param name="yAxis"></param>
		/// <param name="zAxis"></param>
		public static Quaternion FromAxes( Vector3 xAxis, Vector3 yAxis, Vector3 zAxis )
		{
			var rotation = new Matrix3();

			rotation.m00 = xAxis.x;
			rotation.m10 = xAxis.y;
			rotation.m20 = xAxis.z;

			rotation.m01 = yAxis.x;
			rotation.m11 = yAxis.y;
			rotation.m21 = yAxis.z;

			rotation.m02 = zAxis.x;
			rotation.m12 = zAxis.y;
			rotation.m22 = zAxis.z;

			// set this quaternions values from the rotation matrix built
			return FromRotationMatrix( rotation );
		}
Пример #27
0
 /// <summary>
 /// Multiplies all the items in the Matrix3 by a scalar value.
 /// </summary>
 /// <param name="matrix"></param>
 /// <param name="scalar"></param>
 /// <returns></returns>
 public static Matrix3 Multiply( Matrix3 matrix, Real scalar )
 {
     return matrix * scalar;
 }
Пример #28
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="matrix"></param>
		public static Quaternion FromRotationMatrix( Matrix3 matrix )
		{
			// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
			// article "Quaternion Calculus and Fast Animation".

			var result = Quaternion.Zero;

			var trace = matrix.m00 + matrix.m11 + matrix.m22;

			Real root = 0.0f;

			if ( trace > 0.0f )
			{
				// |this.w| > 1/2, may as well choose this.w > 1/2
				root = Utility.Sqrt( trace + 1.0f ); // 2w
				result.w = 0.5f*root;

				root = 0.5f/root; // 1/(4w)

				result.x = ( matrix.m21 - matrix.m12 )*root;
				result.y = ( matrix.m02 - matrix.m20 )*root;
				result.z = ( matrix.m10 - matrix.m01 )*root;
			}
			else
			{
				// |result.w| <= 1/2

				var i = 0;
				if ( matrix.m11 > matrix.m00 )
				{
					i = 1;
				}
				if ( matrix.m22 > matrix[ i, i ] )
				{
					i = 2;
				}

				var j = next[ i ];
				var k = next[ j ];

				root = Utility.Sqrt( matrix[ i, i ] - matrix[ j, j ] - matrix[ k, k ] + 1.0f );

#if AXIOM_SAFE_ONLY
                var pi = 0.5f * root;
                root = 0.5f / root;                                                                                                       
                var pw = (matrix[k, j] - matrix[j, k]) * root;
                var pj = (matrix[j, i] + matrix[i, j]) * root;
                var pk = (matrix[k, i] + matrix[i, k]) * root;
			    result = i == 0
			                 ? new Quaternion(pw, pi, pj, pk)
			                 : i == 1
			                       ? new Quaternion(pw, pk, pi, pj)
			                       : new Quaternion(pw, pj, pk, pi);
#else
				unsafe
				{
					var apkQuat = &result.x;

					apkQuat[ i ] = 0.5f*root;
					root = 0.5f/root;

					result.w = ( matrix[ k, j ] - matrix[ j, k ] )*root;

					apkQuat[ j ] = ( matrix[ j, i ] + matrix[ i, j ] )*root;
					apkQuat[ k ] = ( matrix[ k, i ] + matrix[ i, k ] )*root;
				}
#endif
			}

			return result;
		}
Пример #29
0
 /// <summary>
 /// Negates all the items in the Matrix.
 /// </summary>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static Matrix3 Negate( Matrix3 matrix )
 {
     return -matrix;
 }
Пример #30
0
		public override void UpdateGpuProgramsParams( IRenderable rend, Pass pass, AutoParamDataSource source,
		                                              Core.Collections.LightList lightList )
		{
			if ( this.lightParamsList.Count == 0 )
			{
				return;
			}

			var curLightType = LightType.Directional;
			int curSearchLightIndex = 0;
			Matrix4 matWorld = source.WorldMatrix;
			Matrix3 matWorldInvRotation;

			var vRow0 = new Vector3( matWorld[ 0, 0 ], matWorld[ 0, 1 ], matWorld[ 0, 2 ] );
			var vRow1 = new Vector3( matWorld[ 1, 0 ], matWorld[ 1, 1 ], matWorld[ 1, 2 ] );
			var vRow2 = new Vector3( matWorld[ 2, 0 ], matWorld[ 2, 1 ], matWorld[ 2, 2 ] );

			vRow0.Normalize();
			vRow1.Normalize();
			vRow2.Normalize();

			matWorldInvRotation = new Matrix3( vRow0, vRow1, vRow2 );
			//update inverse rotation parameter
			if ( this.worldInvRotMatrix != null )
			{
				this.worldInvRotMatrix.SetGpuParameter( matWorldInvRotation );
			}

			//update per light parameters
			for ( int i = 0; i < this.lightParamsList.Count; i++ )
			{
				LightParams curParams = this.lightParamsList[ i ];

				if ( curLightType != curParams.Type )
				{
					curLightType = curParams.Type;
					curSearchLightIndex = 0;
				}

				Light srcLight = null;
				Vector4 vParameter;
				ColorEx color;

				//Search a matching light from the current sorted lights of the given renderable
				for ( int j = 0; j < lightList.Count; j++ )
				{
					if ( lightList[ j ].Type == curLightType )
					{
						srcLight = lightList[ j ];
						curSearchLightIndex = j + 1;
						break;
					}
				}

				//No matching light found -> use a blank dummy light for parameter update
				if ( srcLight == null )
				{
					srcLight = blankLight;
				}

				switch ( curParams.Type )
				{
					case LightType.Directional:
					{
						Vector3 vec3;

						//Update light direction (object space)
						vec3 = matWorldInvRotation*srcLight.DerivedDirection;
						vec3.Normalize();

						vParameter.x = -vec3.x;
						vParameter.y = -vec3.y;
						vParameter.z = -vec3.z;
						vParameter.w = 0.0;
						curParams.Direction.SetGpuParameter( vParameter );
					}
						break;
					case LightType.Point:
						//update light position (world space)
						vParameter = srcLight.GetAs4DVector( true );
						curParams.Position.SetGpuParameter( vParameter );

						//Update light attenuation parameters.
						vParameter.x = srcLight.AttenuationRange;
						vParameter.y = srcLight.AttenuationConstant;
						vParameter.z = srcLight.AttenuationLinear;
						vParameter.w = srcLight.AttenuationQuadratic;
						curParams.AttenuatParams.SetGpuParameter( vParameter );

						break;
					case LightType.Spotlight:
					{
						Vector3 vec3;

						//Update light position (world space)
						vParameter = srcLight.GetAs4DVector( true );
						curParams.Position.SetGpuParameter( vParameter );

						//Update light direction (object space)
						vec3 = matWorldInvRotation*srcLight.DerivedDirection;
						vec3.Normalize();

						vParameter.x = -vec3.x;
						vParameter.y = -vec3.y;
						vParameter.z = -vec3.z;
						vParameter.w = 0.0;

						curParams.Direction.SetGpuParameter( vParameter );

						//Update light attenuation parameters.
						vParameter.x = srcLight.AttenuationRange;
						vParameter.y = srcLight.AttenuationConstant;
						vParameter.z = srcLight.AttenuationLinear;
						vParameter.w = srcLight.AttenuationQuadratic;
						curParams.AttenuatParams.SetGpuParameter( vParameter );

						//Update spotlight parameters
						Real phi = System.Math.Cos( (double)srcLight.SpotlightOuterAngle*0.5f );
						Real theta = System.Math.Cos( (double)srcLight.SpotlightInnerAngle*0.5f );

						vec3.x = theta;
						vec3.y = phi;
						vec3.z = srcLight.SpotlightFalloff;

						curParams.SpotParams.SetGpuParameter( vec3 );
					}
						break;
				}

				//Update diffuse color
				if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
				{
					color = srcLight.Diffuse*pass.Diffuse;
					curParams.DiffuseColor.SetGpuParameter( color );
				}
				else
				{
					color = srcLight.Diffuse;
					curParams.DiffuseColor.SetGpuParameter( color );
				}

				//Update specular color if need to
				if ( this.specularEnabled )
				{
					//Update diffuse color
					if ( ( this.trackVertexColorType & TrackVertexColor.Diffuse ) == 0 )
					{
						color = srcLight.Specular*pass.Specular;
						curParams.SpecularColor.SetGpuParameter( color );
					}
					else
					{
						color = srcLight.Specular;
						curParams.SpecularColor.SetGpuParameter( color );
					}
				}
			}
		}
Пример #31
0
        /// <summary>
        ///    Constructs this Matrix from 3 euler angles, in degrees.
        /// </summary>
        /// <param name="yaw"></param>
        /// <param name="pitch"></param>
        /// <param name="roll"></param>
        public void FromEulerAnglesXYZ( Real yaw, Real pitch, Real roll )
        {
            Real cos = Utility.Cos( yaw );
            Real sin = Utility.Sin( yaw );
            Matrix3 xMat = new Matrix3( 1, 0, 0, 0, cos, -sin, 0, sin, cos );

            cos = Utility.Cos( pitch );
            sin = Utility.Sin( pitch );
            Matrix3 yMat = new Matrix3( cos, 0, sin, 0, 1, 0, -sin, 0, cos );

            cos = Utility.Cos( roll );
            sin = Utility.Sin( roll );
            Matrix3 zMat = new Matrix3( cos, -sin, 0, sin, cos, 0, 0, 0, 1 );

            this = xMat * ( yMat * zMat );
        }
Пример #32
0
		/// <summary>
		///		Used to add two matrices together.
		/// </summary>
		/// <param name="left"></param>
		/// <param name="right"></param>
		/// <returns></returns>
		public static Matrix3 operator +( Matrix3 left, Matrix3 right )
		{
			var result = new Matrix3();

			for ( var row = 0; row < 3; row++ )
			{
				for ( var col = 0; col < 3; col++ )
				{
					result[ row, col ] = left[ row, col ] + right[ row, col ];
				}
			}

			return result;
		}
Пример #33
0
		/// <summary>
		/// Moves the node along arbitrary axes.
		/// </summary>
		/// <remarks>
		///	This method translates the node by a vector which is relative to
		///	a custom set of axes.
		///	</remarks>
		/// <param name="axes">3x3 Matrix containg 3 column vectors each representing the
		///	X, Y and Z axes respectively. In this format the standard cartesian axes would be expressed as:
		///		1 0 0
		///		0 1 0
		///		0 0 1
		///		i.e. The Identity matrix.
		///	</param>
		/// <param name="move">Vector relative to the supplied axes.</param>
		public virtual void Translate( Matrix3 axes, Vector3 move )
		{
			Vector3 derived = axes * move;
			Translate( derived, TransformSpace.Parent );
		}
Пример #34
0
	    public void Extract3x3Matrix( out Matrix3 m3 )
	    {
            m3.m00 = m00;
            m3.m01 = m01;
            m3.m02 = m02;
            m3.m10 = m10;
            m3.m11 = m11;
            m3.m12 = m12;
            m3.m20 = m20;
            m3.m21 = m21;
            m3.m22 = m22;
	    }
Пример #35
0
		/// <summary>
		///		Used to allow assignment from a Matrix3 to a Matrix4 object.
		/// </summary>
		/// <param name="right"></param>
		/// <returns></returns>
		public static Matrix4 FromMatrix3( Matrix3 right )
		{
			return right;
		}
Пример #36
0
        public override void NotifyCurrentCamera( Camera camera )
        {
            base.NotifyCurrentCamera( camera );

            Vector3 zVec = ParentNode.DerivedPosition - camera.DerivedPosition;
            float sqdist = zVec.LengthSquared;
            zVec.Normalize();
            Vector3 fixedAxis = camera.DerivedOrientation * Vector3.UnitY;
            Vector3 xVec = fixedAxis.Cross( zVec );
            xVec.Normalize();
            Vector3 yVec = zVec.Cross( xVec );
            yVec.Normalize();
            Quaternion oriQuat = Quaternion.FromAxes( xVec, yVec, zVec );
            if ( sqdist > mSize * mSize / 2 )    // ADD THIS CONDITION HERE
            {
                mFakeOrientation = oriQuat.ToRotationMatrix();
            }
            else
            {
                mFakeOrientation = camera.DerivedOrientation.ToRotationMatrix(); //cam->getDerivedOrientation().ToRotationMatrix(m_fakeOrientation);
            }


            Matrix3 tempMat = Matrix3.Zero;
            Quaternion q = ParentNode.DerivedOrientation.UnitInverse * oriQuat;
            tempMat = q.ToRotationMatrix();
            Matrix4 rotMat = Matrix4.Identity;
            rotMat = tempMat;
            rotMat.Translation = new Vector3( 0.5f, 0.5f, 0.5f );
            mUnit.TextureMatrix = rotMat;
            material.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ).TextureMatrix = rotMat;
        }