Constructor
| 35 | |
| 36 | // Constructor |
| 37 | Capsule::Capsule(reactphysics3d::BodyType type, bool isSimulationCollider, float radius, float height, reactphysics3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* physicsWorld, |
| 38 | const std::string& meshFolderPath) |
| 39 | : PhysicsObject(physicsCommon, meshFolderPath + "capsule.obj"), mRadius(radius), mHeight(height), mPhysicsWorld(physicsWorld) { |
| 40 | |
| 41 | // Compute the scaling matrix |
| 42 | mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, |
| 43 | 0, (mHeight + 2.0f * mRadius) / 3.0f, 0,0, |
| 44 | 0, 0, mRadius, 0, |
| 45 | 0, 0, 0, 1.0f); |
| 46 | |
| 47 | mPreviousTransform = rp3d::Transform::identity(); |
| 48 | |
| 49 | // Create the collision shape for the rigid body (sphere shape) |
| 50 | // ReactPhysics3D will clone this object to create an internal one. Therefore, |
| 51 | // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() |
| 52 | mCapsuleShape = mPhysicsCommon.createCapsuleShape(mRadius, mHeight); |
| 53 | |
| 54 | // Create the body |
| 55 | rp3d::RigidBody* body = physicsWorld->createRigidBody(mPreviousTransform); |
| 56 | body->setType(type); |
| 57 | body->setIsDebugEnabled(true); |
| 58 | mCollider = body->addCollider(mCapsuleShape, rp3d::Transform::identity()); |
| 59 | mCollider->setIsSimulationCollider(isSimulationCollider); |
| 60 | body->updateMassPropertiesFromColliders(); |
| 61 | mBody = body; |
| 62 | |
| 63 | mTransformMatrix = mTransformMatrix * mScalingMatrix; |
| 64 | |
| 65 | // Create the VBOs and VAO |
| 66 | if (totalNbCapsules == 0) { |
| 67 | createVBOAndVAO(); |
| 68 | } |
| 69 | |
| 70 | totalNbCapsules++; |
| 71 | } |
| 72 | |
| 73 | // Destructor |
| 74 | Capsule::~Capsule() { |
nothing calls this directly
no test coverage detected