From 678c88d3bd5be850a3ec354e742b8002363120e6 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Tue, 16 May 2017 07:11:18 +0200 Subject: [PATCH] Add box in collision detection scene for the testbed application --- .../CollisionDetectionScene.cpp | 20 +++++++++++++++++++ .../CollisionDetectionScene.h | 1 + 2 files changed, 21 insertions(+) diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp index 8c0196b3..b96620b6 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.cpp @@ -60,6 +60,7 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name) mSphere1->setColor(mGreyColorDemo); mSphere1->setSleepingColor(mRedColorDemo); + /* // ---------- Sphere 2 ---------- // openglframework::Vector3 position2(4, 0, 0); @@ -92,6 +93,17 @@ CollisionDetectionScene::CollisionDetectionScene(const std::string& name) // Set the color mCapsule2->setColor(mGreyColorDemo); mCapsule2->setSleepingColor(mRedColorDemo); +*/ + // ---------- Box 1 ---------- // + openglframework::Vector3 position5(4, 5, 0); + + // Create a box and a corresponding collision body in the dynamics world + mBox1 = new Box(BOX_SIZE, position5, mCollisionWorld, mMeshFolderPath); + mAllShapes.push_back(mBox1); + + // Set the color + mBox1->setColor(mGreyColorDemo); + mBox1->setSleepingColor(mRedColorDemo); // ---------- Cone ---------- // //openglframework::Vector3 position4(0, 0, 0); @@ -171,6 +183,7 @@ CollisionDetectionScene::~CollisionDetectionScene() { mCollisionWorld->destroyCollisionBody(mSphere1->getCollisionBody()); delete mSphere1; + /* mCollisionWorld->destroyCollisionBody(mSphere2->getCollisionBody()); delete mSphere2; @@ -179,6 +192,10 @@ CollisionDetectionScene::~CollisionDetectionScene() { mCollisionWorld->destroyCollisionBody(mCapsule2->getCollisionBody()); delete mCapsule2; + */ + + mCollisionWorld->destroyCollisionBody(mBox1->getCollisionBody()); + delete mBox1; /* // Destroy the corresponding rigid body from the dynamics world @@ -300,9 +317,12 @@ void CollisionDetectionScene::renderSinglePass(openglframework::Shader& shader, // Render the shapes if (mSphere1->getCollisionBody()->isActive()) mSphere1->render(shader, worldToCameraMatrix, mIsWireframeEnabled); + /* if (mSphere2->getCollisionBody()->isActive()) mSphere2->render(shader, worldToCameraMatrix, mIsWireframeEnabled); if (mCapsule1->getCollisionBody()->isActive()) mCapsule1->render(shader, worldToCameraMatrix, mIsWireframeEnabled); if (mCapsule2->getCollisionBody()->isActive()) mCapsule2->render(shader, worldToCameraMatrix, mIsWireframeEnabled); + */ + if (mBox1->getCollisionBody()->isActive()) mBox1->render(shader, worldToCameraMatrix, mIsWireframeEnabled); /* if (mBox->getCollisionBody()->isActive()) mBox->render(shader, worldToCameraMatrix); diff --git a/testbed/scenes/collisiondetection/CollisionDetectionScene.h b/testbed/scenes/collisiondetection/CollisionDetectionScene.h index 2c33b3ac..01df3df8 100644 --- a/testbed/scenes/collisiondetection/CollisionDetectionScene.h +++ b/testbed/scenes/collisiondetection/CollisionDetectionScene.h @@ -146,6 +146,7 @@ class CollisionDetectionScene : public SceneDemo { Sphere* mSphere2; Capsule* mCapsule1; Capsule* mCapsule2; + Box* mBox1; //Cone* mCone; //Cylinder* mCylinder; //Capsule* mCapsule;