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); }
private BuoyancyTest() { //Make a box //Bottom Body ground = BodyFactory.CreateBody(World); Vertices edge = PolygonTools.CreateEdge(new Vector2(0.0f, 0.0f), new Vector2(40.0f, 0.0f)); PolygonShape shape = new PolygonShape(edge); ground.CreateFixture(shape); //Left side shape.Set(PolygonTools.CreateEdge(new Vector2(0.0f, 0.0f), new Vector2(00.0f, 15.0f))); ground.CreateFixture(shape); //Right side shape.Set(PolygonTools.CreateEdge(new Vector2(40.0f, 0.0f), new Vector2(40.0f, 15.0f))); ground.CreateFixture(shape); //Buoyancy controller _aabbContainer = new AABBFluidContainer(new Vector2(0, 0), 40, 10); _waveContainer = new WaveContainer(new Vector2(0, 0), 40, 10); _waveContainer.WaveGeneratorStep = 0; FluidDragController buoyancyController = new FluidDragController(_waveContainer, 4f, 0.98f, 0.2f, World.Gravity); buoyancyController.Entry += EntryEventHandler; Vector2 offset = new Vector2(5, 0); //Bunch of balls for (int i = 0; i < 4; i++) { Fixture fixture = FixtureFactory.CreateCircle(World, 1, 1, new Vector2(15, 1) + offset * i); fixture.Body.BodyType = BodyType.Dynamic; buoyancyController.AddGeom(fixture); } World.Add(buoyancyController); }
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); }
public void Reset() { FluidDragController.Reset(); }