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