diff --git a/testbed/common/Box.cpp b/testbed/common/Box.cpp index 0720799e..09dc388e 100644 --- a/testbed/common/Box.cpp +++ b/testbed/common/Box.cpp @@ -39,13 +39,8 @@ int Box::totalNbBoxes = 0; // Constructor Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position, - reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cube.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) + : PhysicsObject(meshFolderPath + "cube.obj") { // Initialize the size of the box mSize[0] = size.x * 0.5f; @@ -93,7 +88,8 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p // Constructor Box::Box(const openglframework::Vector3& size, const openglframework::Vector3& position, - float mass, reactphysics3d::DynamicsWorld* world, const std::string& meshFolderPath) { + float mass, reactphysics3d::DynamicsWorld* world, const std::string& meshFolderPath) + : PhysicsObject(meshFolderPath + "cube.obj") { // Load the mesh from a file openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cube.obj", *this); @@ -284,24 +280,6 @@ void Box::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Box::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Box::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Box.h b/testbed/common/Box.h index 0c21be36..a1f05d5e 100644 --- a/testbed/common/Box.h +++ b/testbed/common/Box.h @@ -88,9 +88,6 @@ class Box : public PhysicsObject { /// Render the cube at the correct position and with the correct orientation void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/Capsule.cpp b/testbed/common/Capsule.cpp index e9ae2b40..413d6eb2 100644 --- a/testbed/common/Capsule.cpp +++ b/testbed/common/Capsule.cpp @@ -37,13 +37,7 @@ int Capsule::totalNbCapsules = 0; Capsule::Capsule(float radius, float height, const openglframework::Vector3& position, reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "capsule.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "capsule.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -86,13 +80,7 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3& pos Capsule::Capsule(float radius, float height, const openglframework::Vector3& position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "capsule.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "capsule.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -272,24 +260,6 @@ void Capsule::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Capsule::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Capsule::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Capsule.h b/testbed/common/Capsule.h index 2a97b14b..f117984f 100644 --- a/testbed/common/Capsule.h +++ b/testbed/common/Capsule.h @@ -97,9 +97,6 @@ class Capsule : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/ConcaveMesh.cpp b/testbed/common/ConcaveMesh.cpp index 2f0360ba..608e0020 100644 --- a/testbed/common/ConcaveMesh.cpp +++ b/testbed/common/ConcaveMesh.cpp @@ -30,16 +30,10 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, reactphysics3d::CollisionWorld* world, const std::string& meshPath) - : mVBOVertices(GL_ARRAY_BUFFER), + : PhysicsObject(meshPath), mVBOVertices(GL_ARRAY_BUFFER), mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) { - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this); - - // Calculate the normals of the mesh - calculateNormals(); - // Initialize the position where the sphere will be rendered translateWorld(position); @@ -87,16 +81,10 @@ ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, ConcaveMesh::ConcaveMesh(const openglframework::Vector3 &position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshPath) - : mVBOVertices(GL_ARRAY_BUFFER), + : PhysicsObject(meshPath), mVBOVertices(GL_ARRAY_BUFFER), mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) { - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this); - - // Calculate the normals of the mesh - calculateNormals(); - // Initialize the position where the sphere will be rendered translateWorld(position); @@ -285,24 +273,6 @@ void ConcaveMesh::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void ConcaveMesh::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void ConcaveMesh::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/ConcaveMesh.h b/testbed/common/ConcaveMesh.h index e4b33308..afda3d45 100644 --- a/testbed/common/ConcaveMesh.h +++ b/testbed/common/ConcaveMesh.h @@ -90,9 +90,6 @@ class ConcaveMesh : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/Cone.cpp b/testbed/common/Cone.cpp index 96f52c54..bbd32ed9 100644 --- a/testbed/common/Cone.cpp +++ b/testbed/common/Cone.cpp @@ -37,13 +37,7 @@ int Cone::totalNbCones = 0; Cone::Cone(float radius, float height, const openglframework::Vector3 &position, reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cone.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "cone.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -85,13 +79,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, Cone::Cone(float radius, float height, const openglframework::Vector3 &position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cone.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "cone.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -269,24 +257,6 @@ void Cone::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Cone::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Cone::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Cone.h b/testbed/common/Cone.h index 6fc35182..8f71493c 100644 --- a/testbed/common/Cone.h +++ b/testbed/common/Cone.h @@ -96,9 +96,6 @@ class Cone : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/ConvexMesh.cpp b/testbed/common/ConvexMesh.cpp index c107724f..7842c529 100644 --- a/testbed/common/ConvexMesh.cpp +++ b/testbed/common/ConvexMesh.cpp @@ -30,16 +30,10 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, reactphysics3d::CollisionWorld* world, const std::string& meshPath) - : mVBOVertices(GL_ARRAY_BUFFER), + : PhysicsObject(meshPath), mVBOVertices(GL_ARRAY_BUFFER), mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) { - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this); - - // Calculate the normals of the mesh - calculateNormals(); - // Initialize the position where the sphere will be rendered translateWorld(position); @@ -81,16 +75,10 @@ ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshPath) - : mVBOVertices(GL_ARRAY_BUFFER), + : PhysicsObject(meshPath), mVBOVertices(GL_ARRAY_BUFFER), mVBONormals(GL_ARRAY_BUFFER), mVBOTextureCoords(GL_ARRAY_BUFFER), mVBOIndices(GL_ELEMENT_ARRAY_BUFFER) { - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this); - - // Calculate the normals of the mesh - calculateNormals(); - // Initialize the position where the sphere will be rendered translateWorld(position); @@ -266,24 +254,6 @@ void ConvexMesh::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void ConvexMesh::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void ConvexMesh::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/ConvexMesh.h b/testbed/common/ConvexMesh.h index 19b39220..b6cb90c1 100644 --- a/testbed/common/ConvexMesh.h +++ b/testbed/common/ConvexMesh.h @@ -89,9 +89,6 @@ class ConvexMesh : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/Cylinder.cpp b/testbed/common/Cylinder.cpp index 9b520d5c..2943c3e8 100644 --- a/testbed/common/Cylinder.cpp +++ b/testbed/common/Cylinder.cpp @@ -37,13 +37,7 @@ int Cylinder::totalNbCylinders = 0; Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& position, reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cylinder.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "cylinder.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -85,13 +79,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& p Cylinder::Cylinder(float radius, float height, const openglframework::Vector3& position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath) - : mRadius(radius), mHeight(height) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cylinder.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "cylinder.obj"), mRadius(radius), mHeight(height) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -270,24 +258,6 @@ void Cylinder::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Cylinder::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != nullptr) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Cylinder::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Cylinder.h b/testbed/common/Cylinder.h index 4aab2dc9..3a94b443 100644 --- a/testbed/common/Cylinder.h +++ b/testbed/common/Cylinder.h @@ -96,9 +96,6 @@ class Cylinder : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/Dumbbell.cpp b/testbed/common/Dumbbell.cpp index 770f8ec1..03afd59b 100644 --- a/testbed/common/Dumbbell.cpp +++ b/testbed/common/Dumbbell.cpp @@ -35,13 +35,8 @@ int Dumbbell::totalNbDumbbells = 0; // Constructor Dumbbell::Dumbbell(const openglframework::Vector3 &position, - reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "dumbbell.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + reactphysics3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath) + : PhysicsObject(meshFolderPath + "dumbbell.obj") { // Identity scaling matrix mScalingMatrix.setToIdentity(); @@ -105,13 +100,8 @@ Dumbbell::Dumbbell(const openglframework::Vector3 &position, // Constructor Dumbbell::Dumbbell(const openglframework::Vector3 &position, - reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "dumbbell.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) + : PhysicsObject(meshFolderPath + "dumbbell.obj"){ // Identity scaling matrix mScalingMatrix.setToIdentity(); @@ -309,24 +299,6 @@ void Dumbbell::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Dumbbell::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != NULL) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Dumbbell::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Dumbbell.h b/testbed/common/Dumbbell.h index 5ce3ec95..81020935 100644 --- a/testbed/common/Dumbbell.h +++ b/testbed/common/Dumbbell.h @@ -97,9 +97,6 @@ class Dumbbell : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/HeightField.cpp b/testbed/common/HeightField.cpp index 55da4e1d..377cab07 100644 --- a/testbed/common/HeightField.cpp +++ b/testbed/common/HeightField.cpp @@ -328,24 +328,6 @@ void HeightField::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void HeightField::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != NULL) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void HeightField::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/HeightField.h b/testbed/common/HeightField.h index d9851992..acb39163 100644 --- a/testbed/common/HeightField.h +++ b/testbed/common/HeightField.h @@ -103,9 +103,6 @@ class HeightField : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/common/PhysicsObject.cpp b/testbed/common/PhysicsObject.cpp index c69f9485..acba8e67 100644 --- a/testbed/common/PhysicsObject.cpp +++ b/testbed/common/PhysicsObject.cpp @@ -33,6 +33,16 @@ PhysicsObject::PhysicsObject() : openglframework::Mesh() { mSleepingColor = openglframework::Color(1, 0, 0, 1); } +/// Constructor +PhysicsObject::PhysicsObject(const std::string& meshPath) : PhysicsObject() { + + // Load the mesh from a file + openglframework::MeshReaderWriter::loadMeshFromFile(meshPath, *this); + + // Calculate the normals of the mesh + calculateNormals(); +} + // Compute the new transform matrix openglframework::Matrix4 PhysicsObject::computeTransform(float interpolationFactor, const openglframework::Matrix4& scalingMatrix) { @@ -57,3 +67,21 @@ openglframework::Matrix4 PhysicsObject::computeTransform(float interpolationFact // Apply the scaling matrix to have the correct box dimensions return newMatrix * scalingMatrix; } + +// Reset the transform +void PhysicsObject::resetTransform(const rp3d::Transform& transform) { + + // Reset the transform + mBody->setTransform(transform); + + mBody->setIsSleeping(false); + + // Reset the velocity of the rigid body + rp3d::RigidBody* rigidBody = dynamic_cast(mBody); + if (rigidBody != nullptr) { + rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); + rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); + } + + updateTransform(1.0f); +} diff --git a/testbed/common/PhysicsObject.h b/testbed/common/PhysicsObject.h index bc470091..15f5cf80 100644 --- a/testbed/common/PhysicsObject.h +++ b/testbed/common/PhysicsObject.h @@ -56,6 +56,9 @@ class PhysicsObject : public openglframework::Mesh { /// Constructor PhysicsObject(); + /// Constructor + PhysicsObject(const std::string& meshPath); + /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor)=0; @@ -65,6 +68,9 @@ class PhysicsObject : public openglframework::Mesh { /// Set the sleeping color of the box void setSleepingColor(const openglframework::Color& color); + /// Set the position of the box + void resetTransform(const rp3d::Transform& transform); + /// Return a pointer to the collision body of the box reactphysics3d::CollisionBody* getCollisionBody(); diff --git a/testbed/common/Sphere.cpp b/testbed/common/Sphere.cpp index 93c48af2..9eaf62c2 100644 --- a/testbed/common/Sphere.cpp +++ b/testbed/common/Sphere.cpp @@ -37,13 +37,7 @@ int Sphere::totalNbSpheres = 0; Sphere::Sphere(float radius, const openglframework::Vector3 &position, reactphysics3d::CollisionWorld* world, const std::string& meshFolderPath) - : mRadius(radius) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "sphere.obj"), mRadius(radius) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -86,13 +80,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, Sphere::Sphere(float radius, const openglframework::Vector3 &position, float mass, reactphysics3d::DynamicsWorld* world, const std::string& meshFolderPath) - : mRadius(radius) { - - // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", *this); - - // Calculate the normals of the mesh - calculateNormals(); + : PhysicsObject(meshFolderPath + "sphere.obj"), mRadius(radius) { // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, @@ -270,24 +258,6 @@ void Sphere::createVBOAndVAO() { mVAO.unbind(); } -// Reset the transform -void Sphere::resetTransform(const rp3d::Transform& transform) { - - // Reset the transform - mBody->setTransform(transform); - - mBody->setIsSleeping(false); - - // Reset the velocity of the rigid body - rp3d::RigidBody* rigidBody = dynamic_cast(mBody); - if (rigidBody != NULL) { - rigidBody->setLinearVelocity(rp3d::Vector3(0, 0, 0)); - rigidBody->setAngularVelocity(rp3d::Vector3(0, 0, 0)); - } - - updateTransform(1.0f); -} - // Set the scaling of the object void Sphere::setScaling(const openglframework::Vector3& scaling) { diff --git a/testbed/common/Sphere.h b/testbed/common/Sphere.h index d941d984..62f1809e 100644 --- a/testbed/common/Sphere.h +++ b/testbed/common/Sphere.h @@ -93,9 +93,6 @@ class Sphere : public PhysicsObject { void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix, bool wireframe); - /// Set the position of the box - void resetTransform(const rp3d::Transform& transform); - /// Update the transform matrix of the object virtual void updateTransform(float interpolationFactor) override; diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.h b/testbed/scenes/collisiondetection/CollisionDetectionScene.h index d77cee7f..06b426fe 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.h +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.h @@ -27,7 +27,6 @@ #define COLLISION_DETECTION_SCENE_H // Libraries -#define _USE_MATH_DEFINES #include #include "openglframework.h" #include "reactphysics3d.h"