diff --git a/testbed/common/PhysicsObject.cpp b/testbed/common/PhysicsObject.cpp index acba8e67..9955725c 100644 --- a/testbed/common/PhysicsObject.cpp +++ b/testbed/common/PhysicsObject.cpp @@ -69,7 +69,7 @@ openglframework::Matrix4 PhysicsObject::computeTransform(float interpolationFact } // Reset the transform -void PhysicsObject::resetTransform(const rp3d::Transform& transform) { +void PhysicsObject::setTransform(const rp3d::Transform& transform) { // Reset the transform mBody->setTransform(transform); diff --git a/testbed/common/PhysicsObject.h b/testbed/common/PhysicsObject.h index 15f5cf80..0da224c3 100644 --- a/testbed/common/PhysicsObject.h +++ b/testbed/common/PhysicsObject.h @@ -68,8 +68,11 @@ 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); + /// Get the transform + const rp3d::Transform& getTransform() const; + + /// Set the transform + void setTransform(const rp3d::Transform& transform); /// Return a pointer to the collision body of the box reactphysics3d::CollisionBody* getCollisionBody(); @@ -91,6 +94,11 @@ inline void PhysicsObject::setSleepingColor(const openglframework::Color& color) mSleepingColor = color; } +// Get the transform +inline const rp3d::Transform& PhysicsObject::getTransform() const { + return mBody->getTransform(); +} + // Return a pointer to the collision body of the box inline rp3d::CollisionBody* PhysicsObject::getCollisionBody() { return mBody; diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp index 09544540..8aae0145 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp @@ -54,8 +54,7 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name) // Create a sphere and a corresponding collision body in the dynamics world mSphere1 = new Sphere(6, position1, mCollisionWorld, mMeshFolderPath); - mAllShapesObjects.push_back(mSphere1); - mAllShapesPhysicsObjects.push_back(mSphere1); + mAllShapes.push_back(mSphere1); // Set the color mSphere1->setColor(mGreyColorDemo); @@ -66,8 +65,7 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name) // Create a sphere and a corresponding collision body in the dynamics world mSphere2 = new Sphere(4, position2, mCollisionWorld, mMeshFolderPath); - mAllShapesObjects.push_back(mSphere2); - mAllShapesPhysicsObjects.push_back(mSphere2); + mAllShapes.push_back(mSphere2); // Set the color mSphere2->setColor(mGreyColorDemo); @@ -139,7 +137,7 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name) // Create the VBO and VAO to render the lines createVBOAndVAO(mPhongShader); - mAllShapesPhysicsObjects[mSelectedShapeIndex]->setColor(mBlueColorDemo); + mAllShapes[mSelectedShapeIndex]->setColor(mBlueColorDemo); } // Reset the scene @@ -332,12 +330,12 @@ void CollisionDetectionScene::selectNextShape() { int previousIndex = mSelectedShapeIndex; mSelectedShapeIndex++; - if (mSelectedShapeIndex >= mAllShapesPhysicsObjects.size()) { + if (mSelectedShapeIndex >= mAllShapes.size()) { mSelectedShapeIndex = 0; } - mAllShapesPhysicsObjects[previousIndex]->setColor(mGreyColorDemo); - mAllShapesPhysicsObjects[mSelectedShapeIndex]->setColor(mBlueColorDemo); + mAllShapes[previousIndex]->setColor(mGreyColorDemo); + mAllShapes[mSelectedShapeIndex]->setColor(mBlueColorDemo); } // Called when a keyboard event occurs @@ -349,10 +347,68 @@ bool CollisionDetectionScene::keyboardEvent(int key, int scancode, int action, i return true; } + float stepDist = 0.5f; + float stepAngle = 20 * (3.14f / 180.0f); + if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS) { - rp3d::Transform transform = mAllShapesPhysicsObjects[mSelectedShapeIndex]->getCollisionBody()->getTransform(); - transform.setPosition(transform.getPosition() + rp3d::Vector3(1, 0, 0)); - mAllShapesObjects[mSelectedShapeIndex]->translateWorld(openglframework::Vector3(1, 0, 0)); + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(stepDist, 0, 0)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_LEFT && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(-stepDist, 0, 0)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_UP && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(0, stepDist, 0)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_DOWN && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(0, -stepDist, 0)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_Z && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(0, 0, stepDist)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_H && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setPosition(transform.getPosition() + rp3d::Vector3(0, 0, -stepDist)); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_A && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(0, stepAngle, 0) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_D && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(0, -stepAngle, 0) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_W && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(stepAngle, 0, 0) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_S && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(-stepAngle, 0, 0) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_F && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(0, 0, stepAngle) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); + } + else if (key == GLFW_KEY_G && action == GLFW_PRESS) { + rp3d::Transform transform = mAllShapes[mSelectedShapeIndex]->getTransform(); + transform.setOrientation(rp3d::Quaternion(0, 0, -stepAngle) * transform.getOrientation()); + mAllShapes[mSelectedShapeIndex]->setTransform(transform); } return false; diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.h b/testbed/scenes/collisiondetection/CollisionDetectionScene.h index 06b426fe..b7f57c1d 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.h +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.h @@ -146,8 +146,7 @@ class CollisionDetectionScene : public SceneDemo { //ConcaveMesh* mConcaveMesh; //HeightField* mHeightField; - std::vector mAllShapesObjects; - std::vector mAllShapesPhysicsObjects; + std::vector mAllShapes; int mSelectedShapeIndex; diff --git a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp index e146bd6b..8db4908a 100644 --- a/testbed/scenes/collisionshapes/CollisionShapesScene.cpp +++ b/testbed/scenes/collisionshapes/CollisionShapesScene.cpp @@ -524,7 +524,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mDumbbells[i]->resetTransform(transform); + mDumbbells[i]->setTransform(transform); } // Create all the boxes of the scene @@ -542,7 +542,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mBoxes[i]->resetTransform(transform); + mBoxes[i]->setTransform(transform); } // Create all the spheres of the scene @@ -560,7 +560,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mSpheres[i]->resetTransform(transform); + mSpheres[i]->setTransform(transform); } // Create all the cones of the scene @@ -578,7 +578,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mCones[i]->resetTransform(transform); + mCones[i]->setTransform(transform); } // Create all the cylinders of the scene @@ -596,7 +596,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mCylinders[i]->resetTransform(transform); + mCylinders[i]->setTransform(transform); } // Create all the capsules of the scene @@ -614,7 +614,7 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mCapsules[i]->resetTransform(transform); + mCapsules[i]->setTransform(transform); } // Create all the convex meshes of the scene @@ -632,6 +632,6 @@ void CollisionShapesScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Reset the transform - mConvexMeshes[i]->resetTransform(transform); + mConvexMeshes[i]->setTransform(transform); } } diff --git a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp index 9b65893e..11474819 100644 --- a/testbed/scenes/concavemesh/ConcaveMeshScene.cpp +++ b/testbed/scenes/concavemesh/ConcaveMeshScene.cpp @@ -175,7 +175,7 @@ void ConcaveMeshScene::reset() { // Reset the transform rp3d::Transform transform(rp3d::Vector3::zero(), rp3d::Quaternion::identity()); - mConcaveMesh->resetTransform(transform); + mConcaveMesh->setTransform(transform); for (int i=0; iresetTransform(boxTransform); + mBoxes[i * NB_BOXES_Z + j]->setTransform(boxTransform); } } diff --git a/testbed/scenes/heightfield/HeightFieldScene.cpp b/testbed/scenes/heightfield/HeightFieldScene.cpp index 5b62f614..3e4061c9 100644 --- a/testbed/scenes/heightfield/HeightFieldScene.cpp +++ b/testbed/scenes/heightfield/HeightFieldScene.cpp @@ -171,13 +171,13 @@ void HeightFieldScene::reset() { // Reset the transform rp3d::Transform transform(rp3d::Vector3(0, 0, 0), rp3d::Quaternion::identity()); - mHeightField->resetTransform(transform); + mHeightField->setTransform(transform); float heightFieldWidth = 10.0f; float stepDist = heightFieldWidth / (NB_BOXES + 1); for (int i=0; iresetTransform(boxTransform); + mBoxes[i]->setTransform(boxTransform); } } diff --git a/testbed/scenes/joints/JointsScene.cpp b/testbed/scenes/joints/JointsScene.cpp index 34bb1503..23bcdb93 100644 --- a/testbed/scenes/joints/JointsScene.cpp +++ b/testbed/scenes/joints/JointsScene.cpp @@ -193,7 +193,7 @@ void JointsScene::reset() { rp3d::Transform transform(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mBallAndSocketJointChainBoxes[i]->resetTransform(transform); + mBallAndSocketJointChainBoxes[i]->setTransform(transform); positionBox.y -= boxDimension.y + 0.5f; } @@ -207,7 +207,7 @@ void JointsScene::reset() { rp3d::Transform transformBottomBox(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mSliderJointBottomBox->resetTransform(transformBottomBox); + mSliderJointBottomBox->setTransform(transformBottomBox); // Position of the box openglframework::Vector3 positionBox2(0, 4.2f, 0); @@ -216,7 +216,7 @@ void JointsScene::reset() { rp3d::Transform transformTopBox(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mSliderJointTopBox->resetTransform(transformTopBox); + mSliderJointTopBox->setTransform(transformTopBox); // --------------- Propeller Hinge joint --------------- // @@ -227,7 +227,7 @@ void JointsScene::reset() { rp3d::Transform transformHingeBox(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mPropellerBox->resetTransform(transformHingeBox); + mPropellerBox->setTransform(transformHingeBox); // --------------- Fixed joint --------------- // @@ -238,7 +238,7 @@ void JointsScene::reset() { rp3d::Transform transformFixedBox1(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mFixedJointBox1->resetTransform(transformFixedBox1); + mFixedJointBox1->setTransform(transformFixedBox1); // Position of the box positionBox2 = openglframework::Vector3(-5, 7, 0); @@ -247,7 +247,7 @@ void JointsScene::reset() { rp3d::Transform transformFixedBox2(initPosition, initOrientation); // Create a box and a corresponding rigid in the dynamics world - mFixedJointBox2->resetTransform(transformFixedBox2); + mFixedJointBox2->setTransform(transformFixedBox2); } // Create the boxes and joints for the Ball-and-Socket joint example diff --git a/testbed/src/TestbedApplication.h b/testbed/src/TestbedApplication.h index 93d85ea7..8790a1f7 100644 --- a/testbed/src/TestbedApplication.h +++ b/testbed/src/TestbedApplication.h @@ -162,12 +162,6 @@ class TestbedApplication : public Screen { /// Set the variable to know if we need to take a single physics step void toggleTakeSinglePhysicsStep(); - /// Enable/Disable shadow mapping - void enableShadows(bool enable); - - /// Display/Hide contact points - void displayContactPoints(bool display); - public : // -------------------- Methods -------------------- // @@ -252,16 +246,6 @@ inline void TestbedApplication::toggleTakeSinglePhysicsStep() { } } -// Enable/Disable shadow mapping -inline void TestbedApplication::enableShadows(bool enable) { - mIsShadowMappingEnabled = enable; -} - -/// Display/Hide contact points -inline void TestbedApplication::displayContactPoints(bool display) { - mIsContactPointsDisplayed = display; -} - // Enable/Disable Vertical synchronization inline void TestbedApplication::enableVSync(bool enable) { mIsVSyncEnabled = enable;