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); }