Now, we are going to add another physics simulator with a different gravitational force to control the fluid model as an actor, with a predefined behavior.
1. Stay in the
3DInvadersSilverlight
project.2. Open
InvadersGame.cs
.3. Add the following
private
variable in thepublic class InvadersGame : RealTimeGame
, to hold anotherPhysicsSimulator
(FarseerGames.FarseerPhysics.PhysicsSimulator
) instance:private PhysicsSimulator _fluidPhysicsSimulator;
4. Add the following
private
variable to hold the newFluidWithWaves
instance:private FluidWithWaves _fluidWithWaves;
5. Add the following
private
method to initialize the fluids physics simulator, specifying a specific desired gravitational force as a 2D vector parameter:private void InitializeFluidPhysicsSimulator() { fluidPhysicsSimulator = new PhysicsSimulator(new Vector2(0,4f)); //50 pixels = 1 meter ConvertUnits.SetDisplayUnitToSimUnitRatio(50); }
6. Add the following lines of code...