Constructor
| 35 | |
| 36 | // Constructor |
| 37 | Dumbbell::Dumbbell(reactphysics3d::BodyType type, bool isSimulationCollider, rp3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld, const std::string& meshFolderPath) |
| 38 | : PhysicsObject(physicsCommon, meshFolderPath + "dumbbell.obj"), mPhysicsWorld(physicsWorld) { |
| 39 | |
| 40 | // Identity scaling matrix |
| 41 | mScalingMatrix.setToIdentity(); |
| 42 | |
| 43 | mDistanceBetweenSphere = 8.0f; |
| 44 | |
| 45 | // Create a sphere collision shape for the two ends of the dumbbell |
| 46 | // ReactPhysics3D will clone this object to create an internal one. Therefore, |
| 47 | // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() |
| 48 | const rp3d::decimal radiusSphere = rp3d::decimal(1.5); |
| 49 | mSphereShape = mPhysicsCommon.createSphereShape(radiusSphere); |
| 50 | |
| 51 | // Create a capsule collision shape for the middle of the dumbbell |
| 52 | // ReactPhysics3D will clone this object to create an internal one. Therefore, |
| 53 | // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() |
| 54 | const rp3d::decimal radiusCapsule = rp3d::decimal(0.5); |
| 55 | const rp3d::decimal heightCapsule = rp3d::decimal(7.0); |
| 56 | mCapsuleShape = mPhysicsCommon.createCapsuleShape(radiusCapsule, heightCapsule); |
| 57 | |
| 58 | mPreviousTransform = rp3d::Transform::identity(); |
| 59 | |
| 60 | // Initial transform of the first sphere collision shape of the dumbbell (in local-space) |
| 61 | rp3d::Transform transformSphereShape1(rp3d::Vector3(0, mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity()); |
| 62 | |
| 63 | // Initial transform of the second sphere collision shape of the dumbell (in local-space) |
| 64 | rp3d::Transform transformSphereShape2(rp3d::Vector3(0, -mDistanceBetweenSphere / 2.0f, 0), rp3d::Quaternion::identity()); |
| 65 | |
| 66 | // Initial transform of the cylinder collision shape of the dumbell (in local-space) |
| 67 | rp3d::Transform transformCylinderShape(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity()); |
| 68 | |
| 69 | // Create a body corresponding to the dumbbell in the physics world |
| 70 | rp3d::RigidBody* body = physicsWorld->createRigidBody(mPreviousTransform); |
| 71 | body->setType(type); |
| 72 | body->setIsDebugEnabled(true); |
| 73 | mColliderSphere1 = body->addCollider(mSphereShape, transformSphereShape1); |
| 74 | mColliderSphere1->setIsSimulationCollider(isSimulationCollider); |
| 75 | mColliderSphere2 = body->addCollider(mSphereShape, transformSphereShape2); |
| 76 | mColliderSphere2->setIsSimulationCollider(isSimulationCollider); |
| 77 | mColliderCapsule = body->addCollider(mCapsuleShape, transformCylinderShape); |
| 78 | mColliderCapsule->setIsSimulationCollider(isSimulationCollider); |
| 79 | mColliderSphere1->getMaterial().setMassDensity(2); |
| 80 | mColliderSphere2->getMaterial().setMassDensity(2); |
| 81 | body->updateMassPropertiesFromColliders(); |
| 82 | mBody = body; |
| 83 | |
| 84 | mTransformMatrix = mTransformMatrix * mScalingMatrix; |
| 85 | |
| 86 | // Create the VBOs and VAO |
| 87 | if (totalNbDumbbells == 0) { |
| 88 | createVBOAndVAO(); |
| 89 | } |
| 90 | |
| 91 | totalNbDumbbells++; |
| 92 | } |
| 93 | |
| 94 | // Destructor |
nothing calls this directly
no test coverage detected