public Muscle(Organism organism, Organ from, Organ to, float fromRadialPosition, float toRadialPosition, float contractionFactor) { Organism = organism; From = from; To = to; ContractionFactor = contractionFactor; var angle = fromRadialPosition * Math.PI / 180.0; var x = (float)Math.Cos(angle) * from.Radius; var y = (float)Math.Sin(angle) * from.Radius; var anchorFrom = new Vector2(x, y); angle = toRadialPosition * Math.PI / 180.0; x = (float)Math.Cos(angle) * to.Radius; y = (float)Math.Sin(angle) * to.Radius; var anchorTo = new Vector2(x, y); Joint = new DistanceJoint(from.Body, to.Body, anchorFrom, anchorTo) { DampingRatio = 1, Frequency = 0.9f }; Joint.UserData = new MuscleUserData() { Muscle = this }; organism.World.AddJoint(Joint); }
public static DistanceJoint CreateDistanceJoint(World world, Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB) { DistanceJoint distanceJoint = new DistanceJoint(bodyA, bodyB, anchorA, anchorB); world.AddJoint(distanceJoint); return(distanceJoint); }
private void CreateJoints(World world) { const float dampingRatio = 1f; const float frequency = 25f; //head -> body DistanceJoint jHeadBody = new DistanceJoint(_head, _body, new Vector2(0f, -1f), new Vector2(0f, 1.5f)); jHeadBody.CollideConnected = true; jHeadBody.DampingRatio = dampingRatio; jHeadBody.Frequency = frequency; jHeadBody.Length = 0.025f; world.Add(jHeadBody); //leftJet -> body DistanceJoint jLeftJetBody = new DistanceJoint(_leftJet, _body, new Vector2(0.5f, 0f), new Vector2(-1f, 1.5f)); jLeftJetBody.CollideConnected = true; jLeftJetBody.DampingRatio = dampingRatio; jLeftJetBody.Frequency = frequency; jLeftJetBody.Length = 0.025f; world.Add(jLeftJetBody); //rightJet -> body DistanceJoint jRightJetBody = new DistanceJoint(_rightJet, _body, new Vector2(-0.5f, 0f), new Vector2(1f, 1.5f)); jRightJetBody.CollideConnected = true; jRightJetBody.DampingRatio = dampingRatio; jRightJetBody.Frequency = frequency; jRightJetBody.Length = 0.025f; world.Add(jRightJetBody); }
private void AttachGunJoint(Body body) { float rotation = (item.body.Dir == -1.0f) ? item.body.Rotation - MathHelper.Pi : item.body.Rotation; body.SetTransform(TransformedBarrelPos, rotation); //Vector2 axis = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); if (gunJoint != null) { GameMain.World.RemoveJoint(gunJoint); } gunJoint = new DistanceJoint(item.body.FarseerBody, body, BarrelPos, new Vector2(sectionLength / 2, 0.0f)); gunJoint.Length = sectionLength; //gunJoint.LocalAnchorA = BarrelPos; //gunJoint.LocalAnchorB = new Vector2(sectionLength / 2, 0.0f); //gunJoint.UpperLimit = sectionLength; //gunJoint.LowerLimit = 0.0f; //gunJoint.LimitEnabled = true; //gunJoint.ReferenceAngle = 0.0f; GameMain.World.AddJoint(gunJoint); }
private void SetupDistanceJoint(object sender) { //remove old joints if (_joints.Count > 0) { foreach (DistanceJoint jnt in _joints) { _physicsController.DeleteObject(jnt); } } const float breakpoint = 1000f; //translate coordinates relative to screen var touchedObject = sender as PhysicsSprite; //var list = BoundaryHelper.GetPointsForElement(touchedObject.uiElement, e.ManipulationContainer, false); //get reference to player PhysicsSprite player = _physicsController.PhysicsObjects["player"]; //create distance joint between the two DistanceJoint joint = JointFactory.CreateDistanceJoint(_physicsController.Simulator, player.BodyObject, touchedObject.BodyObject, Vector2.Zero, Vector2.Zero); joint.Frequency = 4.0f; joint.DampingRatio = .5f; joint.Breakpoint = breakpoint; joint.CollideConnected = true; joint.Broke += joint_Broke; _joints.Add(joint); //create tounge //timer var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(33) }; timer.Tick += delegate { //joint broke if (!joint.Enabled) { timer.Stop(); _physicsController.DeleteObject(joint); return; } //reduce distance if (joint.Length <= 0f) { timer.Stop(); _physicsController.DeleteObject(joint); } joint.Length -= .1f; }; timer.Start(); }
/// <summary> /// Updates all GUI elements from current values in the joint. /// </summary> /// <param name="joint">Joint to update the GUI from.</param> protected void Refresh(DistanceJoint joint) { if (enableMinLimitField.Value != joint.EnableMinDistanceLimit) { enableMinLimitField.Value = joint.EnableMinDistanceLimit; minLimitField.Active = joint.EnableMinDistanceLimit; } minLimitField.Value = joint.MinDistance; if (enableMaxLimitField.Value != joint.EnableMaxDistanceLimit) { enableMaxLimitField.Value = joint.EnableMaxDistanceLimit; maxLimitField.Active = joint.EnableMaxDistanceLimit; } maxLimitField.Value = joint.MaxDistance; toleranceField.Value = joint.Tolerance; if (enableSpringField.Value != joint.EnableSpring) { enableSpringField.Value = joint.EnableSpring; springLayout.Active = joint.EnableSpring; } springGUI.Spring = joint.Spring; base.Refresh(joint); }
public static DistanceJoint CreateDistanceJoint(World world, Body bodyA, Body bodyB, Vector2 anchorA, Vector2 anchorB, bool useWorldCoordinates = false) { var distanceJoint = new DistanceJoint(bodyA, bodyB, anchorA, anchorB, useWorldCoordinates); world.addJoint(distanceJoint); return(distanceJoint); }
internal Organ(Guid dnauid, Organism organism, Organ parent, Vector2 position, float radius) { DNAUID = dnauid; Organism = organism; Parent = parent; Radius = radius; Body = new Body(organism.World, position, 0, BodyType.Dynamic, this); Body.CreateFixture(new CircleShape(radius, 1), new OrganUserData() { Organ = this }); Body.UserData = new OrganUserData() { Organ = this }; if (parent != null) { Bone = new DistanceJoint(parent.Body, Body, Vector2.Zero, Vector2.Zero); Bone.UserData = new BoneUserData() { From = parent, To = this }; organism.World.AddJoint(Bone); } }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, Lines, Framework.GraphicsDevice); _obstacles = new Body(World); FixtureFactory.AttachEdge(new Vector2(-16f, -1f), new Vector2(-14f, 1f), _obstacles); FixtureFactory.AttachEdge(new Vector2(-14f, 1f), new Vector2(-12f, -1f), _obstacles); FixtureFactory.AttachEdge(new Vector2(14f, -1f), new Vector2(12f, 5f), _obstacles); FixtureFactory.AttachEdge(new Vector2(14f, -1f), new Vector2(16f, 5f), _obstacles); _angleBody[0] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[0].BodyType = BodyType.Dynamic; _angleBody[0].Friction = 0.7f; _angleBody[0].Position = new Vector2(-15f, -5f); _angleBody[1] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[1].BodyType = BodyType.Dynamic; _angleBody[1].Friction = 0.7f; _angleBody[1].Position = new Vector2(-18f, 5f); _angleBody[2] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[2].BodyType = BodyType.Dynamic; _angleBody[2].Friction = 0.7f; _angleBody[2].Position = new Vector2(-10f, 5f); World.AddJoint(new AngleJoint(_angleBody[0], _angleBody[1])); World.AddJoint(new AngleJoint(_angleBody[0], _angleBody[2])); _distanceBody[0] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[0].BodyType = BodyType.Dynamic; _distanceBody[0].Friction = 0.7f; _distanceBody[0].Position = new Vector2(11.5f, -4f); _distanceBody[1] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[1].BodyType = BodyType.Dynamic; _distanceBody[1].Friction = 0.7f; _distanceBody[1].Position = new Vector2(16.5f, -4f); _distanceBody[2] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[2].BodyType = BodyType.Dynamic; _distanceBody[2].Friction = 0.7f; _distanceBody[2].Position = new Vector2(11.5f, -6f); _distanceBody[3] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[3].BodyType = BodyType.Dynamic; _distanceBody[3].Friction = 0.7f; _distanceBody[3].Position = new Vector2(16.5f, -6f); DistanceJoint softDistance = new DistanceJoint(_distanceBody[0], _distanceBody[1], Vector2.Zero, Vector2.Zero, false); softDistance.DampingRatio = 0.3f; softDistance.Frequency = 5f; World.AddJoint(softDistance); World.AddJoint(new DistanceJoint(_distanceBody[2], _distanceBody[3], Vector2.Zero, Vector2.Zero, false)); // create sprites based on bodies _angleCube = new Sprite(ContentWrapper.TextureFromShape(_angleBody[0].FixtureList[0].Shape, "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Grey, 1f)); _distanceCube = new Sprite(ContentWrapper.TextureFromShape(_distanceBody[0].FixtureList[0].Shape, "Stripe", ContentWrapper.Red, ContentWrapper.Blue, ContentWrapper.Grey, 4f)); }
private void RemovePlayerJoint() { if (_playerBodyJoint != null) { PlayWindow.World.RemoveJoint(_playerBodyJoint); _playerBodyJoint = null; } }
private void CreatePlayerJoint(Body playerBody) { _playerBodyJoint = JointFactory.CreateDistanceJoint(PlayWindow.World, Body, playerBody, Vector2.Zero, Vector2.Zero); _playerBodyJoint.Frequency = 5.5f; _playerBodyJoint.DampingRatio = 1.5f; _playerBodyJoint.Length = 0.01f; _playerBodyJoint.CollideConnected = true; }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _obstacles = BodyFactory.CreateBody(World); FixtureFactory.AttachEdge(new Vector2(-16f, -1f), new Vector2(-14f, 1f), _obstacles); FixtureFactory.AttachEdge(new Vector2(-14f, 1f), new Vector2(-12f, -1f), _obstacles); FixtureFactory.AttachEdge(new Vector2(14f, -1f), new Vector2(12f, 5f), _obstacles); FixtureFactory.AttachEdge(new Vector2(14f, -1f), new Vector2(16f, 5f), _obstacles); _angleBody[0] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[0].BodyType = BodyType.Dynamic; _angleBody[0].Friction = 0.7f; _angleBody[0].Position = new Vector2(-15f, -5f); _angleBody[1] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[1].BodyType = BodyType.Dynamic; _angleBody[1].Friction = 0.7f; _angleBody[1].Position = new Vector2(-18f, 5f); _angleBody[2] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _angleBody[2].BodyType = BodyType.Dynamic; _angleBody[2].Friction = 0.7f; _angleBody[2].Position = new Vector2(-10f, 5f); World.AddJoint(new AngleJoint(_angleBody[0], _angleBody[1])); World.AddJoint(new AngleJoint(_angleBody[0], _angleBody[2])); _distanceBody[0] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[0].BodyType = BodyType.Dynamic; _distanceBody[0].Friction = 0.7f; _distanceBody[0].Position = new Vector2(11.5f, -4f); _distanceBody[1] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[1].BodyType = BodyType.Dynamic; _distanceBody[1].Friction = 0.7f; _distanceBody[1].Position = new Vector2(16.5f, -4f); _distanceBody[2] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[2].BodyType = BodyType.Dynamic; _distanceBody[2].Friction = 0.7f; _distanceBody[2].Position = new Vector2(11.5f, -6f); _distanceBody[3] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _distanceBody[3].BodyType = BodyType.Dynamic; _distanceBody[3].Friction = 0.7f; _distanceBody[3].Position = new Vector2(16.5f, -6f); DistanceJoint softDistance = new DistanceJoint(_distanceBody[0], _distanceBody[1], Vector2.Zero, Vector2.Zero); JointHelper.LinearStiffness(5f, 0.3f, softDistance.BodyA, softDistance.BodyB, out var stiffness, out var damping); softDistance.Damping = damping; softDistance.Stiffness = stiffness; World.AddJoint(softDistance); World.AddJoint(new DistanceJoint(_distanceBody[2], _distanceBody[3], Vector2.Zero, Vector2.Zero)); // create sprites based on bodies _angleCube = new Sprite(Managers.TextureManager.TextureFromShape(_angleBody[0].FixtureList[0].Shape, "Square", Colors.Gold, Colors.Orange, Colors.Grey, 1f)); _distanceCube = new Sprite(Managers.TextureManager.TextureFromShape(_distanceBody[0].FixtureList[0].Shape, "Stripe", Colors.Red, Colors.Blue, Colors.Grey, 4f)); }
public override void update() { if (first) { Body b = gameWorld.bodyDict[anchorName]; toAnchor = gameWorld.joinBodies_Distance(entity.my_Body, b); OGLength = toAnchor.GetLength(); first = false; diving = true; retracting = true; return; } float length = toAnchor.GetLength(); if (!diving && diveIn <= 0) { diving = true; } else if (diving) { if (retracting) { length -= .05f; toAnchor.SetLength(length); if (length < 2) { diving = false; retracting = false; diveIn = random.Next(50, 250); pauseTime = random.Next(50, 150); } } else { if (length >= OGLength) { if (pauseTime <= 0) { retracting = true; } else { pauseTime--; } } else { length += .05f; toAnchor.SetLength(length); } } } else { diveIn--; } }
/// <inheritdoc/> protected internal override void Initialize() { DistanceJoint joint = InspectedObject as DistanceJoint; if (joint != null) { BuildGUI(joint); } }
public override Joint createJoint() { var joint = new DistanceJoint(bodyA, bodyB, ownerBodyAnchor * FSConvert.displayToSim, otherBodyAnchor * FSConvert.displayToSim); joint.collideConnected = collideConnected; joint.frequency = frequency; joint.dampingRatio = dampingRatio; return(joint); }
public override Joint CreateJoint() { var joint = new DistanceJoint(BodyA, BodyB, OwnerBodyAnchor * FSConvert.DisplayToSim, OtherBodyAnchor * FSConvert.DisplayToSim); joint.CollideConnected = CollideConnected; joint.Frequency = Frequency; joint.DampingRatio = DampingRatio; return(joint); }
/** * Adds a body and the pre-made distance joint. Should only be used for deserialization. */ public void addBodyAndJoint(Body argBody, DistanceJoint argJoint) { addBody(argBody); if (joints == null) { joints = new List<DistanceJoint>(); } joints.Add(argJoint); }
/// <summary> /// Creates a distance joint between two bodies /// </summary> /// <param name="b1"></param> /// <param name="b2"></param> /// <returns></returns> public DistanceJoint joinBodies_Distance(Body b1, Body b2) { Vector2 pos1 = b1.GetWorldCenter(); Vector2 pos2 = b2.GetWorldCenter(); DistanceJointDef djd = new DistanceJointDef(); djd.Initialize(b1, b2, pos1, pos2); djd.collideConnected = false; DistanceJoint dj = physicsWorld.CreateJoint(djd) as DistanceJoint; return(dj); }
private WreckingBallTest() { Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); { Body prevBody = ground; CircleShape largeShape = new CircleShape(1.5f, 100); CircleShape smallShape = new CircleShape(0.5f, 20); const int N = 10; const float y = 15; for (int i = 0; i < N; ++i) { Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(0.5f + 1.0f * i, y); if (i == N - 1) { Fixture fixture = body.CreateFixture(largeShape); fixture.Friction = 0.2f; fixture.CollisionCategories = Category.Cat2; fixture.CollidesWith = Category.All & ~Category.Cat2; body.Position = new Vector2(1.0f * i, y); body.AngularDamping = 0.4f; } else { Fixture fixture = body.CreateFixture(smallShape); fixture.Friction = 0.2f; fixture.CollisionCategories = Category.Cat1; fixture.CollidesWith = Category.All & ~Category.Cat2; } Vector2 anchor = new Vector2(i, y); RevoluteJoint jd = new RevoluteJoint(prevBody, body, anchor, true); jd.CollideConnected = false; World.AddJoint(jd); prevBody = body; } _dj = new DistanceJoint(ground, prevBody, new Vector2(0, y), Vector2.Zero); //Velcro: The two following lines are actually not needed as Velcro sets the MaxLength to a default value const float extraLength = 0.01f; _dj.MaxLength = N - 1.0f + extraLength; World.AddJoint(_dj); } }
public override Joint CreateJoint() { DistanceJoint joint = new DistanceJoint(BodyA, BodyB, OwnerBodyAnchor * FSConvert.DisplayToSim, OtherBodyAnchor * FSConvert.DisplayToSim) { CollideConnected = CollideConnected, Frequency = Frequency, DampingRatio = DampingRatio }; return(joint); }
public override void InitJoint() { base.InitJoint(); joint = FarseerPhysics.Factories.JointFactory.CreateDistanceJoint(FSWorldComponent.PhysicsWorld, BodyA.PhysicsBody, BodyB.PhysicsBody, Microsoft.Xna.Framework.FVector2.Zero, Microsoft.Xna.Framework.FVector2.Zero); joint.CollideConnected = CollideConnected; joint.Frequency = Frequency; //joint.DampingRatio = 0.5f; }
public async Task JointDeletionTest() { var server = StartServer(); await server.WaitIdleAsync(); var entManager = server.ResolveDependency <IEntityManager>(); var mapManager = server.ResolveDependency <IMapManager>(); var susManager = server.ResolveDependency <IEntitySystemManager>(); var jointSystem = susManager.GetEntitySystem <SharedJointSystem>(); var broadphase = susManager.GetEntitySystem <SharedBroadphaseSystem>(); var fixSystem = susManager.GetEntitySystem <FixtureSystem>(); DistanceJoint joint = default !;
public PendulumPhysicsComponent(Engine engine, Point gameWorldPivotPosition, Point gameWorldWeightPosition) : base(engine) { pivotFixture = FixtureFactory.CreateRectangle(Engine.Physics.World, 0.8f, 0.8f, 1.0f); MainFixture = FixtureFactory.CreateRectangle(Engine.Physics.World, 0.8f, 0.8f, 1.0f); MainFixture.Body.Mass = 100.0f; pivotFixture.Body.Position = Engine.Physics.PositionToPhysicsWorld(new Vector2(gameWorldPivotPosition.X, gameWorldPivotPosition.Y)); MainFixture.Body.Position = Engine.Physics.PositionToPhysicsWorld(new Vector2(gameWorldWeightPosition.X, gameWorldWeightPosition.Y)); pivotFixture.CollisionFilter.CollidesWith = Category.Cat31; MainFixture.Body.BodyType = BodyType.Dynamic; distanceJoint = JointFactory.CreateDistanceJoint(Engine.Physics.World, pivotFixture.Body, MainFixture.Body, Vector2.Zero, MainFixture.Body.LocalCenter - new Vector2(0.0f, 0.4f)); }
internal override void UpdateJoint() { base.UpdateJoint(); if (this.joint == null) { return; } DistanceJoint j = this.joint as DistanceJoint; j.LocalAnchorB = GetFarseerPoint(this.BodyB, this.localAnchorB); j.LocalAnchorA = GetFarseerPoint(this.BodyA, this.localAnchorA); j.DampingRatio = this.dampingRatio; j.Frequency = this.frequency; j.Length = PhysicsConvert.ToPhysicalUnit(this.length); }
internal override void UpdateJoint() { base.UpdateJoint(); if (this.joint == null) { return; } DistanceJoint j = this.joint as DistanceJoint; j.LocalAnchorB = GetFarseerPoint(this.OtherBody, this.localAnchorB); j.LocalAnchorA = GetFarseerPoint(this.ParentBody, this.localAnchorA); j.DampingRatio = this.dampingRatio; j.Frequency = this.frequency; j.Length = PhysicsUnit.LengthToPhysical * this.length; }
private static void DrawDistanceJoint(DistanceJoint joint) { Vector3 anchorA = GetAnchor(joint, JointBody.Target); Vector3 anchorB = GetAnchor(joint, JointBody.Anchor); Gizmos.Color = Color.White; Gizmos.DrawSphere(anchorA, 0.05f); Gizmos.DrawSphere(anchorB, 0.05f); Gizmos.Color = Color.Red; Vector3 diff = anchorB - anchorA; float length = diff.Length; Vector3 normal = diff.Normalized; float min = 0.0f; float max = length; if (joint.HasFlag(DistanceJointFlag.MinDistance)) { min = MathEx.Max(0.0f, joint.MinDistance); if (joint.HasFlag(DistanceJointFlag.MaxDistance)) { min = MathEx.Min(min, MathEx.Min(10000.0f, joint.MaxDistance)); } Gizmos.DrawLine(anchorA, anchorA + normal * min); } if (joint.HasFlag(DistanceJointFlag.MaxDistance)) { max = MathEx.Min(10000.0f, joint.MaxDistance); if (joint.HasFlag(DistanceJointFlag.MinDistance)) { max = MathEx.Max(max, min); } if (length > max) { Gizmos.DrawLine(anchorA + normal * max, anchorA + normal * length); } } Gizmos.Color = Color.Green; Gizmos.DrawLine(anchorA + normal * min, anchorA + normal * MathEx.Min(max, length)); }
private static Joint DeserializeDistanceJoint(XElement jointElement, Body bodyA, Body bodyB, World world) { DistanceJoint joint = null; Vector2 localAnchorA, localAnchorB; float dampingRatio = 0.0f, frequency = 0.0f, length = 0.0f; localAnchorA = bodyA.WorldCenter; localAnchorB = bodyB.WorldCenter; foreach (XElement element in jointElement.Elements()) { switch (element.Name.ToString().ToLower()) { case "dampingratio": float.TryParse(element.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out dampingRatio); break; case "frequency": float.TryParse(element.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out frequency); break; case "length": float.TryParse(element.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out length); break; case "localanchora": localAnchorA = localAnchorA.DeserializeOffset(element); localAnchorA = ConvertUnits.ToSimUnits(localAnchorA); break; case "localanchorb": localAnchorB = localAnchorB.DeserializeOffset(element); localAnchorB = ConvertUnits.ToSimUnits(localAnchorB); break; } } joint = JointFactory.CreateDistanceJoint(world, bodyA, bodyB, localAnchorA, localAnchorB); joint.DampingRatio = dampingRatio; joint.Frequency = frequency; joint.Length = ConvertUnits.ToSimUnits(length); return(joint); }
private void UndoSilk(bool rightHand) { if (rightHand) { if (rightSilk != null) { world.RemoveJoint(rightSilk); rightSilk = null; } } else { if (leftSilk != null) { world.RemoveJoint(leftSilk); leftSilk = null; } } }
/// <inheritdoc/> protected internal override InspectableState Refresh() { DistanceJoint joint = InspectedObject as DistanceJoint; if (joint == null) { return(InspectableState.NotModified); } Refresh(joint); InspectableState oldState = modifyState; if (modifyState.HasFlag(InspectableState.Modified)) { modifyState = InspectableState.NotModified; } return(oldState); }
private float SilkSlingRight(Fixture f, Vector2 p, Vector2 n, float fr) { if (f.Body == ragdoll._lowerRightArm) { return(-1); } Vector2 handAnchor = getHandAnchor(true); UndoSilk(true); rightSilk = new DistanceJoint(ragdoll._lowerRightArm, f.Body, ragdoll._lowerRightArm.GetLocalPoint(handAnchor), f.Body.GetLocalPoint(p)); rightSilk.Frequency = silkForce; rightSilk.DampingRatio = .5f; rightSilk.Length = 0; rightSilk.CollideConnected = true; world.AddJoint(rightSilk); return(fr); }
private DistanceJointTest() { Body ground = BodyFactory.CreateEdge(World, new Vector2(-40, 0), new Vector2(40, 0)); Body body = BodyFactory.CreateRectangle(World, 1f, 1f, 5.0f, new Vector2(0, 5), bodyType: BodyType.Dynamic); body.SleepingAllowed = false; body.AngularDamping = 0.1f; float hertz = 1.0f; float dampingRatio = 0.7f; _joint = JointFactory.CreateDistanceJoint(World, ground, body, new Vector2(0, 15), body.Position, true); _joint.CollideConnected = true; JointHelper.LinearStiffness(hertz, dampingRatio, _joint.BodyA, _joint.BodyB, out float stiffness, out float damping); _joint.Stiffness = stiffness; _joint.Damping = damping; _joint.MaxLength = _joint.Length; _joint.MinLength = _joint.Length; }