static void Main(string[] args) { using (RagDollDemo game = new RagDollDemo()) { game.Run(); } }
public RagDoll (RagDollDemo ragDollDemo,DynamicsWorld ownerWorld, ref IndexedVector3 positionOffset,StreamWriter streamWriter) { m_ownerWorld = ownerWorld; m_ragDollDemo = ragDollDemo; // Setup the geometry m_shapes[(int)BODYPART.PELVIS] = new CapsuleShape(0.15f, 0.20f); m_shapes[(int)BODYPART.SPINE] = new CapsuleShape(0.15f, 0.28f); m_shapes[(int)BODYPART.HEAD] = new CapsuleShape(0.10f, 0.05f); m_shapes[(int)BODYPART.LEFT_UPPER_LEG] = new CapsuleShape(0.07f, 0.45f); m_shapes[(int)BODYPART.LEFT_LOWER_LEG] = new CapsuleShape(0.05f, 0.37f); m_shapes[(int)BODYPART.RIGHT_UPPER_LEG] = new CapsuleShape(0.07f, 0.45f); m_shapes[(int)BODYPART.RIGHT_LOWER_LEG] = new CapsuleShape(0.05f, 0.37f); m_shapes[(int)BODYPART.LEFT_UPPER_ARM] = new CapsuleShape(0.05f, 0.33f); m_shapes[(int)BODYPART.LEFT_LOWER_ARM] = new CapsuleShape(0.04f, 0.25f); m_shapes[(int)BODYPART.RIGHT_UPPER_ARM] = new CapsuleShape(0.05f, 0.33f); m_shapes[(int)BODYPART.RIGHT_LOWER_ARM] = new CapsuleShape(0.04f, 0.25f); // Setup all the rigid bodies IndexedMatrix offset = IndexedMatrix.CreateTranslation(positionOffset); IndexedMatrix transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,1,0)); IndexedMatrix adjusted = offset*transform; m_bodies[(int)BODYPART.PELVIS] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.PELVIS],true); m_bodies[(int)BODYPART.PELVIS].SetUserPointer("PELVIS"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,1.2f,0)); adjusted = offset * transform; m_bodies[(int)BODYPART.SPINE] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.SPINE], true); m_bodies[(int)BODYPART.SPINE].SetUserPointer("SPINE"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0,1.6f,0)); adjusted = offset * transform; m_bodies[(int)BODYPART.HEAD] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.HEAD], true); m_bodies[(int)BODYPART.HEAD].SetUserPointer("HEAD"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(-0.18f, 0.65f, 0)); adjusted = offset * transform ; m_bodies[(int)BODYPART.LEFT_UPPER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_UPPER_LEG], true); m_bodies[(int)BODYPART.LEFT_UPPER_LEG].SetUserPointer("LEFTUPPERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(-0.18f, 0.2f, 0)); adjusted = offset *transform; m_bodies[(int)BODYPART.LEFT_LOWER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_LOWER_LEG], true); m_bodies[(int)BODYPART.LEFT_LOWER_LEG].SetUserPointer("LEFTLOWERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0.18f, 0.65f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_UPPER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_UPPER_LEG], true); m_bodies[(int)BODYPART.RIGHT_UPPER_LEG].SetUserPointer("RIGHTUPPERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0.18f, 0.2f, 0)); adjusted = offset*transform; m_bodies[(int)BODYPART.RIGHT_LOWER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_LOWER_LEG], true); m_bodies[(int)BODYPART.RIGHT_LOWER_LEG].SetUserPointer("RIGHTLOWERLEG"); transform = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(-0.35f, 1.45f, 0); adjusted = offset *transform; m_bodies[(int)BODYPART.LEFT_UPPER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_UPPER_ARM], true); m_bodies[(int)BODYPART.LEFT_UPPER_ARM].SetUserPointer("LEFTUPPERARM"); transform = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(-0.7f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.LEFT_LOWER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_LOWER_ARM], true); m_bodies[(int)BODYPART.LEFT_LOWER_ARM].SetUserPointer("LEFTLOWERARM"); transform = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(0.35f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_UPPER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_UPPER_ARM], true); m_bodies[(int)BODYPART.RIGHT_UPPER_ARM].SetUserPointer("RIGHTUPPERARM"); transform = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(0.7f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_LOWER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_LOWER_ARM], true); m_bodies[(int)BODYPART.RIGHT_LOWER_ARM].SetUserPointer("RIGHTLOWERARM"); // Setup some damping on the m_bodies for (int i = 0; i < (int)BODYPART.COUNT; ++i) { if (m_bodies[i] != null) { //m_bodies[i].SetDamping(0.05f, 0.85f); m_bodies[i].SetDamping(0.5f, 0.85f); m_bodies[i].SetDeactivationTime(0.8f); m_bodies[i].SetSleepingThresholds(1.6f, 2.5f); } } // Now setup the constraints HingeConstraint hingeC; ConeTwistConstraint coneC; IndexedMatrix localA = IndexedMatrix.Identity; IndexedMatrix localB = IndexedMatrix.Identity; localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.15f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.SPINE], ref localA, ref localB); hingeC.SetLimit(-MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.PELVIS_SPINE] = hingeC; m_joints[(int)JOINT.PELVIS_SPINE].m_debugName = "PELVIS_SPINE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.PELVIS_SPINE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localA._origin = new IndexedVector3(0.0f, 0.30f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.HEAD], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.SPINE_HEAD] = coneC; m_joints[(int)JOINT.SPINE_HEAD].m_debugName = "SPINE_HEAD"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.SPINE_HEAD], true); localA = IndexedMatrix.Identity; localB = IndexedMatrix.Identity; localA = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_QUARTER_PI * 5); localA._origin = new IndexedVector3(-0.18f, -0.10f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_QUARTER_PI * 5); localB._origin = new IndexedVector3(0.0f, 0.225f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.LEFT_UPPER_LEG], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, 0); m_joints[(int)JOINT.LEFT_HIP] = coneC; m_joints[(int)JOINT.LEFT_HIP].m_debugName = "LEFT_HIP"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_HIP], true); localA = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); localA._origin = new IndexedVector3(0.0f, -0.225f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, 0.185f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.LEFT_UPPER_LEG], m_bodies[(int)BODYPART.LEFT_LOWER_LEG], ref localA, ref localB); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.LEFT_KNEE] = hingeC; m_joints[(int)JOINT.LEFT_KNEE].m_debugName = "LEFT_KNEE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_KNEE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_QUARTER_PI); localA._origin = new IndexedVector3(0.18f, -0.10f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_QUARTER_PI); localB._origin = new IndexedVector3(0.0f, 0.225f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.RIGHT_UPPER_LEG], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, 0); m_joints[(int)JOINT.RIGHT_HIP] = coneC; m_joints[(int)JOINT.RIGHT_HIP].m_debugName = "RIGHT_HIP"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_HIP], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, -0.225f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, 0.185f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.RIGHT_UPPER_LEG], m_bodies[(int)BODYPART.RIGHT_LOWER_LEG], ref localA, ref localB); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.RIGHT_KNEE] = hingeC; m_joints[(int)JOINT.RIGHT_KNEE].m_debugName = "RIGHT_KNEE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_KNEE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_PI); localA._origin = new IndexedVector3(-0.2f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.18f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.LEFT_UPPER_ARM], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_HALF_PI, 0); coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_joints[(int)JOINT.LEFT_SHOULDER] = coneC; m_joints[(int)JOINT.LEFT_SHOULDER].m_debugName = "LEFT_SHOULDER"; m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_SHOULDER], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.18f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.LEFT_UPPER_ARM], m_bodies[(int)BODYPART.LEFT_LOWER_ARM], ref localA, ref localB); // hingeC.setLimit(-MathUtil.SIMD_HALF_PI), 0)); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.LEFT_ELBOW] = hingeC; m_joints[(int)JOINT.LEFT_ELBOW].m_debugName = "LEFT_ELBOW"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_ELBOW], true); localA = MathUtil.SetEulerZYX(0, 0, 0); localA._origin = new IndexedVector3(0.2f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.18f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.RIGHT_UPPER_ARM], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_HALF_PI, 0); m_joints[(int)JOINT.RIGHT_SHOULDER] = coneC; m_joints[(int)JOINT.RIGHT_SHOULDER].m_debugName = "RIGHT_SHOULDER"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_SHOULDER], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.18f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.RIGHT_UPPER_ARM], m_bodies[(int)BODYPART.RIGHT_LOWER_ARM], ref localA, ref localB); // hingeC.setLimit(-MathUtil.SIMD_HALF_PI), 0)); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.RIGHT_ELBOW] = hingeC; m_joints[(int)JOINT.RIGHT_ELBOW].m_debugName = "RIGHT_ELBOW"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_ELBOW], true); }
public RagDoll(RagDollDemo ragDollDemo, DynamicsWorld ownerWorld, ref IndexedVector3 positionOffset, StreamWriter streamWriter) { m_ownerWorld = ownerWorld; m_ragDollDemo = ragDollDemo; // Setup the geometry m_shapes[(int)BODYPART.PELVIS] = new CapsuleShape(0.15f, 0.20f); m_shapes[(int)BODYPART.SPINE] = new CapsuleShape(0.15f, 0.28f); m_shapes[(int)BODYPART.HEAD] = new CapsuleShape(0.10f, 0.05f); m_shapes[(int)BODYPART.LEFT_UPPER_LEG] = new CapsuleShape(0.07f, 0.45f); m_shapes[(int)BODYPART.LEFT_LOWER_LEG] = new CapsuleShape(0.05f, 0.37f); m_shapes[(int)BODYPART.RIGHT_UPPER_LEG] = new CapsuleShape(0.07f, 0.45f); m_shapes[(int)BODYPART.RIGHT_LOWER_LEG] = new CapsuleShape(0.05f, 0.37f); m_shapes[(int)BODYPART.LEFT_UPPER_ARM] = new CapsuleShape(0.05f, 0.33f); m_shapes[(int)BODYPART.LEFT_LOWER_ARM] = new CapsuleShape(0.04f, 0.25f); m_shapes[(int)BODYPART.RIGHT_UPPER_ARM] = new CapsuleShape(0.05f, 0.33f); m_shapes[(int)BODYPART.RIGHT_LOWER_ARM] = new CapsuleShape(0.04f, 0.25f); // Setup all the rigid bodies IndexedMatrix offset = IndexedMatrix.CreateTranslation(positionOffset); IndexedMatrix transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 1, 0)); IndexedMatrix adjusted = offset * transform; m_bodies[(int)BODYPART.PELVIS] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.PELVIS], true); m_bodies[(int)BODYPART.PELVIS].SetUserPointer("PELVIS"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 1.2f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.SPINE] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.SPINE], true); m_bodies[(int)BODYPART.SPINE].SetUserPointer("SPINE"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0, 1.6f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.HEAD] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.HEAD], true); m_bodies[(int)BODYPART.HEAD].SetUserPointer("HEAD"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(-0.18f, 0.65f, 0)); adjusted = offset * transform ; m_bodies[(int)BODYPART.LEFT_UPPER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_UPPER_LEG], true); m_bodies[(int)BODYPART.LEFT_UPPER_LEG].SetUserPointer("LEFTUPPERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(-0.18f, 0.2f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.LEFT_LOWER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_LOWER_LEG], true); m_bodies[(int)BODYPART.LEFT_LOWER_LEG].SetUserPointer("LEFTLOWERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0.18f, 0.65f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_UPPER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_UPPER_LEG], true); m_bodies[(int)BODYPART.RIGHT_UPPER_LEG].SetUserPointer("RIGHTUPPERLEG"); transform = IndexedMatrix.CreateTranslation(new IndexedVector3(0.18f, 0.2f, 0)); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_LOWER_LEG] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_LOWER_LEG], true); m_bodies[(int)BODYPART.RIGHT_LOWER_LEG].SetUserPointer("RIGHTLOWERLEG"); transform = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(-0.35f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.LEFT_UPPER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_UPPER_ARM], true); m_bodies[(int)BODYPART.LEFT_UPPER_ARM].SetUserPointer("LEFTUPPERARM"); transform = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(-0.7f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.LEFT_LOWER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.LEFT_LOWER_ARM], true); m_bodies[(int)BODYPART.LEFT_LOWER_ARM].SetUserPointer("LEFTLOWERARM"); transform = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(0.35f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_UPPER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_UPPER_ARM], true); m_bodies[(int)BODYPART.RIGHT_UPPER_ARM].SetUserPointer("RIGHTUPPERARM"); transform = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_HALF_PI); transform._origin = new IndexedVector3(0.7f, 1.45f, 0); adjusted = offset * transform; m_bodies[(int)BODYPART.RIGHT_LOWER_ARM] = m_ragDollDemo.LocalCreateRigidBody(1f, adjusted, m_shapes[(int)BODYPART.RIGHT_LOWER_ARM], true); m_bodies[(int)BODYPART.RIGHT_LOWER_ARM].SetUserPointer("RIGHTLOWERARM"); // Setup some damping on the m_bodies for (int i = 0; i < (int)BODYPART.COUNT; ++i) { if (m_bodies[i] != null) { //m_bodies[i].SetDamping(0.05f, 0.85f); m_bodies[i].SetDamping(0.5f, 0.85f); m_bodies[i].SetDeactivationTime(0.8f); m_bodies[i].SetSleepingThresholds(1.6f, 2.5f); } } // Now setup the constraints HingeConstraint hingeC; ConeTwistConstraint coneC; IndexedMatrix localA = IndexedMatrix.Identity; IndexedMatrix localB = IndexedMatrix.Identity; localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.15f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.SPINE], ref localA, ref localB); hingeC.SetLimit(-MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.PELVIS_SPINE] = hingeC; m_joints[(int)JOINT.PELVIS_SPINE].m_debugName = "PELVIS_SPINE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.PELVIS_SPINE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localA._origin = new IndexedVector3(0.0f, 0.30f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.HEAD], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.SPINE_HEAD] = coneC; m_joints[(int)JOINT.SPINE_HEAD].m_debugName = "SPINE_HEAD"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.SPINE_HEAD], true); localA = IndexedMatrix.Identity; localB = IndexedMatrix.Identity; localA = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_QUARTER_PI * 5); localA._origin = new IndexedVector3(-0.18f, -0.10f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, -MathUtil.SIMD_QUARTER_PI * 5); localB._origin = new IndexedVector3(0.0f, 0.225f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.LEFT_UPPER_LEG], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, 0); m_joints[(int)JOINT.LEFT_HIP] = coneC; m_joints[(int)JOINT.LEFT_HIP].m_debugName = "LEFT_HIP"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_HIP], true); localA = MathUtil.SetEulerZYX(0f, MathUtil.SIMD_HALF_PI, 0f); localA._origin = new IndexedVector3(0.0f, -0.225f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, 0.185f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.LEFT_UPPER_LEG], m_bodies[(int)BODYPART.LEFT_LOWER_LEG], ref localA, ref localB); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.LEFT_KNEE] = hingeC; m_joints[(int)JOINT.LEFT_KNEE].m_debugName = "LEFT_KNEE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_KNEE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_QUARTER_PI); localA._origin = new IndexedVector3(0.18f, -0.10f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_QUARTER_PI); localB._origin = new IndexedVector3(0.0f, 0.225f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.PELVIS], m_bodies[(int)BODYPART.RIGHT_UPPER_LEG], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_QUARTER_PI, MathUtil.SIMD_QUARTER_PI, 0); m_joints[(int)JOINT.RIGHT_HIP] = coneC; m_joints[(int)JOINT.RIGHT_HIP].m_debugName = "RIGHT_HIP"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_HIP], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, -0.225f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, 0.185f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.RIGHT_UPPER_LEG], m_bodies[(int)BODYPART.RIGHT_LOWER_LEG], ref localA, ref localB); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.RIGHT_KNEE] = hingeC; m_joints[(int)JOINT.RIGHT_KNEE].m_debugName = "RIGHT_KNEE"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_KNEE], true); localA = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_PI); localA._origin = new IndexedVector3(-0.2f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.18f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.LEFT_UPPER_ARM], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_HALF_PI, 0); coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_joints[(int)JOINT.LEFT_SHOULDER] = coneC; m_joints[(int)JOINT.LEFT_SHOULDER].m_debugName = "LEFT_SHOULDER"; m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_SHOULDER], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.18f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.LEFT_UPPER_ARM], m_bodies[(int)BODYPART.LEFT_LOWER_ARM], ref localA, ref localB); // hingeC.setLimit(-MathUtil.SIMD_HALF_PI), 0)); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.LEFT_ELBOW] = hingeC; m_joints[(int)JOINT.LEFT_ELBOW].m_debugName = "LEFT_ELBOW"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.LEFT_ELBOW], true); localA = MathUtil.SetEulerZYX(0, 0, 0); localA._origin = new IndexedVector3(0.2f, 0.15f, 0.0f); localB = MathUtil.SetEulerZYX(0, 0, MathUtil.SIMD_HALF_PI); localB._origin = new IndexedVector3(0.0f, -0.18f, 0.0f); coneC = new ConeTwistConstraint(m_bodies[(int)BODYPART.SPINE], m_bodies[(int)BODYPART.RIGHT_UPPER_ARM], ref localA, ref localB); coneC.SetLimit(MathUtil.SIMD_HALF_PI, MathUtil.SIMD_HALF_PI, 0); m_joints[(int)JOINT.RIGHT_SHOULDER] = coneC; m_joints[(int)JOINT.RIGHT_SHOULDER].m_debugName = "RIGHT_SHOULDER"; coneC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_SHOULDER], true); localA = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localA._origin = new IndexedVector3(0.0f, 0.18f, 0.0f); localB = MathUtil.SetEulerZYX(0, MathUtil.SIMD_HALF_PI, 0); localB._origin = new IndexedVector3(0.0f, -0.14f, 0.0f); hingeC = new HingeConstraint(m_bodies[(int)BODYPART.RIGHT_UPPER_ARM], m_bodies[(int)BODYPART.RIGHT_LOWER_ARM], ref localA, ref localB); // hingeC.setLimit(-MathUtil.SIMD_HALF_PI), 0)); hingeC.SetLimit(0, MathUtil.SIMD_HALF_PI); m_joints[(int)JOINT.RIGHT_ELBOW] = hingeC; m_joints[(int)JOINT.RIGHT_ELBOW].m_debugName = "RIGHT_ELBOW"; hingeC.SetDbgDrawSize(CONSTRAINT_DEBUG_SIZE); m_ownerWorld.AddConstraint(m_joints[(int)JOINT.RIGHT_ELBOW], true); }