From 767be784dc7fe293bf5c5ee6507df242526be3ed Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 24 Sep 2019 02:10:06 -0400 Subject: [PATCH] Rag doll is back. --- RagDoll.java | 86 ++++++++++++++++++++++++------------------ 1 files changed, 49 insertions(+), 37 deletions(-) diff --git a/RagDoll.java b/RagDoll.java index a0d1819..7e67857 100644 --- a/RagDoll.java +++ b/RagDoll.java @@ -123,6 +123,8 @@ JOINT_COUNT } + float scale; + //DynamicsWorld ownerWorld; CollisionShape[] shapes = new CollisionShape[BodyPart.BODYPART_COUNT.ordinal()]; RigidBody/*Serial*/[] bodies = new RigidBody/*Serial*/[BodyPart.BODYPART_COUNT.ordinal()]; @@ -140,6 +142,8 @@ public void init(/*DynamicsWorld ownerWorld,*/ Vector3f positionOffset, float scale_ragdoll, boolean walk) { + scale = scale_ragdoll; + this.walkmotion = walk; boolean hasbodies = (bodies[BodyPart.BODYPART_SPINE.ordinal()] != null); @@ -149,32 +153,40 @@ Transform tmpTrans = new Transform(); Vector3f tmp = new Vector3f(); - boolean node = true; + boolean node = false; // true; + + // KIDS4 + float upperarmlength = 0.3f; // 0.25 + float lowerarmlength = 0.25f; // 0.2 + float handlength = 0.1f; // 0.1 + float upperarmdist = 0.15f; // 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); + float thin = 0.1f; + + 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_LEFT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.4f * thin, scale_ragdoll * 0.4f, node); + shapes[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.37f * thin, scale_ragdoll * 0.37f, node); + shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f * thin, 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_RIGHT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.4f * thin, scale_ragdoll * 0.4f, node); + shapes[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.37f * thin, scale_ragdoll * 0.37f, node); + shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f * thin, 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_LEFT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * upperarmlength * thin, scale_ragdoll * upperarmlength, node); + shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * lowerarmlength * thin, scale_ragdoll * lowerarmlength, node); + shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * handlength * thin, scale_ragdoll * handlength, 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); + shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * upperarmlength * thin, scale_ragdoll * upperarmlength, node); + shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * lowerarmlength * thin, scale_ragdoll * lowerarmlength, node); + shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * handlength * thin, scale_ragdoll * handlength, node); } //scale_ragdoll *= 1.25; @@ -185,7 +197,7 @@ Transform transform = new Transform(); - float depth = -0.02f; // .02f; + float depth = -0.01f; // .02f; // transform.setIdentity(); // transform.origin.set(0f, scale_ragdoll * 1f, 0f); @@ -242,7 +254,7 @@ 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); + transform.origin.set(-0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.0125f); MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0); tmpTrans.mul(offset, transform); body.worldTransform.set(tmpTrans); @@ -252,7 +264,7 @@ 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); + transform.origin.set(0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.0125f); MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0); tmpTrans.mul(offset, transform); body.worldTransform.set(tmpTrans); @@ -300,7 +312,7 @@ 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); + transform.origin.set(-(upperarmlength/2 + upperarmdist) * 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); @@ -310,7 +322,7 @@ 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); + transform.origin.set(-(lowerarmlength/2 + upperarmlength + upperarmdist) * 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); @@ -320,7 +332,7 @@ 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); + transform.origin.set(-(handlength/2 + lowerarmlength + upperarmlength + upperarmdist) * 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); @@ -330,7 +342,7 @@ 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); + transform.origin.set((upperarmlength/2 + upperarmdist) * 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); @@ -340,7 +352,7 @@ 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); + transform.origin.set((lowerarmlength/2 + upperarmlength + upperarmdist) * 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); @@ -350,7 +362,7 @@ 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); + transform.origin.set((handlength/2 + lowerarmlength + upperarmlength + upperarmdist) * 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); @@ -418,10 +430,10 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(-0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth); + localA.origin.set(-upperarmdist * 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); + localB.origin.set(0f, -upperarmlength/2 * scale_ragdoll, 0); joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_SPINE.ordinal()], bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA); @@ -447,9 +459,9 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth); + localA.origin.set(upperarmdist * 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); + localB.origin.set(0f, -upperarmlength/2 * scale_ragdoll, 0); joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_SPINE.ordinal()], bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA); //#ifdef RIGID @@ -474,8 +486,8 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(0f, 0.125f * scale_ragdoll, 0f); - localB.origin.set(0f, -0.1f * scale_ragdoll, 0f); + localA.origin.set(0f, upperarmlength/2 * scale_ragdoll, 0f); + localB.origin.set(0f, -lowerarmlength/2 * 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 @@ -500,8 +512,8 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(0f, 0.125f * scale_ragdoll, 0f); - localB.origin.set(0f, -0.1f * scale_ragdoll, 0f); + localA.origin.set(0f, upperarmlength/2 * scale_ragdoll, 0f); + localB.origin.set(0f, -lowerarmlength/2 * 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 @@ -526,8 +538,8 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(0f, 0.1f * scale_ragdoll, 0f); - localB.origin.set(0f, -0.05f * scale_ragdoll, 0f); + localA.origin.set(0f, lowerarmlength/2 * scale_ragdoll, 0f); + localB.origin.set(0f, -handlength/2 * scale_ragdoll, 0f); joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()], localA, localB, useLinearReferenceFrameA); //#ifdef RIGID @@ -552,8 +564,8 @@ localA.setIdentity(); localB.setIdentity(); - localA.origin.set(0f, 0.1f * scale_ragdoll, 0f); - localB.origin.set(0f, -0.05f * scale_ragdoll, 0f); + localA.origin.set(0f, lowerarmlength/2 * scale_ragdoll, 0f); + localB.origin.set(0f, -handlength/2 * scale_ragdoll, 0f); joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()], localA, localB, useLinearReferenceFrameA); //#ifdef RIGID -- Gitblit v1.6.2