public AddConstraint ( Constraint constraint ) : void | ||
constraint | Constraint | The constraint which should be removed. |
return | void |
public void BuildRagdoll(World world, JVector position) { // the torso RigidBody torso = new RigidBody(new BoxShape(1.5f, 3, 0.5f)); torso.Position = position; // the head RigidBody head = new RigidBody(new SphereShape(0.5f)); head.Position = position + new JVector(0, 2.1f, 0); // connect head and torso PointPointDistance headTorso = new PointPointDistance(head, torso, position + new JVector(0, 1.6f, 0), position + new JVector(0, 1.5f, 0)); RigidBody arm1 = new RigidBody(new CapsuleShape(0.8f, 0.2f)); arm1.Position = position + new JVector(1.0f, 0.75f, 0); RigidBody arm2 = new RigidBody(new CapsuleShape(0.8f, 0.2f)); arm2.Position = position + new JVector(-1.0f, 0.75f, 0); RigidBody lowerarm1 = new RigidBody(new CapsuleShape(0.6f, 0.2f)); lowerarm1.Position = position + new JVector(1.0f, -0.45f, 0); RigidBody lowerarm2 = new RigidBody(new CapsuleShape(0.6f, 0.2f)); lowerarm2.Position = position + new JVector(-1.0f, -0.45f, 0); PointOnPoint arm1torso = new PointOnPoint(arm1, torso, position + new JVector(0.9f, 1.4f, 0)); PointOnPoint arm2torso = new PointOnPoint(arm2, torso, position + new JVector(-0.9f, 1.4f, 0)); HingeJoint arm1Hinge = new HingeJoint(world, arm1, lowerarm1, position + new JVector(1.0f, 0.05f, 0), JVector.Right); HingeJoint arm2Hinge = new HingeJoint(world, arm2, lowerarm2, position + new JVector(-1.0f, 0.05f, 0), JVector.Right); RigidBody leg1 = new RigidBody(new CapsuleShape(1.0f, 0.3f)); leg1.Position = position + new JVector(-0.5f, -2.4f, 0); RigidBody leg2 = new RigidBody(new CapsuleShape(1.0f, 0.3f)); leg2.Position = position + new JVector(0.5f, -2.4f, 0); PointOnPoint leg1torso = new PointOnPoint(leg1, torso, position + new JVector(-0.5f, -1.6f, 0)); PointOnPoint leg2torso = new PointOnPoint(leg2, torso, position + new JVector(+0.5f, -1.6f, 0)); RigidBody lowerleg1 = new RigidBody(new CapsuleShape(0.8f, 0.3f)); lowerleg1.Position = position + new JVector(-0.5f, -4.0f, 0); RigidBody lowerleg2 = new RigidBody(new CapsuleShape(0.8f, 0.3f)); lowerleg2.Position = position + new JVector(+0.5f, -4.0f, 0); HingeJoint leg1Hinge = new HingeJoint(world, leg1, lowerleg1, position + new JVector(-0.5f, -3.35f, 0), JVector.Right); HingeJoint leg2Hinge = new HingeJoint(world, leg2, lowerleg2, position + new JVector(0.5f, -3.35f, 0), JVector.Right); lowerleg1.IsActive = false; lowerleg2.IsActive = false; leg1.IsActive = false; leg2.IsActive = false; head.IsActive = false; torso.IsActive = false; arm1.IsActive = false; arm2.IsActive = false; lowerarm1.IsActive = false; lowerarm2.IsActive = false; world.AddBody(head); world.AddBody(torso); world.AddBody(arm1); world.AddBody(arm2); world.AddBody(lowerarm1); world.AddBody(lowerarm2); world.AddBody(leg1); world.AddBody(leg2); world.AddBody(lowerleg1); world.AddBody(lowerleg2); arm1Hinge.Activate(); arm2Hinge.Activate(); leg1Hinge.Activate(); leg2Hinge.Activate(); world.AddConstraint(headTorso); world.AddConstraint(arm1torso); world.AddConstraint(arm2torso); world.AddConstraint(leg1torso); world.AddConstraint(leg2torso); }
public void AttachToWorld(World world) { // Create rigid body this.RigidBody = new RigidBody(this.CollisionShape); this.RigidBody.IsStatic = false; this.RigidBody.Position = PhysicsUtils.XNAToJitterVector(this.Position); // Create constraints this.FixedAngleConstraint = new FixedAngle(this.RigidBody); this.ImpulseConstraint = new ImpulseConstraint(world, this.RigidBody); // Add constraints to world world.AddConstraint(this.FixedAngleConstraint); world.AddConstraint(this.ImpulseConstraint); // Add rigid body to world world.AddBody(this.RigidBody); }