public void Initialize(PhysicsSimulator physicsSimulator) { //The wave controller controls how the waves move.. how big, how fast, etc.. //The wave controller is represented as set of points equally //spaced horizontally along the width of the wave. WaveController = new WaveController(); WaveController.Position = ConvertUnits.ToSimUnits(0, 300); WaveController.Width = ConvertUnits.ToSimUnits(700); WaveController.Height = ConvertUnits.ToSimUnits(200); WaveController.NodeCount = 20; //how many vertices make up the surface of the wave WaveController.DampingCoefficient = .95f; //determines how quickly the wave will disipate WaveController.Frequency = .16f; //determines how fast the wave algorithm runs (seconds) //The wave generator parameters simply move an end-point of the wave up and down. //Think of a string attached to a wall on one end and held by a person on the other. //If the person moves the string up and down to make "waves" then the arm is acting //similar to the wave generator. The WaveGeneratorStep property controls how fast the "arm" //moves. WaveController.WaveGeneratorMax = WaveGeneratorMax; WaveController.WaveGeneratorMin = WaveGeneratorMin; WaveController.WaveGeneratorStep = WaveGeneratorStep; WaveController.Initialize(); //fluid drag controller controls how things move once IN the water. FluidDragController = new FluidDragController(); FluidDragController.Initialize(WaveController, 5f, 4f, 2f, physicsSimulator.Gravity); //init with default values. physicsSimulator.Add(FluidDragController); }
public void AddFluidContainer(FluidContainerMain fluidContainerMain) { double x = Convert.ToDouble(fluidContainerMain.VisualElement.GetValue(Canvas.LeftProperty)); double y = Convert.ToDouble(fluidContainerMain.VisualElement.GetValue(Canvas.TopProperty)); float width = (float)fluidContainerMain.VisualElement.ActualWidth; float height = (float)fluidContainerMain.VisualElement.ActualHeight; WaveController waveController = fluidContainerMain.WaveControllerObject; waveController.Position = new Vector2((float)x, (float)y); waveController.Width = width; waveController.Height = height; waveController.NodeCount = fluidContainerMain.NodeCount; waveController.DampingCoefficient = (float)fluidContainerMain.DampingCoefficient; waveController.Frequency = (float)fluidContainerMain.Frequency; waveController.WaveGeneratorMax = (float)fluidContainerMain.WaveGeneratorMax; waveController.WaveGeneratorMin = (float)fluidContainerMain.WaveGeneratorMin; waveController.WaveGeneratorStep = (float)fluidContainerMain.WaveGeneratorStep; waveController.Initialize(); Vector2 vecTopLeft = new Vector2((float)x, (float)y); Vector2 vecBottomRight = new Vector2((float)x + width, (float)y + height); AABB waterAABB = new AABB(vecTopLeft, vecBottomRight); AABBFluidContainer waterContainer = new AABBFluidContainer(waterAABB); FluidDragController fluidDragController = new FluidDragController(); foreach (KeyValuePair <string, PhysicsSprite> item in PhysicsObjects) { PhysicsSprite sprite = item.Value; fluidDragController.AddGeom(sprite.GeometryObject); } fluidDragController.Initialize(waterContainer, (float)fluidContainerMain.FluidDensity, (float)fluidContainerMain.LinearDragCoefficient, (float)fluidContainerMain.RotationalDragCoefficient, new Vector2((float)fluidContainerMain.GravityHorizontal, (float)fluidContainerMain.GravityVertical)); Simulator.Add(fluidDragController); }