Edit ragdoll scene in testbed application

This commit is contained in:
Daniel Chappuis 2021-12-11 21:02:03 +01:00
parent fa9f187632
commit fb8ed81c98
2 changed files with 275 additions and 201 deletions

View File

@ -112,15 +112,17 @@ void RagdollScene::initBodiesPositions() {
for (int i=0; i < NB_RAGDOLLS; i++) { for (int i=0; i < NB_RAGDOLLS; i++) {
mHeadBox[i]->setTransform(rp3d::Transform(mHeadPos[i], rp3d::Quaternion::identity())); mHeadBox[i]->setTransform(rp3d::Transform(mHeadPos[i], rp3d::Quaternion::identity()));
mTorsoBox[i]->setTransform(rp3d::Transform(mTorsoPos[i], rp3d::Quaternion::identity())); mChestCapsule[i]->setTransform(rp3d::Transform(mChestPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftUpperArmBox[i]->setTransform(rp3d::Transform(mLeftUpperArmPos[i], rp3d::Quaternion::identity())); mWaistCapsule[i]->setTransform(rp3d::Transform(mWaistPos[i], rp3d::Quaternion::identity()));
mLeftLowerArmBox[i]->setTransform(rp3d::Transform(mLeftLowerArmPos[i], rp3d::Quaternion::identity())); mHipCapsule[i]->setTransform(rp3d::Transform(mHipPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftUpperLegBox[i]->setTransform(rp3d::Transform(mLeftUpperLegPos[i], rp3d::Quaternion::identity())); mLeftUpperArmCapsule[i]->setTransform(rp3d::Transform(mLeftUpperArmPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftLowerLegBox[i]->setTransform(rp3d::Transform(mLeftLowerLegPos[i], rp3d::Quaternion::identity())); mLeftLowerArmCapsule[i]->setTransform(rp3d::Transform(mLeftLowerArmPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mRightUpperArmBox[i]->setTransform(rp3d::Transform(mRightUpperArmPos[i], rp3d::Quaternion::identity())); mLeftUpperLegCapsule[i]->setTransform(rp3d::Transform(mLeftUpperLegPos[i], rp3d::Quaternion::identity()));
mRightLowerArmBox[i]->setTransform(rp3d::Transform(mRightLowerArmPos[i], rp3d::Quaternion::identity())); mLeftLowerLegCapsule[i]->setTransform(rp3d::Transform(mLeftLowerLegPos[i], rp3d::Quaternion::identity()));
mRightUpperLegBox[i]->setTransform(rp3d::Transform(mRightUpperLegPos[i], rp3d::Quaternion::identity())); mRightUpperArmCapsule[i]->setTransform(rp3d::Transform(mRightUpperArmPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mRightLowerLegBox[i]->setTransform(rp3d::Transform(mRightLowerLegPos[i], rp3d::Quaternion::identity())); mRightLowerArmCapsule[i]->setTransform(rp3d::Transform(mRightLowerArmPos[i], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mRightUpperLegCapsule[i]->setTransform(rp3d::Transform(mRightUpperLegPos[i], rp3d::Quaternion::identity()));
mRightLowerLegCapsule[i]->setTransform(rp3d::Transform(mRightLowerLegPos[i], rp3d::Quaternion::identity()));
} }
} }
@ -133,15 +135,17 @@ void RagdollScene::destroyPhysicsWorld() {
for (int i=0; i < NB_RAGDOLLS; i++) { for (int i=0; i < NB_RAGDOLLS; i++) {
delete mHeadBox[i]; delete mHeadBox[i];
delete mTorsoBox[i]; delete mChestCapsule[i];
delete mLeftUpperArmBox[i]; delete mWaistCapsule[i];
delete mLeftLowerArmBox[i]; delete mHipCapsule[i];
delete mLeftUpperLegBox[i]; delete mLeftUpperArmCapsule[i];
delete mLeftLowerLegBox[i]; delete mLeftLowerArmCapsule[i];
delete mRightUpperArmBox[i]; delete mLeftUpperLegCapsule[i];
delete mRightLowerArmBox[i]; delete mLeftLowerLegCapsule[i];
delete mRightUpperLegBox[i]; delete mRightUpperArmCapsule[i];
delete mRightLowerLegBox[i]; delete mRightLowerArmCapsule[i];
delete mRightUpperLegCapsule[i];
delete mRightLowerLegCapsule[i];
} }
delete mFloor1; delete mFloor1;
@ -168,6 +172,7 @@ void RagdollScene::createRagdolls() {
const float linearDamping = 0.02f; const float linearDamping = 0.02f;
const float angularDamping = 0.02f; const float angularDamping = 0.02f;
const float frictionCoeff = 0.4f;
// For each ragdoll // For each ragdoll
for (int i=0; i < NB_RAGDOLLS_ROWS; i++) { for (int i=0; i < NB_RAGDOLLS_ROWS; i++) {
@ -176,241 +181,294 @@ void RagdollScene::createRagdolls() {
int ragdollIndex = i * NB_RAGDOLLS_COLS + j; int ragdollIndex = i * NB_RAGDOLLS_COLS + j;
const float ragdollDist = 15; const float ragdollDistX = 17;
const float ragdollDistZ = 16;
const float ragdollHeight = 31; const float ragdollHeight = 31;
rp3d::Vector3 ragdollPosition((-(NB_RAGDOLLS_ROWS-1)/2.0 + i) * ragdollDist , ragdollHeight, -11 + (-(NB_RAGDOLLS_COLS-1)/2.0 + j) * ragdollDist); rp3d::Vector3 ragdollPosition((-(NB_RAGDOLLS_ROWS-1)/2.0 + i) * ragdollDistX , ragdollHeight, -6 + (-(NB_RAGDOLLS_COLS-1)/2.0 + j) * ragdollDistZ);
// --------------- Create the head box --------------- // // --------------- Create the head box --------------- //
mHeadPos[ragdollIndex] = ragdollPosition; mHeadPos[ragdollIndex] = ragdollPosition;
mHeadBox[ragdollIndex] = new Box(true, Vector3(1.5, 1.5, 1.5) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mHeadBox[ragdollIndex] = new Sphere(true, 0.75f, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mHeadBox[ragdollIndex]->setTransform(rp3d::Transform(mHeadPos[ragdollIndex], rp3d::Quaternion::identity())); mHeadBox[ragdollIndex]->setTransform(rp3d::Transform(mHeadPos[ragdollIndex], rp3d::Quaternion::identity()));
mHeadBox[ragdollIndex]->setColor(mObjectColorDemo); mHeadBox[ragdollIndex]->setColor(mObjectColorDemo);
mHeadBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mHeadBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mHeadBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(7); mHeadBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(7);
mHeadBox[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mHeadBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mHeadBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mHeadBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mHeadBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mHeadBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mHeadBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mHeadBox[ragdollIndex]); mPhysicsObjects.push_back(mHeadBox[ragdollIndex]);
// --------------- Create the torso box --------------- // // --------------- Create the chest capsule --------------- //
mTorsoPos[ragdollIndex] = mHeadPos[ragdollIndex] + rp3d::Vector3(0, -3.25, 0); mChestPos[ragdollIndex] = mHeadPos[ragdollIndex] + rp3d::Vector3(0, -1.75, 0);
mTorsoBox[ragdollIndex] = new Box(true, Vector3(3, 4, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mChestCapsule[ragdollIndex] = new Capsule(true, 1, 1.5, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mTorsoBox[ragdollIndex]->setTransform(rp3d::Transform(mTorsoPos[ragdollIndex], rp3d::Quaternion::identity())); mChestCapsule[ragdollIndex]->setTransform(rp3d::Transform(mChestPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mTorsoBox[ragdollIndex]->setColor(mObjectColorDemo); mChestCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mTorsoBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mChestCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mTorsoBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9); mChestCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9);
mTorsoBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mChestCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mTorsoBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mChestCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mTorsoBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mChestCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
//mTorsoBox->getRigidBody()->setType(rp3d::BodyType::STATIC); mChestCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mTorsoBox[ragdollIndex]); mPhysicsObjects.push_back(mChestCapsule[ragdollIndex]);
// --------------- Create the left upper arm box --------------- // // --------------- Create the waist capsule --------------- //
mLeftUpperArmPos[ragdollIndex] = mTorsoPos[ragdollIndex] + rp3d::Vector3(2.75, 1.5, 0); mWaistPos[ragdollIndex] = mChestPos[ragdollIndex] + rp3d::Vector3(0, -2, 0);
mLeftUpperArmBox[ragdollIndex] = new Box(true, Vector3(2, 1, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mWaistCapsule[ragdollIndex] = new Capsule(true, 1, 1.5, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mLeftUpperArmBox[ragdollIndex]->setTransform(rp3d::Transform(mLeftUpperArmPos[ragdollIndex], rp3d::Quaternion::identity())); mWaistCapsule[ragdollIndex]->setTransform(rp3d::Transform(mWaistPos[ragdollIndex], rp3d::Quaternion::identity()));
mLeftUpperArmBox[ragdollIndex]->setColor(mObjectColorDemo); mWaistCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mLeftUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mWaistCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mLeftUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mWaistCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9);
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mWaistCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mWaistCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mLeftUpperArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mWaistCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mLeftUpperArmBox[ragdollIndex]); mWaistCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
//mWaistCapsule[ragdollIndex]->getRigidBody()->setType(rp3d::BodyType::STATIC);
mPhysicsObjects.push_back(mWaistCapsule[ragdollIndex]);
// --------------- Create the left lower arm box --------------- // // --------------- Create the hips capsule --------------- //
mLeftLowerArmPos[ragdollIndex] = mLeftUpperArmPos[ragdollIndex] + rp3d::Vector3(2.25, 0, 0); mHipPos[ragdollIndex] = mWaistPos[ragdollIndex] + rp3d::Vector3(0, -2, 0);
mLeftLowerArmBox[ragdollIndex] = new Box(true, Vector3(2, 1, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mHipCapsule[ragdollIndex] = new Capsule(true, 1, 1, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mLeftLowerArmBox[ragdollIndex]->setTransform(rp3d::Transform(mLeftLowerArmPos[ragdollIndex], rp3d::Quaternion::identity())); mHipCapsule[ragdollIndex]->setTransform(rp3d::Transform(mHipPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftLowerArmBox[ragdollIndex]->setColor(mObjectColorDemo); mHipCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mLeftLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mHipCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mLeftLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mHipCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(9);
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mHipCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mHipCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mLeftLowerArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mHipCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mLeftLowerArmBox[ragdollIndex]); mHipCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mHipCapsule[ragdollIndex]);
// --------------- Create the left upper leg box --------------- // // --------------- Create the left upper arm capsule --------------- //
mLeftUpperLegPos[ragdollIndex] = mTorsoPos[ragdollIndex] + rp3d::Vector3(1, -3.75, 0); mLeftUpperArmPos[ragdollIndex] = mChestPos[ragdollIndex] + rp3d::Vector3(2.25, 0, 0);
mLeftUpperLegBox[ragdollIndex] = new Box(true, Vector3(1, 3, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mLeftUpperArmCapsule[ragdollIndex] = new Capsule(true, 0.5, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mLeftUpperLegBox[ragdollIndex]->setTransform(rp3d::Transform(mLeftUpperLegPos[ragdollIndex], rp3d::Quaternion::identity())); mLeftUpperArmCapsule[ragdollIndex]->setTransform(rp3d::Transform(mLeftUpperArmPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftUpperLegBox[ragdollIndex]->setColor(mObjectColorDemo); mLeftUpperArmCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mLeftUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mLeftUpperArmCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mLeftUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mLeftUpperArmCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mLeftUpperArmCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mLeftUpperArmCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mLeftUpperLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mLeftUpperArmCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mLeftUpperLegBox[ragdollIndex]); mLeftUpperArmCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mLeftUpperArmCapsule[ragdollIndex]);
// --------------- Create the left lower leg box --------------- // // --------------- Create the left lower arm capsule --------------- //
mLeftLowerLegPos[ragdollIndex] = mLeftUpperLegPos[ragdollIndex] + rp3d::Vector3(0, -3.25, 0); mLeftLowerArmPos[ragdollIndex] = mLeftUpperArmPos[ragdollIndex] + rp3d::Vector3(2.5, 0, 0);
mLeftLowerLegBox[ragdollIndex] = new Box(true, Vector3(1, 3, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mLeftLowerArmCapsule[ragdollIndex] = new Capsule(true, 0.5, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mLeftLowerLegBox[ragdollIndex]->setTransform(rp3d::Transform(mLeftLowerLegPos[ragdollIndex], rp3d::Quaternion::identity())); mLeftLowerArmCapsule[ragdollIndex]->setTransform(rp3d::Transform(mLeftLowerArmPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mLeftLowerLegBox[ragdollIndex]->setColor(mObjectColorDemo); mLeftLowerArmCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mLeftLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mLeftLowerArmCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mLeftLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mLeftLowerArmCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mLeftLowerArmCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mLeftLowerArmCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mLeftLowerLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mLeftLowerArmCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mLeftLowerLegBox[ragdollIndex]); mLeftLowerArmCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mLeftLowerArmCapsule[ragdollIndex]);
// --------------- Create the right upper arm box --------------- // // --------------- Create the left upper leg capsule --------------- //
mRightUpperArmPos[ragdollIndex] = mTorsoPos[ragdollIndex] + rp3d::Vector3(-2.75, 1.5, 0); mLeftUpperLegPos[ragdollIndex] = mHipPos[ragdollIndex] + rp3d::Vector3(0.8, -1.5, 0);
mRightUpperArmBox[ragdollIndex] = new Box(true, Vector3(2, 1, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mLeftUpperLegCapsule[ragdollIndex] = new Capsule(true, 0.75, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightUpperArmBox[ragdollIndex]->setTransform(rp3d::Transform(mRightUpperArmPos[ragdollIndex], rp3d::Quaternion::identity())); mLeftUpperLegCapsule[ragdollIndex]->setTransform(rp3d::Transform(mLeftUpperLegPos[ragdollIndex], rp3d::Quaternion::identity()));
mRightUpperArmBox[ragdollIndex]->setColor(mObjectColorDemo); mLeftUpperLegCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightUpperArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mLeftUpperLegCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightUpperArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mLeftUpperLegCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightUpperArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mLeftUpperLegCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mRightUpperArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mLeftUpperLegCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightUpperArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mLeftUpperLegCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mRightUpperArmBox[ragdollIndex]); mLeftUpperLegCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mLeftUpperLegCapsule[ragdollIndex]);
// --------------- Create the right lower arm box --------------- // // --------------- Create the left lower leg capsule --------------- //
mRightLowerArmPos[ragdollIndex] = mRightUpperArmPos[ragdollIndex] + rp3d::Vector3(-2.25, 0, 0); mLeftLowerLegPos[ragdollIndex] = mLeftUpperLegPos[ragdollIndex] + rp3d::Vector3(0, -3, 0);
mRightLowerArmBox[ragdollIndex] = new Box(true, Vector3(2, 1, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mLeftLowerLegCapsule[ragdollIndex] = new Capsule(true, 0.5, 3, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightLowerArmBox[ragdollIndex]->setTransform(rp3d::Transform(mRightLowerArmPos[ragdollIndex], rp3d::Quaternion::identity())); mLeftLowerLegCapsule[ragdollIndex]->setTransform(rp3d::Transform(mLeftLowerLegPos[ragdollIndex], rp3d::Quaternion::identity()));
mRightLowerArmBox[ragdollIndex]->setColor(mObjectColorDemo); mLeftLowerLegCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightLowerArmBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mLeftLowerLegCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightLowerArmBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mLeftLowerLegCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightLowerArmBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mLeftLowerLegCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(0.3);
mRightLowerArmBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mLeftLowerLegCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightLowerArmBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mLeftLowerLegCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mRightLowerArmBox[ragdollIndex]); mLeftLowerLegCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mLeftLowerLegCapsule[ragdollIndex]);
// --------------- Create the right upper leg box --------------- // // --------------- Create the right upper arm capsule --------------- //
mRightUpperLegPos[ragdollIndex] = mTorsoPos[ragdollIndex] + rp3d::Vector3(-1, -3.75, 0); mRightUpperArmPos[ragdollIndex] = mChestPos[ragdollIndex] + rp3d::Vector3(-2.25, 0, 0);
mRightUpperLegBox[ragdollIndex] = new Box(true, Vector3(1, 3, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mRightUpperArmCapsule[ragdollIndex] = new Capsule(true, 0.5, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightUpperLegBox[ragdollIndex]->setTransform(rp3d::Transform(mRightUpperLegPos[ragdollIndex], rp3d::Quaternion::identity())); mRightUpperArmCapsule[ragdollIndex]->setTransform(rp3d::Transform(mRightUpperArmPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mRightUpperLegBox[ragdollIndex]->setColor(mObjectColorDemo); mRightUpperArmCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightUpperLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mRightUpperArmCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightUpperLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mRightUpperArmCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightUpperLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mRightUpperArmCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mRightUpperLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mRightUpperArmCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightUpperLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mRightUpperArmCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mRightUpperLegBox[ragdollIndex]); mRightUpperArmCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mRightUpperArmCapsule[ragdollIndex]);
// --------------- Create the right lower leg box --------------- // // --------------- Create the right lower arm capsule --------------- //
mRightLowerLegPos[ragdollIndex] = mRightUpperLegPos[ragdollIndex] + rp3d::Vector3(0, -3.25, 0); mRightLowerArmPos[ragdollIndex] = mRightUpperArmPos[ragdollIndex] + rp3d::Vector3(-2.5, 0, 0);
mRightLowerLegBox[ragdollIndex] = new Box(true, Vector3(1, 3, 1) , mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); mRightLowerArmCapsule[ragdollIndex] = new Capsule(true, 0.5, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightLowerLegBox[ragdollIndex]->setTransform(rp3d::Transform(mRightLowerLegPos[ragdollIndex], rp3d::Quaternion::identity())); mRightLowerArmCapsule[ragdollIndex]->setTransform(rp3d::Transform(mRightLowerArmPos[ragdollIndex], rp3d::Quaternion::fromEulerAngles(0, 0, rp3d::PI_RP3D / 2.0)));
mRightLowerLegBox[ragdollIndex]->setColor(mObjectColorDemo); mRightLowerArmCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightLowerLegBox[ragdollIndex]->setSleepingColor(mSleepingColorDemo); mRightLowerArmCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightLowerLegBox[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8); mRightLowerArmCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightLowerLegBox[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders(); mRightLowerArmCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mRightLowerLegBox[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping); mRightLowerArmCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightLowerLegBox[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping); mRightLowerArmCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mPhysicsObjects.push_back(mRightLowerLegBox[ragdollIndex]); mRightLowerArmCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mRightLowerArmCapsule[ragdollIndex]);
// --------------- Create the joint between head and torso --------------- // // --------------- Create the right upper leg capsule --------------- //
mRightUpperLegPos[ragdollIndex] = mHipPos[ragdollIndex] + rp3d::Vector3(-0.8, -1.5, 0);
mRightUpperLegCapsule[ragdollIndex] = new Capsule(true, 0.75, 2, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightUpperLegCapsule[ragdollIndex]->setTransform(rp3d::Transform(mRightUpperLegPos[ragdollIndex], rp3d::Quaternion::identity()));
mRightUpperLegCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightUpperLegCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightUpperLegCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightUpperLegCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(frictionCoeff);
mRightUpperLegCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightUpperLegCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mRightUpperLegCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mRightUpperLegCapsule[ragdollIndex]);
// --------------- Create the right lower leg capsule --------------- //
mRightLowerLegPos[ragdollIndex] = mRightUpperLegPos[ragdollIndex] + rp3d::Vector3(0, -3, 0);
mRightLowerLegCapsule[ragdollIndex] = new Capsule(true, 0.5, 3, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
mRightLowerLegCapsule[ragdollIndex]->setTransform(rp3d::Transform(mRightLowerLegPos[ragdollIndex], rp3d::Quaternion::identity()));
mRightLowerLegCapsule[ragdollIndex]->setColor(mObjectColorDemo);
mRightLowerLegCapsule[ragdollIndex]->setSleepingColor(mSleepingColorDemo);
mRightLowerLegCapsule[ragdollIndex]->getCollider()->getMaterial().setMassDensity(8);
mRightLowerLegCapsule[ragdollIndex]->getCollider()->getMaterial().setFrictionCoefficient(0.3);
mRightLowerLegCapsule[ragdollIndex]->getRigidBody()->updateMassPropertiesFromColliders();
mRightLowerLegCapsule[ragdollIndex]->getRigidBody()->setLinearDamping(linearDamping);
mRightLowerLegCapsule[ragdollIndex]->getRigidBody()->setAngularDamping(angularDamping);
mPhysicsObjects.push_back(mRightLowerLegCapsule[ragdollIndex]);
// --------------- Create the joint between head and chest --------------- //
// Create the joint info object // Create the joint info object
rp3d::RigidBody* body1 = mHeadBox[ragdollIndex]->getRigidBody(); rp3d::RigidBody* body1 = mHeadBox[ragdollIndex]->getRigidBody();
rp3d::RigidBody* body2 = mTorsoBox[ragdollIndex]->getRigidBody(); rp3d::RigidBody* body2 = mChestCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo1(body1, body2, mHeadPos[ragdollIndex] + rp3d::Vector3(0, -0.82, 0)); rp3d::BallAndSocketJointInfo jointInfo1(body1, body2, mHeadPos[ragdollIndex] + rp3d::Vector3(0, -0.75, 0));
jointInfo1.isCollisionEnabled = false; jointInfo1.isCollisionEnabled = false;
mHeadTorsoJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo1)); mHeadChestJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo1));
mHeadTorsoJoint[ragdollIndex]->setConeLimitLocalAxisBody1(rp3d::Vector3(0, 1, 0)); mHeadChestJoint[ragdollIndex]->setConeLimitHalfAngle(40.0 * rp3d::PI_RP3D / 180.0);
mHeadTorsoJoint[ragdollIndex]->setConeLimitLocalAxisBody2(rp3d::Vector3(0, 1, 0)); mHeadChestJoint[ragdollIndex]->enableConeLimit(true);
mHeadTorsoJoint[ragdollIndex]->setConeLimitHalfAngle(40.0 * rp3d::PI_RP3D / 180.0);
mHeadTorsoJoint[ragdollIndex]->enableConeLimit(true);
// --------------- Create the joint between torso and left upper arm --------------- // // --------------- Create the joint between chest and left upper arm --------------- //
// Create the joint info object // Create the joint info object
body1 = mTorsoBox[ragdollIndex]->getRigidBody(); body1 = mChestCapsule[ragdollIndex]->getRigidBody();
body2 = mLeftUpperArmBox[ragdollIndex]->getRigidBody(); body2 = mLeftUpperArmCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo2(body1, body2, mLeftUpperArmPos[ragdollIndex] + rp3d::Vector3(-0.5, 0, 0)); rp3d::BallAndSocketJointInfo jointInfo2(body1, body2, mLeftUpperArmPos[ragdollIndex] + rp3d::Vector3(-1, 0, 0));
jointInfo2.isCollisionEnabled = false; jointInfo2.isCollisionEnabled = false;
mTorsoLeftUpperArmJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo2)); mChestLeftUpperArmJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo2));
mTorsoLeftUpperArmJoint[ragdollIndex]->setConeLimitLocalAxisBody1(rp3d::Vector3(1, 0, 0)); mChestLeftUpperArmJoint[ragdollIndex]->setConeLimitHalfAngle(180.0 * rp3d::PI_RP3D / 180.0);
mTorsoLeftUpperArmJoint[ragdollIndex]->setConeLimitLocalAxisBody2(rp3d::Vector3(1, 0, 0)); mChestLeftUpperArmJoint[ragdollIndex]->enableConeLimit(true);
mTorsoLeftUpperArmJoint[ragdollIndex]->setConeLimitHalfAngle(90.0 * rp3d::PI_RP3D / 180.0);
mTorsoLeftUpperArmJoint[ragdollIndex]->enableConeLimit(true);
// --------------- Create the joint between left upper arm and left lower arm --------------- // // --------------- Create the joint between left upper arm and left lower arm --------------- //
// Create the joint info object // Create the joint info object
body1 = mLeftUpperArmBox[ragdollIndex]->getRigidBody(); body1 = mLeftUpperArmCapsule[ragdollIndex]->getRigidBody();
body2 = mLeftLowerArmBox[ragdollIndex]->getRigidBody(); body2 = mLeftLowerArmCapsule[ragdollIndex]->getRigidBody();
rp3d::Vector3 joint2WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f; rp3d::Vector3 joint2WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::Vector3 joint2WorldAxis(0, 0, 1); rp3d::Vector3 joint2WorldAxis(0, 0, 1);
rp3d::HingeJointInfo jointInfo3(body1, body2, joint2WorldAnchor, joint2WorldAxis); rp3d::HingeJointInfo jointInfo3(body1, body2, joint2WorldAnchor, joint2WorldAxis);
jointInfo3.isCollisionEnabled = false; jointInfo3.isCollisionEnabled = false;
mLeftUpperLeftLowerArmJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo3)); mLeftUpperLeftLowerArmJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo3));
mLeftUpperLeftLowerArmJoint[ragdollIndex]->enableLimit(true);
mLeftUpperLeftLowerArmJoint[ragdollIndex]->setMinAngleLimit(0.0 * rp3d::PI_RP3D / 180.0);
mLeftUpperLeftLowerArmJoint[ragdollIndex]->setMaxAngleLimit(340.0 * rp3d::PI_RP3D / 180.0);
// --------------- Create the joint between torso and left upper leg --------------- // // --------------- Create the joint between chest and waist --------------- //
// Create the joint info object // Create the joint info object
body1 = mTorsoBox[ragdollIndex]->getRigidBody(); body1 = mChestCapsule[ragdollIndex]->getRigidBody();
body2 = mLeftUpperLegBox[ragdollIndex]->getRigidBody(); body2 = mWaistCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo4(body1, body2, mTorsoPos[ragdollIndex] + rp3d::Vector3(1, -1.87, 0)); rp3d::Vector3 jointChestWaistWorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::FixedJointInfo jointChestWaistInfo(body1, body2, jointChestWaistWorldAnchor);
jointChestWaistInfo.isCollisionEnabled = false;
mChestWaistJoint[ragdollIndex] = dynamic_cast<rp3d::FixedJoint*>(mPhysicsWorld->createJoint(jointChestWaistInfo));
// --------------- Create the joint between waist and hips --------------- //
// Create the joint info object
body1 = mWaistCapsule[ragdollIndex]->getRigidBody();
body2 = mHipCapsule[ragdollIndex]->getRigidBody();
rp3d::Vector3 jointWaistHipsWorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::FixedJointInfo jointWaistHipsInfo(body1, body2, jointWaistHipsWorldAnchor);
jointWaistHipsInfo.isCollisionEnabled = false;
mWaistHipsJoint[ragdollIndex] = dynamic_cast<rp3d::FixedJoint*>(mPhysicsWorld->createJoint(jointWaistHipsInfo));
// --------------- Create the joint between hip and left upper leg --------------- //
// Create the joint info object
body1 = mHipCapsule[ragdollIndex]->getRigidBody();
body2 = mLeftUpperLegCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo4(body1, body2, mHipPos[ragdollIndex] + rp3d::Vector3(0.8, 0, 0));
jointInfo4.isCollisionEnabled = false; jointInfo4.isCollisionEnabled = false;
mTorsoLeftUpperLegJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo4)); mHipLeftUpperLegJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo4));
mTorsoLeftUpperLegJoint[ragdollIndex]->setConeLimitLocalAxisBody1(rp3d::Vector3(0, 1, 0)); mHipLeftUpperLegJoint[ragdollIndex]->setConeLimitHalfAngle(80.0 * rp3d::PI_RP3D / 180.0);
mTorsoLeftUpperLegJoint[ragdollIndex]->setConeLimitLocalAxisBody2(rp3d::Vector3(0, 1, 0)); mHipLeftUpperLegJoint[ragdollIndex]->enableConeLimit(true);
mTorsoLeftUpperLegJoint[ragdollIndex]->setConeLimitHalfAngle(90.0 * rp3d::PI_RP3D / 180.0);
mTorsoLeftUpperLegJoint[ragdollIndex]->enableConeLimit(true);
// --------------- Create the joint between left upper leg and left lower leg --------------- // // --------------- Create the joint between left upper leg and left lower leg --------------- //
// Create the joint info object // Create the joint info object
body1 = mLeftUpperLegBox[ragdollIndex]->getRigidBody(); body1 = mLeftUpperLegCapsule[ragdollIndex]->getRigidBody();
body2 = mLeftLowerLegBox[ragdollIndex]->getRigidBody(); body2 = mLeftLowerLegCapsule[ragdollIndex]->getRigidBody();
rp3d::Vector3 joint5WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f; rp3d::Vector3 joint5WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::Vector3 joint5WorldAxis(1, 0, 0); rp3d::Vector3 joint5WorldAxis(1, 0, 0);
const rp3d::decimal joint5MinAngle = 0.0 * rp3d::PI_RP3D / 180.0; const rp3d::decimal joint5MinAngle = 0.0 * rp3d::PI_RP3D / 180.0;
const rp3d::decimal joint5MaxAngle = 110.0 * rp3d::PI_RP3D / 180.0; const rp3d::decimal joint5MaxAngle = 140.0 * rp3d::PI_RP3D / 180.0;
rp3d::HingeJointInfo jointInfo5(body1, body2, joint5WorldAnchor, joint5WorldAxis, joint5MinAngle, joint5MaxAngle); rp3d::HingeJointInfo jointInfo5(body1, body2, joint5WorldAnchor, joint5WorldAxis, joint5MinAngle, joint5MaxAngle);
jointInfo5.isCollisionEnabled = false; jointInfo5.isCollisionEnabled = false;
mLeftUpperLeftLowerLegJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo5)); mLeftUpperLeftLowerLegJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo5));
// --------------- Create the joint between torso and right upper arm --------------- // // --------------- Create the joint between chest and right upper arm --------------- //
// Create the joint info object // Create the joint info object
body1 = mTorsoBox[ragdollIndex]->getRigidBody(); body1 = mChestCapsule[ragdollIndex]->getRigidBody();
body2 = mRightUpperArmBox[ragdollIndex]->getRigidBody(); body2 = mRightUpperArmCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo6(body1, body2, mRightUpperArmPos[ragdollIndex] + rp3d::Vector3(0.5, 0, 0)); rp3d::BallAndSocketJointInfo jointInfo6(body1, body2, mRightUpperArmPos[ragdollIndex] + rp3d::Vector3(1, 0, 0));
jointInfo6.isCollisionEnabled = false; jointInfo6.isCollisionEnabled = false;
mTorsoRightUpperArmJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo6)); mChestRightUpperArmJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo6));
mTorsoRightUpperArmJoint[ragdollIndex]->setConeLimitLocalAxisBody1(rp3d::Vector3(1, 0, 0)); mChestRightUpperArmJoint[ragdollIndex]->setConeLimitHalfAngle(180.0 * rp3d::PI_RP3D / 180.0);
mTorsoRightUpperArmJoint[ragdollIndex]->setConeLimitLocalAxisBody2(rp3d::Vector3(1, 0, 0)); mChestRightUpperArmJoint[ragdollIndex]->enableConeLimit(true);
mTorsoRightUpperArmJoint[ragdollIndex]->setConeLimitHalfAngle(90.0 * rp3d::PI_RP3D / 180.0);
mTorsoRightUpperArmJoint[ragdollIndex]->enableConeLimit(true);
// --------------- Create the joint between right upper arm and right lower arm --------------- // // --------------- Create the joint between right upper arm and right lower arm --------------- //
// Create the joint info object // Create the joint info object
body1 = mRightUpperArmBox[ragdollIndex]->getRigidBody(); body1 = mRightUpperArmCapsule[ragdollIndex]->getRigidBody();
body2 = mRightLowerArmBox[ragdollIndex]->getRigidBody(); body2 = mRightLowerArmCapsule[ragdollIndex]->getRigidBody();
rp3d::Vector3 joint7WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f; rp3d::Vector3 joint7WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::Vector3 joint7WorldAxis(0, 0, 1); rp3d::Vector3 joint7WorldAxis(0, 0, 1);
rp3d::HingeJointInfo jointInfo7(body1, body2, joint7WorldAnchor, joint7WorldAxis); rp3d::HingeJointInfo jointInfo7(body1, body2, joint7WorldAnchor, joint7WorldAxis);
jointInfo7.isCollisionEnabled = false; jointInfo7.isCollisionEnabled = false;
mRightUpperRightLowerArmJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo7)); mRightUpperRightLowerArmJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo7));
mRightUpperRightLowerArmJoint[ragdollIndex]->enableLimit(true);
mRightUpperRightLowerArmJoint[ragdollIndex]->setMinAngleLimit(0.0 * rp3d::PI_RP3D / 180.0);
mRightUpperRightLowerArmJoint[ragdollIndex]->setMaxAngleLimit(340.0 * rp3d::PI_RP3D / 180.0);
// --------------- Create the joint between torso and right upper leg --------------- // // --------------- Create the joint between hips and right upper leg --------------- //
// Create the joint info object // Create the joint info object
body1 = mTorsoBox[ragdollIndex]->getRigidBody(); body1 = mHipCapsule[ragdollIndex]->getRigidBody();
body2 = mRightUpperLegBox[ragdollIndex]->getRigidBody(); body2 = mRightUpperLegCapsule[ragdollIndex]->getRigidBody();
rp3d::BallAndSocketJointInfo jointInfo8(body1, body2, mTorsoPos[ragdollIndex] + rp3d::Vector3(-1, -1.87, 0)); rp3d::BallAndSocketJointInfo jointInfo8(body1, body2, mHipPos[ragdollIndex] + rp3d::Vector3(-0.8, 0, 0));
jointInfo8.isCollisionEnabled = false; jointInfo8.isCollisionEnabled = false;
mTorsoRightUpperLegJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo8)); mHipRightUpperLegJoint[ragdollIndex] = dynamic_cast<rp3d::BallAndSocketJoint*>(mPhysicsWorld->createJoint(jointInfo8));
mTorsoRightUpperLegJoint[ragdollIndex]->setConeLimitLocalAxisBody1(rp3d::Vector3(0, 1, 0)); mHipRightUpperLegJoint[ragdollIndex]->setConeLimitHalfAngle(80.0 * rp3d::PI_RP3D / 180.0);
mTorsoRightUpperLegJoint[ragdollIndex]->setConeLimitLocalAxisBody2(rp3d::Vector3(0, 1, 0)); mHipRightUpperLegJoint[ragdollIndex]->enableConeLimit(true);
mTorsoRightUpperLegJoint[ragdollIndex]->setConeLimitHalfAngle(90.0 * rp3d::PI_RP3D / 180.0);
mTorsoRightUpperLegJoint[ragdollIndex]->enableConeLimit(true);
// --------------- Create the joint between right upper leg and right lower leg --------------- // // --------------- Create the joint between right upper leg and right lower leg --------------- //
// Create the joint info object // Create the joint info object
body1 = mRightUpperLegBox[ragdollIndex]->getRigidBody(); body1 = mRightUpperLegCapsule[ragdollIndex]->getRigidBody();
body2 = mRightLowerLegBox[ragdollIndex]->getRigidBody(); body2 = mRightLowerLegCapsule[ragdollIndex]->getRigidBody();
rp3d::Vector3 joint9WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f; rp3d::Vector3 joint9WorldAnchor = (body1->getTransform().getPosition() + body2->getTransform().getPosition()) * 0.5f;
rp3d::Vector3 joint9WorldAxis(1, 0, 0); rp3d::Vector3 joint9WorldAxis(1, 0, 0);
const rp3d::decimal joint9MinAngle = 0.0 * rp3d::PI_RP3D / 180.0; const rp3d::decimal joint9MinAngle = 0.0 * rp3d::PI_RP3D / 180.0;
const rp3d::decimal joint9MaxAngle = 110.0 * rp3d::PI_RP3D / 180.0; const rp3d::decimal joint9MaxAngle = 140.0 * rp3d::PI_RP3D / 180.0;
rp3d::HingeJointInfo jointInfo9(body1, body2, joint9WorldAnchor, joint9WorldAxis, joint9MinAngle, joint9MaxAngle); rp3d::HingeJointInfo jointInfo9(body1, body2, joint9WorldAnchor, joint9WorldAxis, joint9MinAngle, joint9MaxAngle);
jointInfo9.isCollisionEnabled = false; jointInfo9.isCollisionEnabled = false;
mRightUpperRightLowerLegJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo9)); mRightUpperRightLowerLegJoint[ragdollIndex] = dynamic_cast<rp3d::HingeJoint*>(mPhysicsWorld->createJoint(jointInfo9));

View File

@ -30,6 +30,8 @@
#include "openglframework.h" #include "openglframework.h"
#include <reactphysics3d/reactphysics3d.h> #include <reactphysics3d/reactphysics3d.h>
#include "Box.h" #include "Box.h"
#include "Capsule.h"
#include "Sphere.h"
#include "SceneDemo.h" #include "SceneDemo.h"
namespace ragdollscene { namespace ragdollscene {
@ -52,35 +54,41 @@ class RagdollScene : public SceneDemo {
// -------------------- Attributes -------------------- // // -------------------- Attributes -------------------- //
/// Head box /// Head sphere
Box* mHeadBox[NB_RAGDOLLS]; Sphere* mHeadBox[NB_RAGDOLLS];
/// Torso box /// Chest
Box* mTorsoBox[NB_RAGDOLLS]; Capsule* mChestCapsule[NB_RAGDOLLS];
/// Left upper arm box /// Waist capsule
Box* mLeftUpperArmBox[NB_RAGDOLLS]; Capsule* mWaistCapsule[NB_RAGDOLLS];
/// Left lower arm box /// Hip capsule
Box* mLeftLowerArmBox[NB_RAGDOLLS]; Capsule* mHipCapsule[NB_RAGDOLLS];
/// Left upper leg box /// Left upper arm capsule
Box* mLeftUpperLegBox[NB_RAGDOLLS]; Capsule* mLeftUpperArmCapsule[NB_RAGDOLLS];
/// Left lower leg box /// Left lower arm capsule
Box* mLeftLowerLegBox[NB_RAGDOLLS]; Capsule* mLeftLowerArmCapsule[NB_RAGDOLLS];
/// Right upper arm box /// Left upper leg capsule
Box* mRightUpperArmBox[NB_RAGDOLLS]; Capsule* mLeftUpperLegCapsule[NB_RAGDOLLS];
/// Right lower arm box /// Left lower leg capsule
Box* mRightLowerArmBox[NB_RAGDOLLS]; Capsule* mLeftLowerLegCapsule[NB_RAGDOLLS];
/// Right upper leg box /// Right upper arm capsule
Box* mRightUpperLegBox[NB_RAGDOLLS]; Capsule* mRightUpperArmCapsule[NB_RAGDOLLS];
/// Right lower leg box /// Right lower arm capsule
Box* mRightLowerLegBox[NB_RAGDOLLS]; Capsule* mRightLowerArmCapsule[NB_RAGDOLLS];
/// Right upper leg capsule
Capsule* mRightUpperLegCapsule[NB_RAGDOLLS];
/// Right lower leg capsule
Capsule* mRightLowerLegCapsule[NB_RAGDOLLS];
/// Box for the floor 1 /// Box for the floor 1
Box* mFloor1; Box* mFloor1;
@ -95,34 +103,42 @@ class RagdollScene : public SceneDemo {
Box* mInclinedPlaneBox; Box* mInclinedPlaneBox;
/// Ball-And-Socket joint between head and torso /// Ball-And-Socket joint between head and torso
rp3d::BallAndSocketJoint* mHeadTorsoJoint[NB_RAGDOLLS]; rp3d::BallAndSocketJoint* mHeadChestJoint[NB_RAGDOLLS];
/// Ball-And-Socket joint between torso and left upper arm /// Ball-And-Socket joint between torso and left upper arm
rp3d::BallAndSocketJoint* mTorsoLeftUpperArmJoint[NB_RAGDOLLS]; rp3d::BallAndSocketJoint* mChestLeftUpperArmJoint[NB_RAGDOLLS];
/// Hinge joint between left upper and left lower arm /// Hinge joint between left upper and left lower arm
rp3d::HingeJoint* mLeftUpperLeftLowerArmJoint[NB_RAGDOLLS]; rp3d::HingeJoint* mLeftUpperLeftLowerArmJoint[NB_RAGDOLLS];
/// Fixed joint between chest and waist
rp3d::FixedJoint* mChestWaistJoint[NB_RAGDOLLS];
/// Fixed joint between waist and hips
rp3d::FixedJoint* mWaistHipsJoint[NB_RAGDOLLS];
/// Ball-And-Socket joint between torso and left upper leg /// Ball-And-Socket joint between torso and left upper leg
rp3d::BallAndSocketJoint* mTorsoLeftUpperLegJoint[NB_RAGDOLLS]; rp3d::BallAndSocketJoint* mHipLeftUpperLegJoint[NB_RAGDOLLS];
/// Hinge joint between left upper and left lower leg /// Hinge joint between left upper and left lower leg
rp3d::HingeJoint* mLeftUpperLeftLowerLegJoint[NB_RAGDOLLS]; rp3d::HingeJoint* mLeftUpperLeftLowerLegJoint[NB_RAGDOLLS];
/// Ball-And-Socket joint between torso and right upper arm /// Ball-And-Socket joint between torso and right upper arm
rp3d::BallAndSocketJoint* mTorsoRightUpperArmJoint[NB_RAGDOLLS]; rp3d::BallAndSocketJoint* mChestRightUpperArmJoint[NB_RAGDOLLS];
/// Hinge joint between left upper and right lower arm /// Hinge joint between left upper and right lower arm
rp3d::HingeJoint* mRightUpperRightLowerArmJoint[NB_RAGDOLLS]; rp3d::HingeJoint* mRightUpperRightLowerArmJoint[NB_RAGDOLLS];
/// Ball-And-Socket joint between torso and right upper leg /// Ball-And-Socket joint between torso and right upper leg
rp3d::BallAndSocketJoint* mTorsoRightUpperLegJoint[NB_RAGDOLLS]; rp3d::BallAndSocketJoint* mHipRightUpperLegJoint[NB_RAGDOLLS];
/// Hinge joint between left upper and left lower leg /// Hinge joint between left upper and left lower leg
rp3d::HingeJoint* mRightUpperRightLowerLegJoint[NB_RAGDOLLS]; rp3d::HingeJoint* mRightUpperRightLowerLegJoint[NB_RAGDOLLS];
rp3d::Vector3 mChestPos[NB_RAGDOLLS];
rp3d::Vector3 mWaistPos[NB_RAGDOLLS];
rp3d::Vector3 mHipPos[NB_RAGDOLLS];
rp3d::Vector3 mHeadPos[NB_RAGDOLLS]; rp3d::Vector3 mHeadPos[NB_RAGDOLLS];
rp3d::Vector3 mTorsoPos[NB_RAGDOLLS];
rp3d::Vector3 mLeftUpperArmPos[NB_RAGDOLLS]; rp3d::Vector3 mLeftUpperArmPos[NB_RAGDOLLS];
rp3d::Vector3 mLeftLowerArmPos[NB_RAGDOLLS]; rp3d::Vector3 mLeftLowerArmPos[NB_RAGDOLLS];
rp3d::Vector3 mLeftUpperLegPos[NB_RAGDOLLS]; rp3d::Vector3 mLeftUpperLegPos[NB_RAGDOLLS];