}
private void buildLimbConstraints() {
Vector3f tmp = new Vector3f();
///////////////////////////// SETTING THE CONSTRAINTS /////////////////////////////////////////////7777
// Now setup the constraints
Generic6DofConstraint joint6DOF;
Transform localA = new Transform(), localB = new Transform();
boolean useLinearReferenceFrameA = true;
/// ******* SPINE HEAD ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, -0.30f * this.buildScale, 0f);
localB.origin.set(0f, 0.14f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_SPINE.ordinal()],
bodies[BodyPart.BODYPART_HEAD.ordinal()], localA, localB,
useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_PI * 0.2f, -BulletGlobals.FLT_EPSILON,
-BulletGlobals.SIMD_PI * 0.1f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.1f, BulletGlobals.FLT_EPSILON,
BulletGlobals.SIMD_PI * 0.10f);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_SPINE_HEAD.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_SPINE_HEAD.ordinal()], true);
}
/// *************************** ///
/// ******* SPINE 2D ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0f, 0f);
localB.origin.set(0f, 0f, 0f);
CollisionShape ZeroShape = null;
GLOBAL.jBullet.ZeroBody = new RigidBody(0.0f, null, ZeroShape);
Transform Rotation = new Transform();
Rotation.setIdentity();
GLOBAL.jBullet.ZeroBody.setWorldTransform(Rotation);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_SPINE.ordinal()],
GLOBAL.jBullet.ZeroBody, localA, localB, false);
joint6DOF.setLimit(0, 1, 0); // Disable X axis limits
joint6DOF.setLimit(1, 1, 0); // Disable Y axis limits
joint6DOF.setLimit(2, 0, 0); // Set the Z axis to always be equal to zero
joint6DOF.setLimit(3, 0, 0); // Disable X rotational axes
joint6DOF.setLimit(4, 0, 0); // Disable Y rotational axes
joint6DOF.setLimit(5, 1, 0); // Uncap the rotational axes
//#endif
joints[JointType.JOINT_PLANE.ordinal()] = joint6DOF;
ownerWorld.addConstraint(joints[JointType.JOINT_PLANE.ordinal()],
true);
}
/// *************************** ///
if (hasArms) {
/// ******* LEFT SHOULDER ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0.15f * -this.buildScale,
0.2f * this.buildScale);
MatrixUtil.setEulerZYX(localB.basis,
BulletGlobals.SIMD_HALF_PI, 0,
-BulletGlobals.SIMD_HALF_PI);
localB.origin.set(0f, 0.18f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_SPINE.ordinal()],
bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()],
localA, localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_PI * 0.8f,
-BulletGlobals.FLT_EPSILON,
-BulletGlobals.SIMD_PI * 0.5f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.8f,
BulletGlobals.FLT_EPSILON, BulletGlobals.SIMD_PI * 0.5f);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_LEFT_SHOULDER.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_LEFT_SHOULDER.ordinal()], true);
}
/// *************************** ///
/// ******* RIGHT SHOULDER ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0.15f * -this.buildScale, -0.2f
* this.buildScale);
MatrixUtil.setEulerZYX(localB.basis, 0, 0,
BulletGlobals.SIMD_HALF_PI);
localB.origin.set(0f, 0.18f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_SPINE.ordinal()],
bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()],
localA, localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_PI * 0.8f,
-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_PI * 0.5f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.8f,
BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_PI * 0.5f);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_RIGHT_SHOULDER.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_RIGHT_SHOULDER.ordinal()], true);
}
/// *************************** ///
/// ******* LEFT ELBOW ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, -0.18f * this.buildScale, 0f);
localB.origin.set(0f, -0.14f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()],
bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()],
localA, localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.7f,
BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_LEFT_ELBOW.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_LEFT_ELBOW.ordinal()], true);
}
/// *************************** ///
/// ******* RIGHT ELBOW ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, -0.18f * this.buildScale, 0f);
localB.origin.set(0f, -0.14f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()],
bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()],
localA, localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.7f,
BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_RIGHT_ELBOW.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_RIGHT_ELBOW.ordinal()], true);
}
/// *************************** ///
}
/// ******* PELVIS ******** ///
{
localA.setIdentity();
localB.setIdentity();
MatrixUtil.setEulerZYX(localA.basis, 0, BulletGlobals.SIMD_HALF_PI,
0);
localA.origin.set(0f, -0.15f * this.buildScale, 0f);
MatrixUtil.setEulerZYX(localB.basis, 0, BulletGlobals.SIMD_HALF_PI,
0);
localB.origin.set(0f, 0.15f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_PELVIS.ordinal()],
bodies[BodyPart.BODYPART_SPINE.ordinal()], localA, localB,
useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_PI * 0.1f, -BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_PI * 0.1f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_PI * 0.2f, BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_PI * 0.15f);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_PELVIS_SPINE.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_PELVIS_SPINE.ordinal()], true);
}
/// *************************** ///
/// ******* LEFT HIP ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0.10f * this.buildScale,
0.08f * this.buildScale);
localB.origin.set(0f, -0.225f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_PELVIS.ordinal()],
bodies[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()], localA,
localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_HALF_PI * 0.5f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_HALF_PI * 0.6f,
BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_HALF_PI * 1.3f); //bend foward
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_LEFT_HIP.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_LEFT_HIP.ordinal()], true);
}
/// *************************** ///
/// ******* RIGHT HIP ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0.10f * this.buildScale, -0.08f
* this.buildScale);
localB.origin.set(0f, -0.225f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_PELVIS.ordinal()],
bodies[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()],
localA, localB, useLinearReferenceFrameA);
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_HALF_PI * 0.6f,
-BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_HALF_PI * 0.5f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_HALF_PI * 1.3f);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_RIGHT_HIP.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_RIGHT_HIP.ordinal()], true);
}
/// *************************** ///
/// ******* LEFT KNEE ******** ///
{
localA.setIdentity();
localB.setIdentity();
localA.origin.set(0f, 0.265f * this.buildScale, 0f);
localB.origin.set(0f, -0.225f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()],
bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()], localA,
localB, useLinearReferenceFrameA);
//
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_PI * .9f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_LEFT_KNEE.ordinal()] = joint6DOF;
ownerWorld.addConstraint(
joints[JointType.JOINT_LEFT_KNEE.ordinal()], true);
}
/// *************************** ///
/// ******* RIGHT KNEE ******** ///
{
localA.setIdentity();
localB.setIdentity();
HingeConstraint jointHinge = null;
localA.origin.set(0f, 0.265f * this.buildScale, 0f);
localB.origin.set(0f, -0.225f * this.buildScale, 0f);
joint6DOF = new Generic6DofConstraint(
bodies[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()],
bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()],
localA, localB, useLinearReferenceFrameA);
//
//#ifdef RIGID
//joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
//joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
//#else
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON,
-BulletGlobals.SIMD_PI * .9f);
joint6DOF.setAngularLowerLimit(tmp);
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON,
BulletGlobals.SIMD_EPSILON);
joint6DOF.setAngularUpperLimit(tmp);
//#endif
joints[JointType.JOINT_RIGHT_KNEE.ordinal()] = joint6DOF;
ownerWorld.addConstraint(