Constructor
| 35 | |
| 36 | // Constructor |
| 37 | Sphere::Sphere(rp3d::BodyType type, bool isSimulationCollider, float radius, rp3d::PhysicsCommon& physicsCommon, rp3d::PhysicsWorld* world, |
| 38 | const std::string& meshFolderPath) |
| 39 | : PhysicsObject(physicsCommon, meshFolderPath + "sphere.obj"), mRadius(radius), mPhysicsWorld(world) { |
| 40 | |
| 41 | // Compute the scaling matrix |
| 42 | mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, |
| 43 | 0, mRadius, 0, 0, |
| 44 | 0, 0, mRadius, 0, |
| 45 | 0, 0, 0, 1); |
| 46 | |
| 47 | // Create the collision shape for the rigid body (sphere shape) |
| 48 | // ReactPhysics3D will clone this object to create an internal one. Therefore, |
| 49 | // it is OK if this object is destroyed right after calling RigidBody::addCollisionShape() |
| 50 | mCollisionShape = mPhysicsCommon.createSphereShape(mRadius); |
| 51 | |
| 52 | mPreviousTransform = rp3d::Transform::identity(); |
| 53 | |
| 54 | // Create a rigid body corresponding to the sphere in the physics world |
| 55 | rp3d::RigidBody* body = world->createRigidBody(mPreviousTransform); |
| 56 | body->setType(type); |
| 57 | body->setIsDebugEnabled(true); |
| 58 | mCollider = body->addCollider(mCollisionShape, 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 (totalNbSpheres == 0) { |
| 67 | createVBOAndVAO(); |
| 68 | } |
| 69 | |
| 70 | totalNbSpheres++; |
| 71 | } |
| 72 | |
| 73 | // Destructor |
| 74 | Sphere::~Sphere() { |
nothing calls this directly
no test coverage detected