Normand Briere
2019-09-24 767be784dc7fe293bf5c5ee6507df242526be3ed
RagDoll.java
....@@ -123,6 +123,8 @@
123123 JOINT_COUNT
124124 }
125125
126
+ float scale;
127
+
126128 //DynamicsWorld ownerWorld;
127129 CollisionShape[] shapes = new CollisionShape[BodyPart.BODYPART_COUNT.ordinal()];
128130 RigidBody/*Serial*/[] bodies = new RigidBody/*Serial*/[BodyPart.BODYPART_COUNT.ordinal()];
....@@ -140,6 +142,8 @@
140142
141143 public void init(/*DynamicsWorld ownerWorld,*/ Vector3f positionOffset, float scale_ragdoll, boolean walk)
142144 {
145
+ scale = scale_ragdoll;
146
+
143147 this.walkmotion = walk;
144148
145149 boolean hasbodies = (bodies[BodyPart.BODYPART_SPINE.ordinal()] != null);
....@@ -149,32 +153,40 @@
149153 Transform tmpTrans = new Transform();
150154 Vector3f tmp = new Vector3f();
151155
152
- boolean node = true;
156
+ boolean node = false; // true;
157
+
158
+ // KIDS4
159
+ float upperarmlength = 0.3f; // 0.25
160
+ float lowerarmlength = 0.25f; // 0.2
161
+ float handlength = 0.1f; // 0.1
162
+ float upperarmdist = 0.15f;
153163
154164 // Setup the geometry
155165 //shapes[BodyPart.BODYPART_GROUND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.125f, scale_ragdoll * 0.20f);
156166 //scale_ragdoll /= 1.25;
157167 if (!hasbodies)
158168 {
159
- shapes[BodyPart.BODYPART_PELVIS.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.35f,false);
160
- shapes[BodyPart.BODYPART_SPINE.ordinal()] = new CapsuleShape(scale_ragdoll * 0.2f, scale_ragdoll * 0.5f,false);
161
- shapes[BodyPart.BODYPART_HEAD.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.15f,false);
169
+ float thin = 0.1f;
170
+
171
+ shapes[BodyPart.BODYPART_PELVIS.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.35f, false);
172
+ shapes[BodyPart.BODYPART_SPINE.ordinal()] = new CapsuleShape(scale_ragdoll * 0.2f, scale_ragdoll * 0.5f, false);
173
+ shapes[BodyPart.BODYPART_HEAD.ordinal()] = new CapsuleShape(scale_ragdoll * 0.15f, scale_ragdoll * 0.15f, false);
162174
163
- shapes[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f, scale_ragdoll * 0.4f,false);
164
- shapes[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.37f,node);
165
- shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
175
+ shapes[BodyPart.BODYPART_LEFT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.4f * thin, scale_ragdoll * 0.4f, node);
176
+ shapes[BodyPart.BODYPART_LEFT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.37f * thin, scale_ragdoll * 0.37f, node);
177
+ shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f * thin, scale_ragdoll * 0.1f, node);
166178
167
- shapes[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f, scale_ragdoll * 0.4f,false);
168
- shapes[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.37f,node);
169
- shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
179
+ shapes[BodyPart.BODYPART_RIGHT_UPPER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.4f * thin, scale_ragdoll * 0.4f, node);
180
+ shapes[BodyPart.BODYPART_RIGHT_LOWER_LEG.ordinal()] = new CapsuleShape(scale_ragdoll * 0.37f * thin, scale_ragdoll * 0.37f, node);
181
+ shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = new CapsuleShape(scale_ragdoll * 0.1f * thin, scale_ragdoll * 0.1f, node);
170182
171
- shapes[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.08f, scale_ragdoll * 0.25f,node);
172
- shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.2f,node);
173
- shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
183
+ shapes[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * upperarmlength * thin, scale_ragdoll * upperarmlength, node);
184
+ shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * lowerarmlength * thin, scale_ragdoll * lowerarmlength, node);
185
+ shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * handlength * thin, scale_ragdoll * handlength, node);
174186
175
- shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.08f, scale_ragdoll * 0.25f,node);
176
- shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * 0.06f, scale_ragdoll * 0.2f,node);
177
- shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * 0.04f, scale_ragdoll * 0.1f,node);
187
+ shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * upperarmlength * thin, scale_ragdoll * upperarmlength, node);
188
+ shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = new CapsuleShape(scale_ragdoll * lowerarmlength * thin, scale_ragdoll * lowerarmlength, node);
189
+ shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = new CapsuleShape(scale_ragdoll * handlength * thin, scale_ragdoll * handlength, node);
178190 }
179191 //scale_ragdoll *= 1.25;
180192
....@@ -185,7 +197,7 @@
185197
186198 Transform transform = new Transform();
187199
188
- float depth = -0.02f; // .02f;
200
+ float depth = -0.01f; // .02f;
189201
190202 // transform.setIdentity();
191203 // transform.origin.set(0f, scale_ragdoll * 1f, 0f);
....@@ -242,7 +254,7 @@
242254 transform.setIdentity();
243255 if ((body = bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()]) == null)
244256 body = bodies[BodyPart.BODYPART_LEFT_FOOT.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_LEFT_FOOT.ordinal()]);
245
- transform.origin.set(-0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.025f);
257
+ transform.origin.set(-0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.0125f);
246258 MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0);
247259 tmpTrans.mul(offset, transform);
248260 body.worldTransform.set(tmpTrans);
....@@ -252,7 +264,7 @@
252264 transform.setIdentity();
253265 if ((body = bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()]) == null)
254266 body = bodies[BodyPart.BODYPART_RIGHT_FOOT.ordinal()] = localCreateRigidBody(massfeet, poisefeet, transform, shapes[BodyPart.BODYPART_RIGHT_FOOT.ordinal()]);
255
- transform.origin.set(0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.025f);
267
+ transform.origin.set(0.09f * scale_ragdoll, 0.075f * scale_ragdoll, 0.0125f);
256268 MatrixUtil.setEulerZYX(transform.basis, BulletGlobals.SIMD_PI/2, 0,BulletGlobals.SIMD_PI); // BulletGlobals.SIMD_PI, 0);
257269 tmpTrans.mul(offset, transform);
258270 body.worldTransform.set(tmpTrans);
....@@ -300,7 +312,7 @@
300312 transform.setIdentity();
301313 if ((body = bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()]) == null)
302314 body = bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()]);
303
- transform.origin.set(-0.275f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
315
+ transform.origin.set(-(upperarmlength/2 + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
304316 MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
305317 tmpTrans.mul(offset, transform);
306318 body.worldTransform.set(tmpTrans);
....@@ -310,7 +322,7 @@
310322 transform.setIdentity();
311323 if ((body = bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()]) == null)
312324 body = bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()]);
313
- transform.origin.set(-0.5f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
325
+ transform.origin.set(-(lowerarmlength/2 + upperarmlength + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
314326 MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
315327 tmpTrans.mul(offset, transform);
316328 body.worldTransform.set(tmpTrans);
....@@ -320,7 +332,7 @@
320332 transform.setIdentity();
321333 if ((body = bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()]) == null)
322334 body = bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_LEFT_HAND.ordinal()]);
323
- transform.origin.set(-0.65f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
335
+ transform.origin.set(-(handlength/2 + lowerarmlength + upperarmlength + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
324336 MatrixUtil.setEulerZYX(transform.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
325337 tmpTrans.mul(offset, transform);
326338 body.worldTransform.set(tmpTrans);
....@@ -330,7 +342,7 @@
330342 transform.setIdentity();
331343 if ((body = bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()]) == null)
332344 body = bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()]);
333
- transform.origin.set(0.275f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
345
+ transform.origin.set((upperarmlength/2 + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
334346 MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
335347 tmpTrans.mul(offset, transform);
336348 body.worldTransform.set(tmpTrans);
....@@ -340,7 +352,7 @@
340352 transform.setIdentity();
341353 if ((body = bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()]) == null)
342354 body = bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()]);
343
- transform.origin.set(0.50f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
355
+ transform.origin.set((lowerarmlength/2 + upperarmlength + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
344356 MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
345357 tmpTrans.mul(offset, transform);
346358 body.worldTransform.set(tmpTrans);
....@@ -350,7 +362,7 @@
350362 transform.setIdentity();
351363 if ((body = bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()]) == null)
352364 body = bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()] = localCreateRigidBody(1f, 0, transform, shapes[BodyPart.BODYPART_RIGHT_HAND.ordinal()]);
353
- transform.origin.set(0.65f * scale_ragdoll, 1.325f * scale_ragdoll, depth);
365
+ transform.origin.set((handlength/2 + lowerarmlength + upperarmlength + upperarmdist) * scale_ragdoll, 1.325f * scale_ragdoll, depth);
354366 MatrixUtil.setEulerZYX(transform.basis, 0, 0, -BulletGlobals.SIMD_HALF_PI);
355367 tmpTrans.mul(offset, transform);
356368 body.worldTransform.set(tmpTrans);
....@@ -418,10 +430,10 @@
418430 localA.setIdentity();
419431 localB.setIdentity();
420432
421
- localA.origin.set(-0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth);
433
+ localA.origin.set(-upperarmdist * scale_ragdoll, 0.125f * scale_ragdoll, depth);
422434
423435 MatrixUtil.setEulerZYX(localB.basis, 0/*BulletGlobals.SIMD_HALF_PI*/, 0, -BulletGlobals.SIMD_HALF_PI);
424
- localB.origin.set(0f, -0.125f * scale_ragdoll, 0);
436
+ localB.origin.set(0f, -upperarmlength/2 * scale_ragdoll, 0);
425437
426438 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_SPINE.ordinal()], bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA);
427439
....@@ -447,9 +459,9 @@
447459 localA.setIdentity();
448460 localB.setIdentity();
449461
450
- localA.origin.set(0.15f * scale_ragdoll, 0.125f * scale_ragdoll, depth);
462
+ localA.origin.set(upperarmdist * scale_ragdoll, 0.125f * scale_ragdoll, depth);
451463 MatrixUtil.setEulerZYX(localB.basis, 0, 0, BulletGlobals.SIMD_HALF_PI);
452
- localB.origin.set(0f, -0.125f * scale_ragdoll, 0);
464
+ localB.origin.set(0f, -upperarmlength/2 * scale_ragdoll, 0);
453465 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_SPINE.ordinal()], bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA);
454466
455467 //#ifdef RIGID
....@@ -474,8 +486,8 @@
474486 localA.setIdentity();
475487 localB.setIdentity();
476488
477
- localA.origin.set(0f, 0.125f * scale_ragdoll, 0f);
478
- localB.origin.set(0f, -0.1f * scale_ragdoll, 0f);
489
+ localA.origin.set(0f, upperarmlength/2 * scale_ragdoll, 0f);
490
+ localB.origin.set(0f, -lowerarmlength/2 * scale_ragdoll, 0f);
479491 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_LEFT_UPPER_ARM.ordinal()], bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA);
480492
481493 //#ifdef RIGID
....@@ -500,8 +512,8 @@
500512 localA.setIdentity();
501513 localB.setIdentity();
502514
503
- localA.origin.set(0f, 0.125f * scale_ragdoll, 0f);
504
- localB.origin.set(0f, -0.1f * scale_ragdoll, 0f);
515
+ localA.origin.set(0f, upperarmlength/2 * scale_ragdoll, 0f);
516
+ localB.origin.set(0f, -lowerarmlength/2 * scale_ragdoll, 0f);
505517 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_RIGHT_UPPER_ARM.ordinal()], bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()], localA, localB, useLinearReferenceFrameA);
506518
507519 //#ifdef RIGID
....@@ -526,8 +538,8 @@
526538 localA.setIdentity();
527539 localB.setIdentity();
528540
529
- localA.origin.set(0f, 0.1f * scale_ragdoll, 0f);
530
- localB.origin.set(0f, -0.05f * scale_ragdoll, 0f);
541
+ localA.origin.set(0f, lowerarmlength/2 * scale_ragdoll, 0f);
542
+ localB.origin.set(0f, -handlength/2 * scale_ragdoll, 0f);
531543 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_LEFT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_LEFT_HAND.ordinal()], localA, localB, useLinearReferenceFrameA);
532544
533545 //#ifdef RIGID
....@@ -552,8 +564,8 @@
552564 localA.setIdentity();
553565 localB.setIdentity();
554566
555
- localA.origin.set(0f, 0.1f * scale_ragdoll, 0f);
556
- localB.origin.set(0f, -0.05f * scale_ragdoll, 0f);
567
+ localA.origin.set(0f, lowerarmlength/2 * scale_ragdoll, 0f);
568
+ localB.origin.set(0f, -handlength/2 * scale_ragdoll, 0f);
557569 joint6DOF = new Generic6DofConstraint(bodies[BodyPart.BODYPART_RIGHT_LOWER_ARM.ordinal()], bodies[BodyPart.BODYPART_RIGHT_HAND.ordinal()], localA, localB, useLinearReferenceFrameA);
558570
559571 //#ifdef RIGID