From f575a46fdded59e66cb70ba5c9554c62e096cb06 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Tue, 10 Sep 2013 21:53:34 +0200 Subject: [PATCH] Modification of the examples --- examples/CMakeLists.txt | 4 +-- examples/common/Box.cpp | 29 ++++++++++------ examples/common/Box.h | 6 ++++ examples/common/Capsule.cpp | 6 ++-- examples/common/Cone.cpp | 2 +- examples/common/Cylinder.cpp | 2 +- examples/common/Sphere.cpp | 2 +- examples/common/Viewer.cpp | 2 +- .../common/opengl-framework/CMakeLists.txt | 24 ++++++++++---- examples/common/opengl-framework/src/Mesh.cpp | 1 - examples/common/opengl-framework/src/Mesh.h | 2 +- .../opengl-framework/src/MeshReaderWriter.cpp | 8 ++--- .../opengl-framework/src/MeshReaderWriter.h | 8 ++--- .../common/opengl-framework/src/Texture2D.cpp | 2 +- .../common/opengl-framework/src/Texture2D.h | 2 +- .../src/TextureReaderWriter.cpp | 33 ++++++++++--------- .../src/TextureReaderWriter.h | 20 ++++------- .../common/opengl-framework/src/maths/Color.h | 2 +- .../opengl-framework/src/shaders/phong.frag | 6 ++-- examples/cubes/CMakeLists.txt | 6 ++-- examples/cubes/Cubes.cpp | 2 +- examples/cubes/Scene.cpp | 16 +++++++-- examples/cubes/Scene.h | 7 ++-- examples/joints/Scene.cpp | 10 +++--- examples/joints/Scene.h | 2 +- 25 files changed, 116 insertions(+), 88 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e8d6a1d6..6399abeb 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,6 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) add_subdirectory(common/) -add_subdirectory(fallingcubes/) +add_subdirectory(cubes/) add_subdirectory(joints/) -add_subdirectory(convexmesh/) +add_subdirectory(collisionshapes/) diff --git a/examples/common/Box.cpp b/examples/common/Box.cpp index 34fb6597..757a3127 100644 --- a/examples/common/Box.cpp +++ b/examples/common/Box.cpp @@ -34,14 +34,14 @@ openglframework::VertexBufferObject Box::mVBOVertices(GL_ARRAY_BUFFER); openglframework::VertexBufferObject Box::mVBOIndices(GL_ELEMENT_ARRAY_BUFFER); bool Box::areVBOsCreated = false; VertexData Box::mCubeVertices[8] = { - {openglframework::Vector3(1,1,1),openglframework::Vector3(1,1,1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(-1,1,1),openglframework::Vector3(-1,1,1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(-1,-1,1),openglframework::Vector3(-1,-1,1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(1,-1,1),openglframework::Vector3(1,-1,1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(1,-1,-1),openglframework::Vector3(1,-1,-1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(-1,-1,-1),openglframework::Vector3(-1,-1,-1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(-1,1,-1),openglframework::Vector3(-1,1,-1),openglframework::Color(0,0,1,1)}, - {openglframework::Vector3(1,1,-1),openglframework::Vector3(1,1,-1),openglframework::Color(0,0,1,1)} + {openglframework::Vector3(1,1,1),openglframework::Vector3(1,1,1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(-1,1,1),openglframework::Vector3(-1,1,1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(-1,-1,1),openglframework::Vector3(-1,-1,1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(1,-1,1),openglframework::Vector3(1,-1,1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(1,-1,-1),openglframework::Vector3(1,-1,-1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(-1,-1,-1),openglframework::Vector3(-1,-1,-1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(-1,1,-1),openglframework::Vector3(-1,1,-1),openglframework::Color(1,0,0,1)}, + {openglframework::Vector3(1,1,-1),openglframework::Vector3(1,1,-1),openglframework::Color(1,0,0,1)} }; GLuint Box::mCubeIndices[36] = { 0, 1, 2, 2, 3, 0, @@ -59,7 +59,7 @@ GLuint Box::mCubeIndices[36] = { 0, 1, 2, // Constructor Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &position, float mass, reactphysics3d::DynamicsWorld* dynamicsWorld) - : openglframework::Object3D() { + : openglframework::Object3D(), mColor(0.5f, 0.5f, 0.5f, 1.0f) { // Initialize the size of the box mSize[0] = size.x * 0.5f; @@ -77,7 +77,7 @@ Box::Box(const openglframework::Vector3& size, const openglframework::Vector3 &p // Create the collision shape for the rigid body (box shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroy right after calling Dynamics::createRigidBody() + // it is OK if this object is destroyed right after calling Dynamics::createRigidBody() const rp3d::BoxShape collisionShape(rp3d::Vector3(mSize[0], mSize[1], mSize[2])); // Compute the inertia tensor of the body using its collision shape @@ -121,6 +121,10 @@ void Box::render(openglframework::Shader& shader, localToCameraMatrix.getUpperLeft3x3Matrix().getInverse().getTranspose(); shader.setMatrix3x3Uniform("normalMatrix", normalMatrix); + // TODO : REMOVE THIS + openglframework::Vector4 color(mColor.r, mColor.g, mColor.b, mColor.a); + shader.setVector4Uniform("vertexColor", color); + // Bind the vertices VBO mVBOVertices.bind(); @@ -153,6 +157,11 @@ void Box::render(openglframework::Shader& shader, shader.unbind(); } +// Set the color of the box +void Box::setColor(openglframework::Color& color) { + mColor = color; +} + // Update the transform matrix of the box void Box::updateTransform() { diff --git a/examples/common/Box.h b/examples/common/Box.h index 302df1bc..c507ed4c 100644 --- a/examples/common/Box.h +++ b/examples/common/Box.h @@ -74,6 +74,9 @@ class Box : public openglframework::Object3D { /// True if the VBOs have already been created static bool areVBOsCreated; + // TODO : REMOVE THIS + openglframework::Color mColor; + // -------------------- Methods -------------------- // /// Create a Vertex Buffer Object to render to box with OpenGL @@ -98,6 +101,9 @@ class Box : public openglframework::Object3D { /// Render the cube at the correct position and with the correct orientation void render(openglframework::Shader& shader, const openglframework::Matrix4& worldToCameraMatrix); + + /// Set the color of the box + void setColor(openglframework::Color& color); }; // Return a pointer to the rigid body of the box diff --git a/examples/common/Capsule.cpp b/examples/common/Capsule.cpp index 07216c5e..d069e25f 100644 --- a/examples/common/Capsule.cpp +++ b/examples/common/Capsule.cpp @@ -40,16 +40,16 @@ Capsule::Capsule(float radius, float height, const openglframework::Vector3 &pos // Compute the scaling matrix mScalingMatrix = openglframework::Matrix4(mRadius, 0, 0, 0, - 0, (mHeight + 2.0 * mRadius) / 3.0, 0,0, + 0, (mHeight + 2.0f * mRadius) / 3.0f, 0,0, 0, 0, mRadius, 0, - 0, 0, 0, 1); + 0, 0, 0, 1.0f); // Initialize the position where the sphere will be rendered translateWorld(position); // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroy right after calling Dynamics::createRigidBody() + // it is OK if this object is destroyed right after calling Dynamics::createRigidBody() const rp3d::CapsuleShape collisionShape(mRadius, mHeight); // Compute the inertia tensor of the body using its collision shape diff --git a/examples/common/Cone.cpp b/examples/common/Cone.cpp index ca7e1cbb..6043c5be 100644 --- a/examples/common/Cone.cpp +++ b/examples/common/Cone.cpp @@ -49,7 +49,7 @@ Cone::Cone(float radius, float height, const openglframework::Vector3 &position, // Create the collision shape for the rigid body (cone shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroy right after calling Dynamics::createRigidBody() + // it is OK if this object is destroyed right after calling Dynamics::createRigidBody() const rp3d::ConeShape collisionShape(mRadius, mHeight); // Compute the inertia tensor of the body using its collision shape diff --git a/examples/common/Cylinder.cpp b/examples/common/Cylinder.cpp index 556d413f..b0b089e1 100644 --- a/examples/common/Cylinder.cpp +++ b/examples/common/Cylinder.cpp @@ -49,7 +49,7 @@ Cylinder::Cylinder(float radius, float height, const openglframework::Vector3 &p // Create the collision shape for the rigid body (cylinder shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroy right after calling Dynamics::createRigidBody() + // it is OK if this object is destroyed right after calling Dynamics::createRigidBody() const rp3d::CylinderShape collisionShape(mRadius, mHeight); // Compute the inertia tensor of the body using its collision shape diff --git a/examples/common/Sphere.cpp b/examples/common/Sphere.cpp index f3d20010..4a62b0b1 100644 --- a/examples/common/Sphere.cpp +++ b/examples/common/Sphere.cpp @@ -49,7 +49,7 @@ Sphere::Sphere(float radius, const openglframework::Vector3 &position, // Create the collision shape for the rigid body (sphere shape) // ReactPhysics3D will clone this object to create an internal one. Therefore, - // it is OK if this object is destroy right after calling Dynamics::createRigidBody() + // it is OK if this object is destroyed right after calling Dynamics::createRigidBody() const rp3d::SphereShape collisionShape(mRadius); // Compute the inertia tensor of the body using its collision shape diff --git a/examples/common/Viewer.cpp b/examples/common/Viewer.cpp index 1f99d4dc..e0114f00 100644 --- a/examples/common/Viewer.cpp +++ b/examples/common/Viewer.cpp @@ -48,7 +48,7 @@ void Viewer::computeFPS() { if(timeInterval > 1000){ // calculate the number of frames per second - fps = nbFrames / (timeInterval / 1000.0f); + fps = static_cast(nbFrames / (timeInterval / 1000.0f)); // Set time previousTime = currentTime; diff --git a/examples/common/opengl-framework/CMakeLists.txt b/examples/common/opengl-framework/CMakeLists.txt index 82cba467..7683a289 100644 --- a/examples/common/opengl-framework/CMakeLists.txt +++ b/examples/common/opengl-framework/CMakeLists.txt @@ -4,6 +4,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) # Project configuration PROJECT(OPENGLFRAMEWORK) +# Options +OPTION(USE_JPEG_TEXTURES "Select this if you want to use jpeg textures (libjpeg required)" OFF) + # Where to find the module to find special packages/libraries set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") @@ -23,12 +26,16 @@ else() MESSAGE("GLEW not found") endif() -# Find the LIBJPEG library -FIND_PACKAGE(JPEG REQUIRED) -if(JPEG_FOUND) - MESSAGE("LIBJPEG found") -else() - MESSAGE("LIBJPEG not found") +# If the user wants to use JPEG textures +if(USE_JPEG_TEXTURES) + + # Find the LIBJPEG library + FIND_PACKAGE(JPEG REQUIRED) + if(JPEG_FOUND) + MESSAGE("LIBJPEG found") + else() + MESSAGE("LIBJPEG not found") + endif() endif() # Freeglut @@ -37,6 +44,10 @@ add_subdirectory(freeglut) # Headers INCLUDE_DIRECTORIES(src freeglut ${JPEG_INCLUDE_DIR}) +if(USE_JPEG_TEXTURES) + add_definitions(-DUSE_JPEG_TEXTURE) +endif() + # Library configuration file ( GLOB_RECURSE @@ -44,7 +55,6 @@ file ( src/* ) - # Require the opengl-framework code to be compiled in a static library ADD_LIBRARY ( openglframework diff --git a/examples/common/opengl-framework/src/Mesh.cpp b/examples/common/opengl-framework/src/Mesh.cpp index 6a993539..070c1d07 100644 --- a/examples/common/opengl-framework/src/Mesh.cpp +++ b/examples/common/opengl-framework/src/Mesh.cpp @@ -84,7 +84,6 @@ void Mesh::calculateNormals() { // Normalize the normal at each vertex for (uint i=0; i -#include -#include +#ifdef USE_JPEG_TEXTURE + #include + #include +#endif using namespace openglframework; using namespace std; @@ -59,8 +61,7 @@ typedef struct { // Load a texture from a file void TextureReaderWriter::loadTextureFromFile(const std::string& filename, - Texture2D& textureToCreate) - throw(runtime_error, invalid_argument){ + Texture2D& textureToCreate) { // Get the extension of the file uint startPosExtension = filename.find_last_of("."); @@ -70,9 +71,11 @@ void TextureReaderWriter::loadTextureFromFile(const std::string& filename, if (extension == "tga") { readTGAPicture(filename, textureToCreate); } +#ifdef USE_JPEG_TEXTURE else if (extension == "jpg" || extension == "jpeg"){ readJPEGPicture(filename, textureToCreate); } +#endif else { // Display an error message and throw an exception @@ -84,9 +87,7 @@ void TextureReaderWriter::loadTextureFromFile(const std::string& filename, } // Write a texture to a file -void TextureReaderWriter::writeTextureToFile(const std::string& filename, - const Texture2D& texture) - throw(runtime_error, invalid_argument){ +void TextureReaderWriter::writeTextureToFile(const std::string& filename,const Texture2D& texture) { // Get the extension of the file uint startPosExtension = filename.find_last_of("."); @@ -96,9 +97,11 @@ void TextureReaderWriter::writeTextureToFile(const std::string& filename, if (extension == "tga") { writeTGAPicture(filename, texture); } +#ifdef USE_JPEG_TEXTURE else if (extension == "jpg" || extension == "jpeg"){ writeJPEGPicture(filename, texture); } +#endif else { // Display an error message and throw an exception @@ -110,8 +113,7 @@ void TextureReaderWriter::writeTextureToFile(const std::string& filename, } // Load a TGA picture -void TextureReaderWriter::readTGAPicture(const std::string &filename, - Texture2D& textureToCreate) throw(runtime_error) { +void TextureReaderWriter::readTGAPicture(const std::string &filename, Texture2D& textureToCreate) { // Open the file std::ifstream stream(filename.c_str(), std::ios::binary); @@ -156,8 +158,7 @@ void TextureReaderWriter::readTGAPicture(const std::string &filename, // Write a TGA picture -void TextureReaderWriter::writeTGAPicture(const std::string& filename, - const Texture2D& texture) throw(runtime_error) { +void TextureReaderWriter::writeTGAPicture(const std::string& filename, const Texture2D& texture) { assert(texture.getID() != 0); // Bind the corresponding texture @@ -219,9 +220,10 @@ void TextureReaderWriter::writeTGAPicture(const std::string& filename, glBindTexture(GL_TEXTURE_2D, 0); } +#ifdef USE_JPEG_TEXTURE + // Read a JPEG picture -void TextureReaderWriter::readJPEGPicture(const std::string& filename, - Texture2D& textureToCreate) throw(std::runtime_error) { +void TextureReaderWriter::readJPEGPicture(const std::string& filename, Texture2D& textureToCreate) { struct jpeg_decompress_struct info; struct jpeg_error_mgr error; @@ -276,8 +278,7 @@ void TextureReaderWriter::readJPEGPicture(const std::string& filename, } // Write a JPEG picture -void TextureReaderWriter::writeJPEGPicture(const std::string& filename, - const Texture2D& texture) throw(std::runtime_error) { +void TextureReaderWriter::writeJPEGPicture(const std::string& filename, const Texture2D& texture) { struct jpeg_compress_struct info; struct jpeg_error_mgr error; @@ -327,3 +328,5 @@ void TextureReaderWriter::writeJPEGPicture(const std::string& filename, // Free allocated memory delete[] data; } + +#endif diff --git a/examples/common/opengl-framework/src/TextureReaderWriter.h b/examples/common/opengl-framework/src/TextureReaderWriter.h index 72a50baf..a83b9671 100644 --- a/examples/common/opengl-framework/src/TextureReaderWriter.h +++ b/examples/common/opengl-framework/src/TextureReaderWriter.h @@ -52,34 +52,26 @@ class TextureReaderWriter { TextureReaderWriter(); // Read a TGA picture - static void readTGAPicture(const std::string& filename, - Texture2D& textureToCreate) throw(std::runtime_error); + static void readTGAPicture(const std::string& filename, Texture2D& textureToCreate); // Write a TGA picture - static void writeTGAPicture(const std::string& filename, - const Texture2D& texture) throw(std::runtime_error); + static void writeTGAPicture(const std::string& filename, const Texture2D& texture); // Read a JPEG picture - static void readJPEGPicture(const std::string& filename, - Texture2D& textureToCreate) throw(std::runtime_error); + static void readJPEGPicture(const std::string& filename, Texture2D& textureToCreate); // Write a JPEG picture - static void writeJPEGPicture(const std::string& filename, - const Texture2D& texture) throw(std::runtime_error); + static void writeJPEGPicture(const std::string& filename, const Texture2D& texture); public : // -------------------- Methods -------------------- // // Load a texture from a file - static void loadTextureFromFile(const std::string& filename, - Texture2D& textureToCreate) - throw(std::runtime_error, std::invalid_argument); + static void loadTextureFromFile(const std::string& filename, Texture2D& textureToCreate); // Write a texture to a file - static void writeTextureToFile(const std::string& filename, - const Texture2D& texture) - throw(std::runtime_error, std::invalid_argument); + static void writeTextureToFile(const std::string& filename, const Texture2D& texture); }; } diff --git a/examples/common/opengl-framework/src/maths/Color.h b/examples/common/opengl-framework/src/maths/Color.h index e8ea2c40..a4629f8d 100644 --- a/examples/common/opengl-framework/src/maths/Color.h +++ b/examples/common/opengl-framework/src/maths/Color.h @@ -47,7 +47,7 @@ struct Color { // Constructor Color(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {} - // Constructor + // Copy-constructor Color(const Color& color) : r(color.r), g(color.g), b(color.b), a(color.a) {} // Destructor diff --git a/examples/common/opengl-framework/src/shaders/phong.frag b/examples/common/opengl-framework/src/shaders/phong.frag index 3102de06..009c5cc7 100644 --- a/examples/common/opengl-framework/src/shaders/phong.frag +++ b/examples/common/opengl-framework/src/shaders/phong.frag @@ -31,6 +31,7 @@ uniform vec3 light0SpecularColor; // Light 0 specular color uniform float shininess; // Shininess uniform sampler2D texture; // Texture uniform bool isTexture; // True if we need to use the texture +uniform vec4 vertexColor; // Vertex color // Varying variables varying vec3 vertexPosCameraSpace; // Camera-space position of the vertex @@ -40,10 +41,11 @@ varying vec2 texCoords; // Texture coordinates void main() { // Compute the ambient term - vec3 ambient = lightAmbientColor; + //vec3 ambient = lightAmbientColor; + vec3 ambient = vertexColor.rgb + 0.0 * lightAmbientColor; // Get the texture color - vec3 textureColor = vec3(1); + vec3 textureColor = vertexColor.rgb; if (isTexture) textureColor = texture2D(texture, texCoords).rgb; // Compute the surface normal vector diff --git a/examples/cubes/CMakeLists.txt b/examples/cubes/CMakeLists.txt index a7b5ee34..f65c428a 100644 --- a/examples/cubes/CMakeLists.txt +++ b/examples/cubes/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) # Project configuration -PROJECT(FallingCubes) +PROJECT(Cubes) # Copy the shaders used for the demo into the build directory FILE(COPY "../common/opengl-framework/src/shaders/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/shaders/") @@ -12,6 +12,6 @@ INCLUDE_DIRECTORIES("../common/opengl-framework/src/" "../common/") # Create the example executable using the # compiled reactphysics3d static library -ADD_EXECUTABLE(fallingcubes FallingCubes.cpp Scene.cpp Scene.h "../common/Box.cpp" "../common/Box.h" "../common/Viewer.cpp" "../common/Viewer.h") +ADD_EXECUTABLE(cubes Cubes.cpp Scene.cpp Scene.h "../common/Box.cpp" "../common/Box.h" "../common/Viewer.cpp" "../common/Viewer.h") -TARGET_LINK_LIBRARIES(fallingcubes reactphysics3d openglframework) +TARGET_LINK_LIBRARIES(cubes reactphysics3d openglframework) diff --git a/examples/cubes/Cubes.cpp b/examples/cubes/Cubes.cpp index 54bbfa62..e0dc6ad0 100644 --- a/examples/cubes/Cubes.cpp +++ b/examples/cubes/Cubes.cpp @@ -51,7 +51,7 @@ int main(int argc, char** argv) { viewer = new Viewer(); Vector2 windowsSize = Vector2(800, 600); Vector2 windowsPosition = Vector2(100, 100); - bool initOK = viewer->init(argc, argv, "ReactPhysics3D Examples - Falling Cubes", windowsSize, windowsPosition); + bool initOK = viewer->init(argc, argv, "ReactPhysics3D Examples - Cubes", windowsSize, windowsPosition); if (!initOK) return 1; // Create the scene diff --git a/examples/cubes/Scene.cpp b/examples/cubes/Scene.cpp index dc2082cc..6fc35f68 100644 --- a/examples/cubes/Scene.cpp +++ b/examples/cubes/Scene.cpp @@ -65,12 +65,13 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0), float angle = i * 30.0f; openglframework::Vector3 position(radius * cos(angle), 1 + i * (BOX_SIZE.y + 0.3f), - radius * sin(angle)); + 0); // Create a cube and a corresponding rigid in the dynamics world - Box* cube = new Box(BOX_SIZE, position , CUBE_MASS, mDynamicsWorld); + Box* cube = new Box(BOX_SIZE, position , BOX_MASS, mDynamicsWorld); cube->getRigidBody()->setIsMotionEnabled(true); + mMapBodyToBox.insert(std::make_pair(cube->getRigidBody(), cube)); // Change the material properties of the rigid body rp3d::Material& material = cube->getRigidBody()->getMaterial(); @@ -87,6 +88,8 @@ Scene::Scene(GlutViewer* viewer) : mViewer(viewer), mLight0(0), // The floor must be a non-moving rigid body mFloor->getRigidBody()->setIsMotionEnabled(false); + mMapBodyToBox.insert(std::make_pair(mFloor->getRigidBody(), mFloor)); + // Change the material properties of the floor rigid body rp3d::Material& material = mFloor->getRigidBody()->getMaterial(); material.setBounciness(rp3d::decimal(0.3)); @@ -142,6 +145,15 @@ void Scene::simulate() { mFloor->updateTransform(); + // Set the color of the awake/sleeping bodies + for (uint i=0; igetRigidBody()->isSleeping()) { + mBoxes[i]->setColor(Color(1, 0, 0, 1)); + } + else { + mBoxes[i]->setColor(Color(0, 1, 0, 1)); + } + } } } diff --git a/examples/cubes/Scene.h b/examples/cubes/Scene.h index 45df3c4b..ed2033ef 100644 --- a/examples/cubes/Scene.h +++ b/examples/cubes/Scene.h @@ -34,8 +34,8 @@ // Constants const int NB_SPHERES = 20; // Number of boxes in the scene const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters -const openglframework::Vector3 FLOOR_SIZE(20, 0.5f, 20); // Floor dimensions in meters -const float CUBE_MASS = 1.0f; // Box mass in kilograms +const openglframework::Vector3 FLOOR_SIZE(50, 0.5f, 50); // Floor dimensions in meters +const float BOX_MASS = 1.0f; // Box mass in kilograms const float FLOOR_MASS = 100.0f; // Floor mass in kilograms // Class Scene @@ -66,6 +66,9 @@ class Scene { /// True if the physics simulation is running bool mIsRunning; + // TODO : REMOVE THIS + std::map mMapBodyToBox; + public: // -------------------- Methods -------------------- // diff --git a/examples/joints/Scene.cpp b/examples/joints/Scene.cpp index 8e5e4e5c..b7b44159 100644 --- a/examples/joints/Scene.cpp +++ b/examples/joints/Scene.cpp @@ -246,7 +246,7 @@ void Scene::createSliderJoint() { // Create a box and a corresponding rigid in the dynamics world openglframework::Vector3 box1Dimension(2, 4, 2); - mSliderJointBottomBox = new Box(box1Dimension, positionBox1 , CUBE_MASS, mDynamicsWorld); + mSliderJointBottomBox = new Box(box1Dimension, positionBox1 , BOX_MASS, mDynamicsWorld); // The fist box cannot move mSliderJointBottomBox->getRigidBody()->setIsMotionEnabled(false); @@ -262,7 +262,7 @@ void Scene::createSliderJoint() { // Create a box and a corresponding rigid in the dynamics world openglframework::Vector3 box2Dimension(1.5f, 4, 1.5f); - mSliderJointTopBox = new Box(box2Dimension, positionBox2 , CUBE_MASS, mDynamicsWorld); + mSliderJointTopBox = new Box(box2Dimension, positionBox2 , BOX_MASS, mDynamicsWorld); // The second box is allowed to move mSliderJointTopBox->getRigidBody()->setIsMotionEnabled(true); @@ -301,7 +301,7 @@ void Scene::createPropellerHingeJoint() { // Create a box and a corresponding rigid in the dynamics world openglframework::Vector3 boxDimension(10, 1, 1); - mPropellerBox = new Box(boxDimension, positionBox1 , CUBE_MASS, mDynamicsWorld); + mPropellerBox = new Box(boxDimension, positionBox1 , BOX_MASS, mDynamicsWorld); // The fist box cannot move mPropellerBox->getRigidBody()->setIsMotionEnabled(true); @@ -339,7 +339,7 @@ void Scene::createFixedJoints() { // Create a box and a corresponding rigid in the dynamics world openglframework::Vector3 boxDimension(1.5, 1.5, 1.5); - mFixedJointBox1 = new Box(boxDimension, positionBox1 , CUBE_MASS, mDynamicsWorld); + mFixedJointBox1 = new Box(boxDimension, positionBox1 , BOX_MASS, mDynamicsWorld); // The fist box cannot move mFixedJointBox1->getRigidBody()->setIsMotionEnabled(true); @@ -354,7 +354,7 @@ void Scene::createFixedJoints() { openglframework::Vector3 positionBox2(-5, 7, 0); // Create a box and a corresponding rigid in the dynamics world - mFixedJointBox2 = new Box(boxDimension, positionBox2 , CUBE_MASS, mDynamicsWorld); + mFixedJointBox2 = new Box(boxDimension, positionBox2 , BOX_MASS, mDynamicsWorld); // The second box is allowed to move mFixedJointBox2->getRigidBody()->setIsMotionEnabled(true); diff --git a/examples/joints/Scene.h b/examples/joints/Scene.h index 1c3f72d5..90430d1d 100644 --- a/examples/joints/Scene.h +++ b/examples/joints/Scene.h @@ -34,7 +34,7 @@ // Constants const openglframework::Vector3 BOX_SIZE(2, 2, 2); // Box dimensions in meters const openglframework::Vector3 FLOOR_SIZE(20, 0.5f, 20); // Floor dimensions in meters -const float CUBE_MASS = 1.0f; // Box mass in kilograms +const float BOX_MASS = 1.0f; // Box mass in kilograms const float FLOOR_MASS = 100.0f; // Floor mass in kilograms const int NB_BALLSOCKETJOINT_BOXES = 7; // Number of Ball-And-Socket chain boxes const int NB_HINGE_BOXES = 7; // Number of Hinge chain boxes