Summary description for MultiplyControllerValue.
Inheritance: BaseControllerFunction
Beispiel #1
0
		public override void CreateScene()
		{
			// create a 3d line
			Line3d line = new Line3d( new Vector3( 0, 0, 30 ), Vector3.UnitY, 50, ColorEx.Blue );

			Triangle tri = new Triangle(
				new Vector3( -25, 0, 0 ),
				new Vector3( 0, 50, 0 ),
				new Vector3( 25, 0, 0 ),
				ColorEx.Red,
				ColorEx.Blue,
				ColorEx.Green );

			// create a node for the line
			SceneNode node = scene.RootSceneNode.CreateChildSceneNode();

			SceneNode lineNode = node.CreateChildSceneNode();
			SceneNode triNode = node.CreateChildSceneNode();
			triNode.Position = new Vector3( 50, 0, 0 );

			// add the line and triangle to the scene
			lineNode.AttachObject( line );
			triNode.AttachObject( tri );

			// create a node rotation controller value, which will mark the specified scene node as a target of the rotation
			// we want to rotate along the Y axis for the triangle and Z for the line (just for the hell of it)
			NodeRotationControllerValue rotate = new NodeRotationControllerValue( triNode, Vector3.UnitY );
			NodeRotationControllerValue rotate2 = new NodeRotationControllerValue( lineNode, Vector3.UnitZ );

			// the multiply controller function will multiply the source controller value by the specified value each frame.
			MultipyControllerFunction func = new MultipyControllerFunction( 50 );

			// create a new controller, using the rotate and func objects created above.  there are 2 overloads to this method.  the one being
			// used uses an internal FrameTimeControllerValue as the source value by default.  The destination value will be the node, which
			// is implemented to simply call Rotate on the specified node along the specified axis.  The function will multiply the given value
			// against the source value, which in this case is the current frame time.  The end result in this demo is that if 50 is specified in the
			// MultiplyControllerValue, then the node will rotate 50 degrees per second.  since the value is scaled by the frame time, the speed
			// of the rotation will be consistent on all machines regardless of CPU speed.
			ControllerManager.Instance.CreateController( rotate, func );
			ControllerManager.Instance.CreateController( rotate2, func );

			// place the camera in an optimal position
			camera.Position = new Vector3( 30, 30, 220 );

			debugText = "Spinning triangle - Using custom built geometry";
		}
		/// <summary>
		///     Creates a basic time-based texture v coordinate modifier designed for creating scrolling textures.
		/// </summary>
		/// <remarks>
		///     This simple method allows you to easily create constant-speed scrolling textures. If you want more
		///     control, look up the <see cref="CreateTextureWaveTransformer"/> for more complex wave-based
		///     scrollers / stretchers / rotaters.
		/// </remarks>
		/// <param name="layer">The texture unit to animate.</param>
		/// <param name="speed">speed, in wraps per second.</param>
		/// <returns>A newly created controller object that will be updated during the main render loop.</returns>
		public Controller<Real> CreateTextureVScroller( TextureUnitState layer, Real speed )
		{
			IControllerValue<Real> val = null;
			IControllerFunction<Real> func = null;
			Controller<Real> controller = null;

			// if both u and v speeds are the same, we can use a single controller for it
			if ( speed != 0 )
			{
				// create the value and function
				val = new TexCoordModifierControllerValue( layer, false, true );
				func = new MultipyControllerFunction( -speed, true );

				// create the controller (uses FrameTime for source by default)
				controller = CreateController( val, func );
			}

			return controller;
		}
		/// <summary>
		///     Creates a basic time-based texture u coordinate modifier designed for creating scrolling textures.
		/// </summary>
		/// <remarks>
		///     This simple method allows you to easily create constant-speed scrolling textures. If you want more
		///     control, look up the <see cref="CreateTextureWaveTransformer"/> for more complex wave-based
		///     scrollers / stretchers / rotaters.
		/// </remarks>
		/// <param name="layer">The texture unit to animate.</param>
		/// <param name="speed">speed, in wraps per second.</param>
		/// <returns>A newly created controller object that will be updated during the main render loop.</returns>
		public Controller<Real> CreateTextureUScroller( TextureUnitState layer, Real speed )
		{
			IControllerValue<Real> val = null;
			IControllerFunction<Real> func = null;
			Controller<Real> controller = null;

			// Don't create a controller if the speed is zero
			if ( speed != 0 )
			{
				// create the value and function
				val = new TexCoordModifierControllerValue( layer, true );
				func = new MultipyControllerFunction( -speed, true );

				// create the controller (uses FrameTime for source by default)
				controller = CreateController( val, func );
			}

			return controller;
		}
		/// <summary>
		///     Predefined controller value for setting a single floating-
		///     point value in a constant paramter of a vertex or fragment program.
		/// </summary>
		/// <remarks>
		///     Any value is accepted, it is propagated into the 'x'
		///     component of the constant register identified by the index. If you
		///     need to use named parameters, retrieve the index from the param
		///     object before setting this controller up.
		/// </remarks>
		/// <param name="parms"></param>
		/// <param name="index"></param>
		/// <param name="timeFactor"></param>
		/// <returns></returns>
		public Controller<Real> CreateGpuProgramTimerParam( GpuProgramParameters parms, int index, Real timeFactor )
		{
			IControllerValue<Real> val = new FloatGpuParamControllerValue( parms, index );
			IControllerFunction<Real> func = new MultipyControllerFunction( timeFactor, true );

			return CreateController( val, func );
		}
		/// <summary>
		///     Creates a basic time-based texture coordinate modifier designed for creating rotating textures.
		/// </summary>
		/// <remarks>
		///     This simple method allows you to easily create constant-speed rotating textures. If you want more
		///     control, look up the ControllerManager.CreateTextureWaveTransformer for more complex wave-based
		///     scrollers / stretchers / rotaters.
		/// </remarks>
		/// <param name="layer">The texture unit to animate.</param>
		/// <param name="speed">Speed of the rotation, in counter-clockwise revolutions per second.</param>
		/// <returns>A newly created controller object that will be updated during the main render loop.</returns>
		public Controller<Real> CreateTextureRotator( TextureUnitState layer, Real speed )
		{
			IControllerValue<Real> val = new TexCoordModifierControllerValue( layer, false, false, false, false, true );
			IControllerFunction<Real> func = new MultipyControllerFunction( -speed, true );

			return CreateController( val, func );
		}