public override void Update(FP dt) { this._uniqueBodies.Clear(); this.World.QueryAABB(delegate(Fixture fixture) { bool flag3 = fixture.Body.IsStatic || !fixture.Body.Awake; bool result; if (flag3) { result = true; } else { bool flag4 = !this._uniqueBodies.ContainsKey(fixture.Body.BodyId); if (flag4) { this._uniqueBodies.Add(fixture.Body.BodyId, fixture.Body); } result = true; } return(result); }, ref this._container); foreach (KeyValuePair <int, Body> current in this._uniqueBodies) { Body value = current.Value; TSVector2 zero = TSVector2.zero; TSVector2 zero2 = TSVector2.zero; FP fP = 0; FP fP2 = 0; for (int i = 0; i < value.FixtureList.Count; i++) { Fixture fixture2 = value.FixtureList[i]; bool flag = fixture2.Shape.ShapeType != ShapeType.Polygon && fixture2.Shape.ShapeType > ShapeType.Circle; if (!flag) { Shape shape = fixture2.Shape; TSVector2 tSVector; FP fP3 = shape.ComputeSubmergedArea(ref this._normal, this._offset, ref value._xf, out tSVector); fP += fP3; zero.x += fP3 * tSVector.x; zero.y += fP3 * tSVector.y; fP2 += fP3 * shape.Density; zero2.x += fP3 * tSVector.x * shape.Density; zero2.y += fP3 * tSVector.y * shape.Density; } } zero.x /= fP; zero.y /= fP; zero2.x /= fP2; zero2.y /= fP2; bool flag2 = fP < Settings.Epsilon; if (!flag2) { TSVector2 force = -this.Density * fP * this._gravity; value.ApplyForce(force, zero2); TSVector2 tSVector2 = value.GetLinearVelocityFromWorldPoint(zero) - this.Velocity; tSVector2 *= -this.LinearDragCoefficient * fP; value.ApplyForce(tSVector2, zero); value.ApplyTorque(-value.Inertia / value.Mass * fP * value.AngularVelocity * this.AngularDragCoefficient); } } }
public override void Update(FP dt) { _uniqueBodies.Clear(); World.QueryAABB(fixture => { if (fixture.Body.IsStatic || !fixture.Body.Awake) { return(true); } if (!_uniqueBodies.ContainsKey(fixture.Body.BodyId)) { _uniqueBodies.Add(fixture.Body.BodyId, fixture.Body); } return(true); }, ref _container); foreach (KeyValuePair <int, Body> kv in _uniqueBodies) { Body body = kv.Value; TSVector2 areac = TSVector2.zero; TSVector2 massc = TSVector2.zero; FP area = 0; FP mass = 0; for (int j = 0; j < body.FixtureList.Count; j++) { Fixture fixture = body.FixtureList[j]; if (fixture.Shape.ShapeType != ShapeType.Polygon && fixture.Shape.ShapeType != ShapeType.Circle) { continue; } Shape shape = fixture.Shape; TSVector2 sc; FP sarea = shape.ComputeSubmergedArea(ref _normal, _offset, ref body._xf, out sc); area += sarea; areac.x += sarea * sc.x; areac.y += sarea * sc.y; mass += sarea * shape.Density; massc.x += sarea * sc.x * shape.Density; massc.y += sarea * sc.y * shape.Density; } areac.x /= area; areac.y /= area; massc.x /= mass; massc.y /= mass; if (area < Settings.Epsilon) { continue; } //Buoyancy TSVector2 buoyancyForce = -Density * area * _gravity; body.ApplyForce(buoyancyForce, massc); //Linear drag TSVector2 dragForce = body.GetLinearVelocityFromWorldPoint(areac) - Velocity; dragForce *= -LinearDragCoefficient * area; body.ApplyForce(dragForce, areac); //Angular drag body.ApplyTorque(-body.Inertia / body.Mass * area * body.AngularVelocity * AngularDragCoefficient); } }