/PhysicsEngines/Tests3D/Ragdoll.cs
C# | 197 lines | 152 code | 40 blank | 5 comment | 0 complexity | 19e2bef44501aadd0a957df46f910df2 MD5 | raw file
Possible License(s): Apache-2.0
- using Delta.PhysicsEngines.VisualShapes;
- using Delta.Utilities.Datatypes;
-
- namespace Delta.PhysicsEngines.Tests3D
- {
- /// <summary>
- /// Class that handles easily ragdoll setup into engine.
- /// </summary>
- public class Ragdoll
- {
- #region Private
-
- #region torso (Private)
- private readonly VisualPhysicsBox torso;
- #endregion
-
- #region head (Private)
- private readonly VisualPhysicsSphere head;
- #endregion
-
- #region arm1 (Private)
- private readonly VisualPhysicsCapsule arm1;
- #endregion
-
- #region arm2 (Private)
- private readonly VisualPhysicsCapsule arm2;
- #endregion
-
- #region lowerarm1 (Private)
- private readonly VisualPhysicsCapsule lowerarm1;
- #endregion
-
- #region lowerarm2 (Private)
- private readonly VisualPhysicsCapsule lowerarm2;
- #endregion
-
- #region leg1 (Private)
- private readonly VisualPhysicsCapsule leg1;
- #endregion
-
- #region leg2 (Private)
- private readonly VisualPhysicsCapsule leg2;
- #endregion
-
- #region lowerleg1 (Private)
- private readonly VisualPhysicsCapsule lowerleg1;
- #endregion
-
- #region lowerleg2 (Private)
- private readonly VisualPhysicsCapsule lowerleg2;
- #endregion
-
- #region headTorso (Private)
- private PhysicsJoint headTorso;
- #endregion
-
- #region arm1torso (Private)
- private PhysicsJoint arm1torso;
- #endregion
-
- #region arm2torso (Private)
- private PhysicsJoint arm2torso;
- #endregion
-
- #region arm1Hinge (Private)
- private PhysicsJoint arm1Hinge;
- #endregion
-
- #region arm2Hinge (Private)
- private PhysicsJoint arm2Hinge;
- #endregion
-
- #region leg1torso (Private)
- private PhysicsJoint leg1torso;
- #endregion
-
- #region leg2torso (Private)
- private PhysicsJoint leg2torso;
- #endregion
-
- #region leg1Hinge (Private)
- private PhysicsJoint leg1Hinge;
- #endregion
-
- #region leg2Hinge (Private)
- private PhysicsJoint leg2Hinge;
- #endregion
-
- #endregion
-
- #region Constructors
- public Ragdoll(Vector position)
- {
- torso = new VisualPhysicsBox(position, 1.5f, 3.0f, 0.5f);
-
- head = new VisualPhysicsSphere(position + new Vector(0, 0, 2.1f), 0.5f);
- //head.IsStatic = true;
-
- // connect head and torso
- headTorso = Physics.CreatePointPointDistance(
- head.Body,
- torso.Body,
- position + new Vector(0, 0, 1.6f),
- position + new Vector(0, 0, 1.5f));
-
- arm1 = new VisualPhysicsCapsule(position + new Vector(1.0f, 0, 0.75f), 0.8f,
- 0.2f);
- arm2 = new VisualPhysicsCapsule(position + new Vector(-1.0f, 0, 0.75f), 0.8f,
- 0.2f);
-
- lowerarm1 = new VisualPhysicsCapsule(position + new Vector(1.0f, 0, -0.45f),
- 0.6f, 0.2f);
- lowerarm2 = new VisualPhysicsCapsule(
- position + new Vector(-1.0f, 0, -0.45f), 0.6f, 0.2f);
-
- arm1torso = Physics.CreatePointOnPoint(arm1.Body, torso.Body,
- position + new Vector(0.9f, 0, 1.4f));
- arm2torso = Physics.CreatePointOnPoint(arm2.Body, torso.Body,
- position + new Vector(-0.9f, 0, 1.4f));
-
- arm1Hinge = Physics.CreateHinge(
- arm1.Body,
- lowerarm1.Body,
- position + new Vector(1.0f, 0, 0.05f),
- new Vector(-1.0f, 0, 0));
-
- arm2Hinge = Physics.CreateHinge(
- arm2.Body,
- lowerarm2.Body,
- position + new Vector(-1.0f, 0, 0.05f),
- new Vector(-1.0f, 0, 0));
-
- leg1 = new VisualPhysicsCapsule(position + new Vector(-0.5f, 0, -2.4f), 1.0f,
- 0.3f);
- leg2 = new VisualPhysicsCapsule(position + new Vector(0.5f, 0, -2.4f), 1.0f,
- 0.3f);
-
- leg1torso = Physics.CreatePointOnPoint(leg1.Body, torso.Body,
- position + new Vector(-0.5f, 0, -1.6f));
- leg2torso = Physics.CreatePointOnPoint(leg2.Body, torso.Body,
- position + new Vector(+0.5f, 0, -1.6f));
-
- lowerleg1 = new VisualPhysicsCapsule(position + new Vector(-0.5f, 0, -4.0f),
- 0.8f, 0.3f);
- lowerleg2 = new VisualPhysicsCapsule(position + new Vector(+0.5f, 0, -4.0f),
- 0.8f, 0.3f);
-
- leg1Hinge = Physics.CreateHinge(
- leg1.Body, lowerleg1.Body,
- position + new Vector(-0.5f, 0, -3.35f),
- new Vector(-1.0f, 0, 0));
-
- leg2Hinge = Physics.CreateHinge(
- leg2.Body, lowerleg2.Body,
- position + new Vector(0.5f, 0, -3.35f),
- new Vector(-1.0f, 0, 0));
-
- Activate(false);
- }
- #endregion
-
- #region Activate (Public)
- public void Activate(bool active)
- {
- lowerleg1.IsActive = active;
- lowerleg2.IsActive = active;
- leg1.IsActive = active;
- leg2.IsActive = active;
- head.IsActive = active;
- torso.IsActive = active;
- arm1.IsActive = active;
- arm2.IsActive = active;
- lowerarm1.IsActive = active;
- lowerarm2.IsActive = active;
- }
- #endregion
-
- #region Draw (Public)
- public void Draw()
- {
- torso.Draw();
- head.Draw();
-
- arm1.Draw();
- arm2.Draw();
- lowerarm1.Draw();
- lowerarm2.Draw();
-
- leg1.Draw();
- leg2.Draw();
-
- lowerleg1.Draw();
- lowerleg2.Draw();
- }
- #endregion
- }
- }