/*
|
* Java port of Bullet (c) 2008 Martin Dvorak <jezek2@advel.cz>
|
*
|
* Bullet Continuous Collision Detection and Physics Library
|
* Ragdoll Demo
|
* Copyright (c) 2007 Starbreeze Studios
|
*
|
* This software is provided 'as-is', without any express or implied warranty.
|
* In no event will the authors be held liable for any damages arising from
|
* the use of this software.
|
*
|
* Permission is granted to anyone to use this software for any purpose,
|
* including commercial applications, and to alter it and redistribute it
|
* freely, subject to the following restrictions:
|
*
|
* 1. The origin of this software must not be misrepresented; you must not
|
* claim that you wrote the original software. If you use this software
|
* in a product, an acknowledgment in the product documentation would be
|
* appreciated but is not required.
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
* misrepresented as being the original software.
|
* 3. This notice may not be removed or altered from any source distribution.
|
*
|
* Written by: Marten Svanfeldt
|
*/
|
|
//package com.bulletphysics.demos.genericjoint;
|
|
import aurelienribon.tweenengine.*;
|
import aurelienribon.tweenengine.equations.*;
|
|
import com.bulletphysics.BulletGlobals;
|
import com.bulletphysics.collision.shapes.*;
|
import com.bulletphysics.collision.shapes.CollisionShape;
|
import com.bulletphysics.dynamics.DynamicsWorld;
|
import com.bulletphysics.dynamics.RigidBody;
|
import com.bulletphysics.dynamics.RigidBodyConstructionInfo;
|
import com.bulletphysics.dynamics.constraintsolver.Generic6DofConstraint;
|
import com.bulletphysics.dynamics.constraintsolver.TypedConstraint;
|
import com.bulletphysics.linearmath.DefaultMotionState;
|
import com.bulletphysics.linearmath.MatrixUtil;
|
import com.bulletphysics.linearmath.Transform;
|
import javax.vecmath.Vector3f;
|
|
import com.bulletphysics.linearmath.MotionState;
|
|
/**
|
*
|
* @author jezek2
|
*/
|
public class RagDoll implements java.io.Serializable
|
{
|
static final long serialVersionUID = 7352595618624832151L;
|
|
//protected final BulletStack stack = BulletStack.get();
|
|
// class RigidBodySerial extends RigidBody implements java.io.Serializable
|
// {
|
// public RigidBodySerial(RigidBodyConstructionInfo constructionInfo)
|
// {
|
// super(constructionInfo);
|
// }
|
//
|
// public RigidBodySerial(float mass, MotionState motionState, CollisionShape collisionShape)
|
// {
|
// super(mass, motionState, collisionShape);
|
// }
|
//
|
// public RigidBodySerial(float mass, MotionState motionState, CollisionShape collisionShape, Vector3f localInertia)
|
// {
|
// super(mass, motionState, collisionShape, localInertia);
|
// }
|
// }
|
|
boolean walkmotion = false;
|
|
public enum BodyPart {
|
BODYPART_PELVIS,
|
BODYPART_SPINE,
|
BODYPART_HEAD,
|
|
BODYPART_LEFT_UPPER_LEG,
|
BODYPART_LEFT_LOWER_LEG,
|
BODYPART_LEFT_FOOT,
|
|
BODYPART_RIGHT_UPPER_LEG,
|
BODYPART_RIGHT_LOWER_LEG,
|
BODYPART_RIGHT_FOOT,
|
|
BODYPART_LEFT_UPPER_ARM,
|
BODYPART_LEFT_LOWER_ARM,
|
BODYPART_LEFT_HAND,
|
|
BODYPART_RIGHT_UPPER_ARM,
|
BODYPART_RIGHT_LOWER_ARM,
|
BODYPART_RIGHT_HAND,
|
|
//BODYPART_GROUND,
|
|
BODYPART_COUNT;
|
}
|
|
public enum JointType {
|
JOINT_PELVIS_SPINE,
|
JOINT_SPINE_HEAD,
|
|
JOINT_LEFT_HIP,
|
JOINT_LEFT_KNEE,
|
JOINT_LEFT_ANKLE,
|
|
JOINT_RIGHT_HIP,
|
JOINT_RIGHT_KNEE,
|
JOINT_RIGHT_ANKLE,
|
|
JOINT_LEFT_SHOULDER,
|
JOINT_LEFT_ELBOW,
|
JOINT_LEFT_WRIST,
|
|
JOINT_RIGHT_SHOULDER,
|
JOINT_RIGHT_ELBOW,
|
JOINT_RIGHT_WRIST,
|
|
JOINT_COUNT
|
}
|
|
//DynamicsWorld ownerWorld;
|
CollisionShape[] shapes = new CollisionShape[BodyPart.BODYPART_COUNT.ordinal()];
|
RigidBody/*Serial*/[] bodies = new RigidBody/*Serial*/[BodyPart.BODYPART_COUNT.ordinal()];
|
TypedConstraint[] joints = new TypedConstraint[JointType.JOINT_COUNT.ordinal()];
|
|
public RagDoll(DynamicsWorld ownerWorld, Vector3f positionOffset)
|
{
|
this(ownerWorld, positionOffset, 1.0f, false);
|
}
|
|
public RagDoll(DynamicsWorld ownerWorld, Vector3f positionOffset, float scale_ragdoll, boolean walk)
|
{
|
init(/*ownerWorld,*/ positionOffset, scale_ragdoll, walk);
|
}
|
|
public void init(/*DynamicsWorld ownerWorld,*/ Vector3f positionOffset, float scale_ragdoll, boolean walk)
|
{
|
this.walkmotion = walk;
|
|
boolean hasbodies = (bodies[BodyPart.BODYPART_SPINE.ordinal()] != null);
|
|
//this.ownerWorld = ownerWorld;
|
|
Transform tmpTrans = new Transform();
|
Vector3f tmp = new Vector3f();
|
|
boolean node = true;
|
|
// Setup the geometry
|
//shapes[BodyPart.BODYPART_GROUND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.125f, scale_ragdoll * 0.20f);
|
//scale_ragdoll /= 1.25;
|
if (!hasbodies)
|
{
|
shapes[BodyPart.BODYPART_PELVIS.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.35f,false);
|
shapes[BodyPart.BODYPART_SPINE.ordinal()] = new CapsuleShape(scale_ragdoll * 0.2f, scale_ragdoll * 0.5f,false);
|
shapes[BodyPart.BODYPART_HEAD.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.15f,false);
|
|
shapes[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f, scale_ragdoll * 0.4f,false);
|
shapes[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.37f,node);
|
shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
|
|
shapes[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f, scale_ragdoll * 0.4f,false);
|
shapes[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.37f,node);
|
shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
|
|
shapes[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.08f, scale_ragdoll * 0.25f,node);
|
shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.2f,node);
|
shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
|
|
shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.08f, scale_ragdoll * 0.25f,node);
|
shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.2f,node);
|
shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
|
}
|
//scale_ragdoll *= 1.25;
|
|
// Setup all the rigid bodies
|
Transform offset = new Transform();
|
offset.setIdentity();
|
offset.origin.set(positionOffset);
|
|
Transform transform = new Transform();
|
|
float depth = -0.02f; // .02f;
|
|
// transform.setIdentity();
|
// transform.origin.set(0f, scale_ragdoll * 1f, 0f);
|
// tmpTrans.mul(offset, transform);
|
// bodies[BodyPart.BODYPART_GROUND.ordinal()] = localCreateRigidBody(1f, tmpTrans, shapes[BodyPart.BODYPART_GROUND.ordinal()]);
|
// bodies[BodyPart.BODYPART_GROUND.ordinal()].setGravity(new javax.vecmath.Vector3f());
|
|
RigidBody body;
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_SPINE.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_SPINE.ordinal()] = localCreateRigidBody(1f, 10, transform, shapes[BodyPart.BODYPART_SPINE.ordinal()]);
|
transform.origin.set(0f, scale_ragdoll * 1.2f, 0f);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
float massfeet = 1;
|
|
if (walkmotion)
|
massfeet = 0;
|
|
float poisefeet = 0;
|
|
if (walkmotion)
|
poisefeet = 10;
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()]);
|
transform.origin.set(-0.09f * scale_ragdoll, 0.275f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
//body.getMotionState().setStartTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()]);
|
transform.origin.set(0.09f * scale_ragdoll, 0.275f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
poisefeet = 0;
|
massfeet = 1;
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()]);
|
transform.origin.set(-0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.025f);
|
MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()]);
|
transform.origin.set(0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.025f);
|
MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_PELVIS.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_PELVIS.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_PELVIS.ordinal()]);
|
transform.origin.set(scale_ragdoll * 0.f, scale_ragdoll * 0.95f, 0f);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_HEAD.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_HEAD.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_HEAD.ordinal()]);
|
transform.origin.set(0f, scale_ragdoll * 1.55f, 0); // depth/2);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()]);
|
transform.origin.set(-0.09f * scale_ragdoll, 0.65f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()]);
|
transform.origin.set(0.09f * scale_ragdoll, 0.65f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()]);
|
transform.origin.set(-0.275f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()]);
|
transform.origin.set(-0.5f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()]);
|
transform.origin.set(-0.65f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()]);
|
transform.origin.set(0.275f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()]);
|
transform.origin.set(0.50f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
transform.setIdentity();
|
if ((body = bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()]) == null)
|
body = bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()]);
|
transform.origin.set(0.65f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
|
tmpTrans.mul(offset, transform);
|
body.worldTransform.set(tmpTrans);
|
body.getMotionState().setWorldTransform(tmpTrans);
|
((cRigidBody)body).anchor.set(tmpTrans.origin);
|
|
// Setup some damping on the m_bodies
|
for (int i = 0; i < BodyPart.BODYPART_COUNT.ordinal(); ++i)
|
{
|
bodies[i].setDamping(0,0); // 0.05f, 0.85f);
|
bodies[i].setDeactivationTime(0.8f);
|
bodies[i].setSleepingThresholds(0,0); // 1.6f, 2.5f);
|
bodies[i].setFriction(1); // .1f);
|
|
// fev 2014
|
bodies[i].setLinearVelocity(new Vector3f(0f, 0f, 0f));
|
bodies[i].setAngularVelocity(new Vector3f(0f, 0f, 0f));
|
}
|
|
|
// CollisionShape groundShape = new BoxShape(new Vector3f(200f, 10f, 200f));
|
// Transform groundTransform = new Transform();
|
// groundTransform.setIdentity();
|
// groundTransform.origin.set(0f, -10f, 0f);
|
// localCreateRigidBody(0f, groundTransform, groundShape);
|
|
///////////////////////////// SETTING THE CONSTRAINTS /////////////////////////////////////////////7777
|
// Now setup the constraints
|
Generic6DofConstraint joint6DOF;
|
Transform localA = new Transform(), localB = new Transform();
|
boolean useLinearReferenceFrameA = true;
|
boolean links = !hasbodies; // true;
|
boolean selfcollision = false;
|
/// ******* SPINE HEAD ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.25f * scale_ragdoll, depth/2);
|
|
localB.origin.set(0f, -0.1f * scale_ragdoll, depth/2);
|
|
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_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
tmp.set(-BulletGlobals.SIMD_PI * 0.1f, -BulletGlobals.FLT_EPSILON, -BulletGlobals.SIMD_PI * 0.1f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.1f, BulletGlobals.FLT_EPSILON, BulletGlobals.SIMD_PI * 0.1f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_SPINE_HEAD.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_SPINE_HEAD.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* LEFT SHOULDER ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(-0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth);
|
|
MatrixUtil.setEulerZYX(localB.basis, 0/*BulletGlobals.SIMD_HALF_PI*/, 0, -BulletGlobals.SIMD_HALF_PI);
|
localB.origin.set(0f, -0.125f * scale_ragdoll, 0);
|
|
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_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.FLT_EPSILON, -BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
//tmp.set(BulletGlobals.SIMD_PI * 0.5f, BulletGlobals.SIMD_PI * 0.5f, BulletGlobals.SIMD_PI * 0.5f); // , BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_LEFT_SHOULDER.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_LEFT_SHOULDER.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* RIGHT SHOULDER ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth);
|
MatrixUtil.setEulerZYX(localB.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
|
localB.origin.set(0f, -0.125f * scale_ragdoll, 0);
|
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_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
//tmp.set(-BulletGlobals.SIMD_PI * 0.0f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_PI * 0.0f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
//tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_EPSILON, 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()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* LEFT ELBOW ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.125f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.1f * scale_ragdoll, 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);
|
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON); // - 0.5f);
|
//tmp.set(BulletGlobals.SIMD_PI * 0.0f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_LEFT_ELBOW.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_LEFT_ELBOW.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* RIGHT ELBOW ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.125f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.1f * scale_ragdoll, 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); // + 0.5f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
//tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
|
joints[JointType.JOINT_RIGHT_ELBOW.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_RIGHT_ELBOW.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* LEFT WRIST ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.1f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.05f * scale_ragdoll, 0f);
|
joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_LEFT_HAND.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);
|
tmp.set(-BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
//tmp.set(BulletGlobals.SIMD_PI * 0.7f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_LEFT_WRIST.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_LEFT_WRIST.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* RIGHT WRIST ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.1f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.05f * scale_ragdoll, 0f);
|
joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_RIGHT_HAND.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_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_PI * 0.5f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
|
joints[JointType.JOINT_RIGHT_WRIST.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_RIGHT_WRIST.ordinal()], !selfcollision);
|
}
|
|
/// ******* PELVIS ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
//MatrixUtil.setEulerZYX(localA.basis, 0, BulletGlobals.SIMD_HALF_PI, 0);
|
localA.origin.set(0f, 0.075f * scale_ragdoll, 0f);
|
//MatrixUtil.setEulerZYX(localB.basis, 0, BulletGlobals.SIMD_HALF_PI, 0);
|
localB.origin.set(0f, -0.175f * scale_ragdoll, 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_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
tmp.set(-BulletGlobals.SIMD_PI * 0.02f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_PI * 0.03f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_PI * 0.02f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_PI * 0.06f);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_PELVIS_SPINE.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_PELVIS_SPINE.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* LEFT HIP ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(-0.09f * scale_ragdoll, -0.10f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(localB.basis, 0, 0, BulletGlobals.SIMD_PI);
|
localB.origin.set(-0.00f * scale_ragdoll, -0.20f * scale_ragdoll, 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_EPSILON);
|
tmp.set(-BulletGlobals.SIMD_HALF_PI * 0.5f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
//tmp.set(BulletGlobals.SIMD_HALF_PI * 0.8f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_HALF_PI * 0.6f);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_LEFT_HIP.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_LEFT_HIP.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
|
/// ******* RIGHT HIP ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0.09f * scale_ragdoll, -0.10f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(localB.basis, 0, 0, BulletGlobals.SIMD_PI);
|
localB.origin.set(0.00f * scale_ragdoll, -0.2f * scale_ragdoll, 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_EPSILON, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
//tmp.set(-BulletGlobals.SIMD_HALF_PI * 0.5f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_HALF_PI * 0.6f);
|
joint6DOF.setAngularLowerLimit(tmp);
|
tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
//tmp.set(BulletGlobals.SIMD_HALF_PI * 0.7f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_RIGHT_HIP.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_RIGHT_HIP.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
|
/// ******* LEFT KNEE ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.19f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.185f * scale_ragdoll, 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_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.02f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularLowerLimit(tmp);
|
//tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.7f, 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()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* RIGHT KNEE ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.19f * scale_ragdoll, 0f);
|
localB.origin.set(0f, -0.185f * scale_ragdoll, 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_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.02f, -BulletGlobals.SIMD_EPSILON, -BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularLowerLimit(tmp);
|
//tmp.set(BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.7f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_RIGHT_KNEE.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_RIGHT_KNEE.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* LEFT ANKLE ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.2f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(localB.basis, -BulletGlobals.SIMD_PI/2, 0,0); // BulletGlobals.SIMD_PI, 0);
|
localB.origin.set(0, -0.05f * scale_ragdoll, 0);
|
joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()], bodies[BodyPart.BODYPART_LEFT_FOOT.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_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.1f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_LEFT_ANKLE.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_LEFT_KNEE.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
/// ******* RIGHT ANKLE ******** ///
|
if (links)
|
{
|
localA.setIdentity();
|
localB.setIdentity();
|
|
localA.origin.set(0f, 0.2f * scale_ragdoll, 0f);
|
MatrixUtil.setEulerZYX(localB.basis, -BulletGlobals.SIMD_PI/2, 0,0); // BulletGlobals.SIMD_PI,0);
|
localB.origin.set(0f, -0.05f * scale_ragdoll, 0f);
|
joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()], bodies[BodyPart.BODYPART_RIGHT_FOOT.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_EPSILON, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
tmp.set(BulletGlobals.SIMD_PI * 0.1f, BulletGlobals.SIMD_EPSILON, BulletGlobals.SIMD_EPSILON);
|
joint6DOF.setAngularUpperLimit(tmp);
|
//#endif
|
joints[JointType.JOINT_RIGHT_ANKLE.ordinal()] = joint6DOF;
|
// ownerWorld.addConstraint(joints[JointType.JOINT_RIGHT_KNEE.ordinal()], !selfcollision);
|
}
|
/// *************************** ///
|
|
|
// Tween.to(thing, 0, 100)
|
// .target(0, 0, -50)
|
// .ease(Linear.INOUT)
|
// //.delay(1000)
|
// //.repeat(2, 200)
|
// .start(tweenManager);
|
// ObjEditor.tweenManager.killAll();
|
|
cRigidBody leftleg = (cRigidBody) bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()];
|
cRigidBody rightleg = (cRigidBody) bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()];
|
|
Timeline walkpath =
|
Timeline.createSequence()
|
.push(Tween.to(rightleg, 0, 0.1f).target(0,0,0.04f))
|
.push(Tween.to(leftleg, 0, 0.1f).target(0,0,0.04f))
|
.repeat(5, 0.0f)
|
;
|
|
Timeline.createSequence()
|
.push(Tween.to(leftleg, 0, 0.1f).target(0,0,0.02f))
|
.push(walkpath)
|
// .beginParallel()
|
// .push(Tween.to(leftleg, 1, 500).target(1).ease(Quad.INOUT))
|
// .push(Tween.to(leftleg, 1, 500).target(1, 1).ease(Quad.INOUT))
|
// .end()
|
// .pushPause(1000)
|
// .push(Tween.to(leftleg, 1, 500).target(100).ease(Quad.INOUT))
|
// .push(Tween.to(leftleg, 1, 500).target(360).ease(Quad.INOUT))
|
// .repeat(5, 1)
|
// .end()
|
.start(ObjEditor.tweenManager)
|
;
|
}
|
|
public void destroy0() {
|
int i;
|
|
// Remove all constraints
|
for (i = 0; i < JointType.JOINT_COUNT.ordinal(); ++i) {
|
// ownerWorld.removeConstraint(joints[i]);
|
//joints[i].destroy();
|
joints[i] = null;
|
}
|
|
// Remove all bodies and shapes
|
for (i = 0; i < BodyPart.BODYPART_COUNT.ordinal(); ++i) {
|
// ownerWorld.removeRigidBody(bodies[i]);
|
|
//bodies[i].getMotionState().destroy();
|
|
bodies[i].destroy();
|
bodies[i] = null;
|
|
//shapes[i].destroy();
|
shapes[i] = null;
|
}
|
}
|
|
int counter = 0;
|
|
void SetDynamics(DynamicsWorld d)
|
{
|
for (int i = 0; i < JointType.JOINT_COUNT.ordinal(); ++i)
|
d.addConstraint(joints[i], true);
|
|
for (int i = 0; i < BodyPart.BODYPART_COUNT.ordinal(); ++i)
|
d.addRigidBody(bodies[i]);
|
}
|
|
void ResetDynamics(DynamicsWorld d)
|
{
|
for (int i = 0; i < JointType.JOINT_COUNT.ordinal(); ++i)
|
d.removeConstraint(joints[i]);
|
|
for (int i = 0; i < BodyPart.BODYPART_COUNT.ordinal(); ++i)
|
d.removeRigidBody(bodies[i]);
|
}
|
|
/**/
|
private cRigidBody/*Serial*/ localCreateRigidBody(float mass, float poise, Transform startTransform, CollisionShape shape)
|
{
|
boolean isDynamic = (mass != 0f);
|
|
Vector3f localInertia = new Vector3f();
|
localInertia.set(0f, 0f, 0f);
|
if (isDynamic) {
|
shape.calculateLocalInertia(mass, localInertia);
|
}
|
|
DefaultMotionState myMotionState = new DefaultMotionState(startTransform);
|
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia);
|
rbInfo.additionalDamping = false; // true;
|
cRigidBody/*Serial*/ body = new cRigidBody/*Serial*/(rbInfo, poise);
|
|
body.setUserPointer(this);
|
|
//if (counter == 0)
|
// ownerWorld.addRigidBody(body);
|
|
return body;
|
}
|
|
/*static*/ int currentfoot = 2;
|
/*static*/ int tick = 7;
|
/*static*/ float walk = 1f / 60f;
|
|
// public enum AnchorMode
|
// {
|
// ANCHOR,
|
// ORIGIN
|
// }
|
|
class cRigidBody extends RigidBody implements java.io.Serializable, TweenAccessor<cRigidBody>
|
{
|
static final long serialVersionUID = -536751811975291098L;
|
|
/**
|
* Gets one or many values from the target object associated to the
|
* given tween type. It is used by the Tween Engine to determine starting
|
* values.
|
*
|
* @param target The target object of the tween.
|
* @param tweenType An integer representing the tween type.
|
* @param returnValues An array which should be modified by this method.
|
* @return The count of modified slots from the returnValues array.
|
*/
|
public int getValues(cRigidBody target, int tweenType, float[] returnValues)
|
{
|
switch (tweenType)
|
{
|
case 0 : // direct origin
|
{
|
returnValues[0] = 0; // worldTransform.origin.x;
|
returnValues[1] = 0; // worldTransform.origin.y;
|
returnValues[2] = 0; // worldTransform.origin.z;
|
}
|
break;
|
case 1 : // anchor
|
{
|
returnValues[0] = 0; // anchor.x;
|
returnValues[1] = 0; // anchor.y;
|
returnValues[2] = 0; // anchor.z;
|
}
|
break;
|
}
|
|
return 3;
|
}
|
|
/**
|
* This method is called by the Tween Engine each time a running tween
|
* associated with the current target object has been updated.
|
*
|
* @param target The target object of the tween.
|
* @param tweenType An integer representing the tween type.
|
* @param newValues The new values determined by the Tween Engine.
|
*/
|
public void setValues(cRigidBody target, int tweenType, float[] newValues)
|
{
|
switch (tweenType)
|
{
|
case 0 : // direct origin
|
{
|
worldTransform.origin.x += newValues[0];
|
worldTransform.origin.y += newValues[1];
|
worldTransform.origin.z += newValues[2];
|
}
|
break;
|
case 1 : // anchor
|
{
|
anchor.x += newValues[0];
|
anchor.y += newValues[1];
|
anchor.z += newValues[2];
|
}
|
break;
|
}
|
}
|
|
int index;
|
float poise;
|
Vector3f anchor = new Vector3f();
|
Vector3f tmp = new Vector3f();
|
Vector3f tmp2 = new Vector3f();
|
|
public cRigidBody(RigidBodyConstructionInfo constructionInfo, float poise)
|
{
|
super(constructionInfo);
|
|
this.poise = poise;
|
anchor.set(this.worldTransform.origin);
|
|
index = counter++;
|
|
if (index == currentfoot) // 1 || index == 2)
|
{
|
// feet
|
// anchor.y += 0.02;
|
}
|
}
|
|
public void applyGravity()
|
{
|
if (walkmotion || index == 0 || index == 5) // spine and pelvis only
|
super.applyGravity();
|
|
if (walkmotion && poise != 0)
|
{
|
//RagDoll rag = (RagDoll) getUserPointer();
|
|
RigidBody spine = /*rag.*/bodies[BodyPart.BODYPART_SPINE.ordinal()];
|
|
//tmp.set(0,0,0);
|
|
switch (index)
|
{
|
case 0: // SPINE
|
cRigidBody leftfoot = (cRigidBody) /*rag.*/bodies[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()];
|
cRigidBody rightfoot = (cRigidBody) /*rag.*/bodies[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()];
|
//cRigidBody leftfoot = (cRigidBody) rag.bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()];
|
//cRigidBody rightfoot = (cRigidBody) rag.bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()];
|
|
tick++;
|
|
if (false) // (tick & 15) == 0)
|
{
|
// if (currentfoot == 1)
|
// {
|
// float oldy = leftfoot.anchor.y;
|
// leftfoot.anchor.set(leftfoot.worldTransform.origin);
|
// leftfoot.anchor.y = oldy;
|
// }
|
// else
|
// {
|
// float oldy = rightfoot.anchor.y;
|
// rightfoot.anchor.set(rightfoot.worldTransform.origin);
|
// rightfoot.anchor.y = oldy;
|
// }
|
if (currentfoot == 1)
|
{
|
leftfoot.anchor.y -= 0.02;
|
}
|
else
|
{
|
rightfoot.anchor.y -= 0.02;
|
}
|
currentfoot %= 2;
|
currentfoot += 1;
|
if (currentfoot == 1)
|
{
|
leftfoot.anchor.y += 0.02;
|
}
|
else
|
{
|
rightfoot.anchor.y += 0.02;
|
}
|
}
|
|
tmp.set(leftfoot.//anchor);
|
worldTransform.origin);
|
tmp.add(rightfoot.//anchor);
|
worldTransform.origin);
|
tmp.scale(0.5f);
|
|
float oldy = anchor.y;
|
//tmp2.set(anchor);
|
anchor.set(tmp);
|
//anchor.z += walk/2;
|
anchor.y = oldy;
|
//tmp2.sub(anchor);
|
|
//leftfoot.anchor.add(tmp2);
|
//rightfoot.anchor.add(tmp2);
|
|
tmp.set(this.worldTransform.origin);
|
tmp.sub(anchor);
|
tmp.scale(-poise*300);
|
|
applyCentralForce(tmp); // equilibrium
|
break;
|
// case 1: // LFOOT
|
// {
|
// cRigidBody otherfoot = (cRigidBody) rag.bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()];
|
//
|
// tmp.set(spine.worldTransform.origin);
|
// tmp.sub(otherfoot.//anchor); //
|
// worldTransform.origin);
|
// tmp.y = 0;
|
//
|
// tmp2.set(spine.worldTransform.origin);
|
// tmp2.sub(this.//anchor); //
|
// worldTransform.origin);
|
// tmp2.y = 0;
|
//
|
// //if (tmp.dot(tmp) < tmp2.dot(tmp2))
|
// {
|
// tmp.set(spine.worldTransform.origin);
|
// tmp.scale(2);
|
// tmp.sub(otherfoot.worldTransform.origin);
|
//
|
// //otherfoot.anchor.set(otherfoot.worldTransform.origin);
|
//
|
// float oldy = anchor.y;
|
// anchor.set(tmp);
|
// anchor.y = oldy;
|
// }
|
// //else
|
// {
|
// tmp2.set(spine.worldTransform.origin);
|
// tmp2.scale(2);
|
// tmp2.sub(this.worldTransform.origin);
|
//
|
// //anchor.set(worldTransform.origin);
|
//
|
// float oldy = otherfoot.anchor.y;
|
// otherfoot.anchor.set(tmp2);
|
// otherfoot.anchor.y = oldy;
|
// }
|
//
|
// }
|
// break;
|
|
// case 2: // RFOOT
|
// {
|
// RigidBody otherfoot = rag.bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()];
|
//
|
// float oldy = anchor.y;
|
// tmp.set(spine.worldTransform.origin);
|
// tmp.scale(2);
|
// tmp.sub(otherfoot.worldTransform.origin);
|
// tmp2.set(spine.worldTransform.origin);
|
// tmp2.scale(2);
|
// tmp2.sub(this.worldTransform.origin);
|
//
|
// if (tmp.dot(tmp) < tmp2.dot(tmp2))
|
// anchor.set(tmp2);
|
//
|
// anchor.y = oldy;
|
// }
|
// break;
|
case 1:
|
case 2:
|
if (true)
|
break;
|
if (index == currentfoot)
|
{
|
// tmp.set(spine.worldTransform.origin);
|
// tmp.sub(worldTransform.origin);
|
// tmp.y = 0;
|
//
|
// if (tmp.dot(tmp) > 0.01)
|
// {
|
// currentfoot %= 2;
|
// currentfoot += 1;
|
// break;
|
// }
|
|
tmp.set(0,0,walk);
|
//spine.worldTransform.basis.transform(tmp);
|
tmp.y = 0;
|
anchor.add(tmp);
|
|
// tmp.set(this.worldTransform.origin);
|
// tmp.sub(anchor);
|
// tmp.scale(-poise*300);
|
//
|
// applyCentralForce(tmp); // equilibrium
|
}
|
else
|
{
|
// tmp.set(this.worldTransform.origin);
|
// tmp.sub(anchor);
|
// tmp.scale(-poise*300);
|
//
|
// applyCentralForce(tmp); // equilibrium
|
}
|
|
worldTransform.origin.set(anchor);
|
// double rnd = Math.random();
|
// double seuil = 0.1;
|
// if (rnd < seuil)
|
// anchor.z += rnd-seuil/2;
|
// else
|
// {
|
// anchor.x = spine.worldTransform.origin.x;
|
// anchor.z = spine.worldTransform.origin.z;
|
// }
|
//rnd = Math.random();
|
//if (rnd > 1-seuil)
|
// anchor.x += 1 - rnd - seuil/2;
|
break;
|
default:
|
tmp.set(this.worldTransform.origin);
|
tmp.sub(anchor);
|
tmp.scale(-poise*300);
|
|
applyCentralForce(tmp); // equilibrium
|
break;
|
}
|
}
|
}
|
}
|
/*
|
|
*/
|
}
|