public static FixedDistanceJoint CreateFixedDistanceJoint(World world, Body body, Vector2 localAnchor, Vector2 worldAnchor) { FixedDistanceJoint distanceJoint = new FixedDistanceJoint(body, localAnchor, worldAnchor); world.AddJoint(distanceJoint); return(distanceJoint); }
internal override void UpdateJoint() { base.UpdateJoint(); if (this.joint == null) { return; } FixedDistanceJoint j = this.joint as FixedDistanceJoint; j.WorldAnchorB = PhysicsConvert.ToPhysicalUnit(this.worldAnchor); j.LocalAnchorA = GetFarseerPoint(this.BodyA, this.localAnchor); j.DampingRatio = this.dampingRatio; j.Frequency = this.frequency; j.Length = PhysicsConvert.ToPhysicalUnit(this.length); }
public void LoadStatics() { JointFactory.CreateFixedRevoluteJoint( Platform.Instance.PhysicsWorld, GameWorldManager.Instance.GetEntity("bridge").PhysicsEntity.GetBody("FloorBody"), UnitsConverter.ToSimUnits(new Vector2(-120f, 0f)), UnitsConverter.ToSimUnits(new Vector2(2040f + 60f * 16, -43)) ); FixedDistanceJoint dj = JointFactory.CreateFixedDistanceJoint( Platform.Instance.PhysicsWorld, GameWorldManager.Instance.GetEntity("bridge").PhysicsEntity.GetBody("FloorBody"), UnitsConverter.ToSimUnits(new Vector2(120f, -5f)), UnitsConverter.ToSimUnits(new Vector2(2040f + 60f * 20, -180f)) ); dj.Frequency = 2f; dj.DampingRatio = 0.4f; }
public void LoadSemiStatics() { GameWorldManager.Instance.GetEntity("button1").RegisterComponent( "active", new ButtonComponent("ButtonJoint1") ); GameWorldManager.Instance.GetEntity("button0").RegisterComponent( "active", new ButtonComponent("ButtonJoint1", false, true) ); GameWorldManager.Instance.GetEntity("lifteddoor0").RegisterComponent( "doorHandle", new LiftedDoorComponent(GameWorldManager.Instance.GetEntity("button1").GetComponent("active"), "DoorJoint1") ); _gravityButton = GameWorldManager.Instance.GetEntity("button0").GetComponent("active") as ButtonComponent; JointFactory.CreateFixedRevoluteJoint( Platform.Instance.PhysicsWorld, GameWorldManager.Instance.GetEntity("floorbridge0").PhysicsEntity.GetBody("FloorBody"), UnitsConverter.ToSimUnits(new Vector2(120f, 0f)), UnitsConverter.ToSimUnits(new Vector2(2689f, 564)) ); FixedDistanceJoint dj = JointFactory.CreateFixedDistanceJoint( Platform.Instance.PhysicsWorld, GameWorldManager.Instance.GetEntity("floorbridge0").PhysicsEntity.GetBody("FloorBody"), UnitsConverter.ToSimUnits(new Vector2(-120f, -5f)), UnitsConverter.ToSimUnits(new Vector2(2466f, 244f)) ); dj.Frequency = 1.5f; dj.DampingRatio = 0.355f; }
private WebTest() { World.JointRemoved += JointRemovedFired; World.BodyRemoved += BodyRemovedFired; { PolygonShape shape = new PolygonShape(5); shape.SetAsBox(0.5f, 0.5f); _bodies[0] = BodyFactory.CreateBody(World); _bodies[0].BodyType = BodyType.Dynamic; _bodies[0].Position = new Vector2(-5.0f, 5.0f); _bodies[0].CreateFixture(shape); _bodies[1] = BodyFactory.CreateBody(World); _bodies[1].BodyType = BodyType.Dynamic; _bodies[1].Position = new Vector2(5.0f, 5.0f); _bodies[1].CreateFixture(shape); _bodies[2] = BodyFactory.CreateBody(World); _bodies[2].BodyType = BodyType.Dynamic; _bodies[2].Position = new Vector2(5.0f, 15.0f); _bodies[2].CreateFixture(shape); _bodies[3] = BodyFactory.CreateBody(World); _bodies[3].BodyType = BodyType.Dynamic; _bodies[3].Position = new Vector2(-5.0f, 15.0f); _bodies[3].CreateFixture(shape); FixedDistanceJoint dj = new FixedDistanceJoint(_bodies[0], new Vector2(-0.5f, -0.5f), new Vector2(-10.0f, 0.0f)); _joints[0] = dj; dj.Frequency = 2.0f; dj.DampingRatio = 0.0f; World.AddJoint(_joints[0]); FixedDistanceJoint dj1 = new FixedDistanceJoint(_bodies[1], new Vector2(0.5f, -0.5f), new Vector2(10.0f, 0.0f)); _joints[1] = dj1; dj1.Frequency = 2.0f; dj1.DampingRatio = 0.0f; World.AddJoint(_joints[1]); FixedDistanceJoint dj2 = new FixedDistanceJoint(_bodies[2], new Vector2(0.5f, 0.5f), new Vector2(10.0f, 20.0f)); _joints[2] = dj2; dj2.Frequency = 2.0f; dj2.DampingRatio = 0.0f; World.AddJoint(_joints[2]); FixedDistanceJoint dj3 = new FixedDistanceJoint(_bodies[3], new Vector2(-0.5f, 0.5f), new Vector2(-10.0f, 20.0f)); _joints[3] = dj3; dj3.Frequency = 2.0f; dj3.DampingRatio = 0.0f; World.AddJoint(_joints[3]); DistanceJoint dj4 = new DistanceJoint(_bodies[0], _bodies[1], Vector2.Zero, Vector2.Zero); _joints[4] = dj4; dj4.Frequency = 2.0f; dj4.DampingRatio = 0.0f; World.AddJoint(_joints[4]); DistanceJoint dj5 = new DistanceJoint(_bodies[1], _bodies[2], Vector2.Zero, Vector2.Zero); _joints[5] = dj5; dj5.Frequency = 2.0f; dj5.DampingRatio = 0.0f; World.AddJoint(_joints[5]); DistanceJoint dj6 = new DistanceJoint(_bodies[2], _bodies[3], Vector2.Zero, Vector2.Zero); _joints[6] = dj6; dj6.Frequency = 2.0f; dj6.DampingRatio = 0.0f; World.AddJoint(_joints[6]); DistanceJoint dj7 = new DistanceJoint(_bodies[3], _bodies[0], Vector2.Zero, Vector2.Zero); _joints[7] = dj7; dj7.Frequency = 2.0f; dj7.DampingRatio = 0.0f; World.AddJoint(_joints[7]); } }
public Spiderweb(World world, Vector2 position, float radius, int rings, int sides) { const float breakpoint = 100f; _world = world; _radius = radius; List <List <Body> > ringBodys = new List <List <Body> >(rings); for (int i = 1; i < rings; ++i) { Vertices vertices = PolygonTools.CreateCircle(i * 2.9f, sides); List <Body> bodies = new List <Body>(sides); //Create the first goo Body prev = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[0]); prev.FixedRotation = true; prev.Position += position; prev.BodyType = BodyType.Dynamic; bodies.Add(prev); //Connect the first goo to the next for (int j = 1; j < vertices.Count; ++j) { Body bod = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[j]); bod.FixedRotation = true; bod.BodyType = BodyType.Dynamic; bod.Position += position; DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prev, bod, Vector2.Zero, Vector2.Zero); dj.Frequency = 4.0f; dj.DampingRatio = 0.5f; dj.Breakpoint = breakpoint; prev = bod; bodies.Add(bod); } //Connect the first and the last box DistanceJoint djEnd = JointFactory.CreateDistanceJoint(world, bodies[0], bodies[bodies.Count - 1], Vector2.Zero, Vector2.Zero); djEnd.Frequency = 4.0f; djEnd.DampingRatio = 0.5f; djEnd.Breakpoint = breakpoint; ringBodys.Add(bodies); } //Create an outer ring Vertices lastRing = PolygonTools.CreateCircle(rings * 2.9f, sides); lastRing.Translate(ref position); List <Body> lastRingFixtures = ringBodys[ringBodys.Count - 1]; //Fix each of the fixtures of the outer ring for (int j = 0; j < lastRingFixtures.Count; ++j) { FixedDistanceJoint fdj = JointFactory.CreateFixedDistanceJoint(world, lastRingFixtures[j], Vector2.Zero, lastRing[j]); fdj.Frequency = 4.0f; fdj.DampingRatio = 0.5f; fdj.Breakpoint = breakpoint; } //Interconnect the rings for (int i = 1; i < ringBodys.Count; i++) { List <Body> prev = ringBodys[i - 1]; List <Body> current = ringBodys[i]; for (int j = 0; j < prev.Count; j++) { Body prevFixture = prev[j]; Body currentFixture = current[j]; DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prevFixture, currentFixture, Vector2.Zero, Vector2.Zero); dj.Frequency = 4.0f; dj.DampingRatio = 0.5f; } } }