PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. using Delta.PhysicsEngines.VisualShapes;
  2. using Delta.Utilities.Datatypes;
  3. namespace Delta.PhysicsEngines.Tests3D
  4. {
  5. /// <summary>
  6. /// Class that handles easily ragdoll setup into engine.
  7. /// </summary>
  8. public class Ragdoll
  9. {
  10. #region Private
  11. #region torso (Private)
  12. private readonly VisualPhysicsBox torso;
  13. #endregion
  14. #region head (Private)
  15. private readonly VisualPhysicsSphere head;
  16. #endregion
  17. #region arm1 (Private)
  18. private readonly VisualPhysicsCapsule arm1;
  19. #endregion
  20. #region arm2 (Private)
  21. private readonly VisualPhysicsCapsule arm2;
  22. #endregion
  23. #region lowerarm1 (Private)
  24. private readonly VisualPhysicsCapsule lowerarm1;
  25. #endregion
  26. #region lowerarm2 (Private)
  27. private readonly VisualPhysicsCapsule lowerarm2;
  28. #endregion
  29. #region leg1 (Private)
  30. private readonly VisualPhysicsCapsule leg1;
  31. #endregion
  32. #region leg2 (Private)
  33. private readonly VisualPhysicsCapsule leg2;
  34. #endregion
  35. #region lowerleg1 (Private)
  36. private readonly VisualPhysicsCapsule lowerleg1;
  37. #endregion
  38. #region lowerleg2 (Private)
  39. private readonly VisualPhysicsCapsule lowerleg2;
  40. #endregion
  41. #region headTorso (Private)
  42. private PhysicsJoint headTorso;
  43. #endregion
  44. #region arm1torso (Private)
  45. private PhysicsJoint arm1torso;
  46. #endregion
  47. #region arm2torso (Private)
  48. private PhysicsJoint arm2torso;
  49. #endregion
  50. #region arm1Hinge (Private)
  51. private PhysicsJoint arm1Hinge;
  52. #endregion
  53. #region arm2Hinge (Private)
  54. private PhysicsJoint arm2Hinge;
  55. #endregion
  56. #region leg1torso (Private)
  57. private PhysicsJoint leg1torso;
  58. #endregion
  59. #region leg2torso (Private)
  60. private PhysicsJoint leg2torso;
  61. #endregion
  62. #region leg1Hinge (Private)
  63. private PhysicsJoint leg1Hinge;
  64. #endregion
  65. #region leg2Hinge (Private)
  66. private PhysicsJoint leg2Hinge;
  67. #endregion
  68. #endregion
  69. #region Constructors
  70. public Ragdoll(Vector position)
  71. {
  72. torso = new VisualPhysicsBox(position, 1.5f, 3.0f, 0.5f);
  73. head = new VisualPhysicsSphere(position + new Vector(0, 0, 2.1f), 0.5f);
  74. //head.IsStatic = true;
  75. // connect head and torso
  76. headTorso = Physics.CreatePointPointDistance(
  77. head.Body,
  78. torso.Body,
  79. position + new Vector(0, 0, 1.6f),
  80. position + new Vector(0, 0, 1.5f));
  81. arm1 = new VisualPhysicsCapsule(position + new Vector(1.0f, 0, 0.75f), 0.8f,
  82. 0.2f);
  83. arm2 = new VisualPhysicsCapsule(position + new Vector(-1.0f, 0, 0.75f), 0.8f,
  84. 0.2f);
  85. lowerarm1 = new VisualPhysicsCapsule(position + new Vector(1.0f, 0, -0.45f),
  86. 0.6f, 0.2f);
  87. lowerarm2 = new VisualPhysicsCapsule(
  88. position + new Vector(-1.0f, 0, -0.45f), 0.6f, 0.2f);
  89. arm1torso = Physics.CreatePointOnPoint(arm1.Body, torso.Body,
  90. position + new Vector(0.9f, 0, 1.4f));
  91. arm2torso = Physics.CreatePointOnPoint(arm2.Body, torso.Body,
  92. position + new Vector(-0.9f, 0, 1.4f));
  93. arm1Hinge = Physics.CreateHinge(
  94. arm1.Body,
  95. lowerarm1.Body,
  96. position + new Vector(1.0f, 0, 0.05f),
  97. new Vector(-1.0f, 0, 0));
  98. arm2Hinge = Physics.CreateHinge(
  99. arm2.Body,
  100. lowerarm2.Body,
  101. position + new Vector(-1.0f, 0, 0.05f),
  102. new Vector(-1.0f, 0, 0));
  103. leg1 = new VisualPhysicsCapsule(position + new Vector(-0.5f, 0, -2.4f), 1.0f,
  104. 0.3f);
  105. leg2 = new VisualPhysicsCapsule(position + new Vector(0.5f, 0, -2.4f), 1.0f,
  106. 0.3f);
  107. leg1torso = Physics.CreatePointOnPoint(leg1.Body, torso.Body,
  108. position + new Vector(-0.5f, 0, -1.6f));
  109. leg2torso = Physics.CreatePointOnPoint(leg2.Body, torso.Body,
  110. position + new Vector(+0.5f, 0, -1.6f));
  111. lowerleg1 = new VisualPhysicsCapsule(position + new Vector(-0.5f, 0, -4.0f),
  112. 0.8f, 0.3f);
  113. lowerleg2 = new VisualPhysicsCapsule(position + new Vector(+0.5f, 0, -4.0f),
  114. 0.8f, 0.3f);
  115. leg1Hinge = Physics.CreateHinge(
  116. leg1.Body, lowerleg1.Body,
  117. position + new Vector(-0.5f, 0, -3.35f),
  118. new Vector(-1.0f, 0, 0));
  119. leg2Hinge = Physics.CreateHinge(
  120. leg2.Body, lowerleg2.Body,
  121. position + new Vector(0.5f, 0, -3.35f),
  122. new Vector(-1.0f, 0, 0));
  123. Activate(false);
  124. }
  125. #endregion
  126. #region Activate (Public)
  127. public void Activate(bool active)
  128. {
  129. lowerleg1.IsActive = active;
  130. lowerleg2.IsActive = active;
  131. leg1.IsActive = active;
  132. leg2.IsActive = active;
  133. head.IsActive = active;
  134. torso.IsActive = active;
  135. arm1.IsActive = active;
  136. arm2.IsActive = active;
  137. lowerarm1.IsActive = active;
  138. lowerarm2.IsActive = active;
  139. }
  140. #endregion
  141. #region Draw (Public)
  142. public void Draw()
  143. {
  144. torso.Draw();
  145. head.Draw();
  146. arm1.Draw();
  147. arm2.Draw();
  148. lowerarm1.Draw();
  149. lowerarm2.Draw();
  150. leg1.Draw();
  151. leg2.Draw();
  152. lowerleg1.Draw();
  153. lowerleg2.Draw();
  154. }
  155. #endregion
  156. }
  157. }