public void PivotJointProperties() { var anchorA = new Vect(1, 1); var anchorB = new Vect(0.5, 0.5); var constraint = new PivotJoint(bodyA, bodyB, anchorA, anchorB); var constraint2 = new PivotJoint(bodyA, bodyB, Vect.Zero ); Assert.AreEqual(anchorA, constraint.AnchorA, "#1"); Assert.AreEqual(anchorB, constraint.AnchorB, "#2"); constraint.AnchorA = anchorB; constraint.AnchorB = anchorA; Assert.AreEqual(anchorB, constraint.AnchorA, "#3"); Assert.AreEqual(anchorA, constraint.AnchorB, "#4"); Assert.IsTrue(PivotJoint.IsPivotJoint(constraint), "#5"); Assert.AreEqual(new Vect(-3, -2), constraint2.AnchorB, "#6"); Assert.AreEqual(new Vect(-2, -1), constraint2.AnchorA, "#7"); }
public override Space LoadContent() { space = ChipmunkDemoGame.CreateSpace(); space.Iterations = 10; space.SleepTimeThreshold = 0.5; Body staticBody = space.StaticBody; Shape shape = new Segment(staticBody, new Vect(-320, -240), new Vect(-320, 240), 0.0); // Create segments around the edge of the screen. space.AddShape(shape); shape.Elasticity = 1.0; shape.Friction = 1.0; shape.Filter = ChipmunkDemoGame.NotGrabbableFilter; shape = new Segment(staticBody, new Vect(320, -240), new Vect(320, 240), 0.0); space.AddShape(shape); shape.Elasticity = 1.0; shape.Friction = 1.0; shape.Filter = ChipmunkDemoGame.NotGrabbableFilter; shape = new Segment(staticBody, new Vect(-320, -240), new Vect(320, -240), 0.0); space.AddShape(shape); shape.Elasticity = 1.0; shape.Friction = 1.0; shape.Filter = ChipmunkDemoGame.NotGrabbableFilter; shape = new Segment(staticBody, new Vect(-320, 240), new Vect(320, 240), 0.0); space.AddShape(shape); shape.Elasticity = 1.0; shape.Friction = 1.0; shape.Filter = ChipmunkDemoGame.NotGrabbableFilter; for (int i = 0; i < 50; i++) { Body body = AddBox(20, 1); Constraint p = new PivotJoint(staticBody, body, Vect.Zero, Vect.Zero); space.AddConstraint(p); p.MaxBias = 0; // disable joint correction p.MaxForce = 1000.0; // emulate linear friction Constraint g = new GearJoint(staticBody, body, 0.0, 1.0); space.AddConstraint(g); g.MaxBias = 0; // disable joint correction g.MaxForce = 5000.0; // emulate angular friction } // We joint the tank to the control body and control the tank indirectly by modifying the control body. tankControlBody = new Body(BodyType.Kinematic); space.AddBody(tankControlBody); tankBody = AddBox(30, 10); Constraint pivot = new PivotJoint(tankControlBody, tankBody, Vect.Zero, Vect.Zero); space.AddConstraint(pivot); pivot.MaxBias = 0; // disable joint correction pivot.MaxForce = 10000.0; // emulate linear friction Constraint gear = new GearJoint(tankControlBody, tankBody, 0.0, 1.0); space.AddConstraint(gear); gear.ErrorBias = 0; // attempt to fully correct the joint each step gear.MaxBias = 1.2; // but limit it's angular correction rate gear.MaxForce = 50000.0; // emulate angular friction return(space); }