From 6b8180b6200b7d4fd1b0f18d3d05334a7d4f3899 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sat, 18 Jan 2014 17:57:42 +0100 Subject: [PATCH] Fix issues with the paths of the shaders and meshes in the examples --- examples/CMakeLists.txt | 5 ----- examples/collisionshapes/CollisionShapes.cpp | 13 +++++++++++- examples/collisionshapes/Scene.cpp | 21 +++++++++++-------- examples/collisionshapes/Scene.h | 3 ++- examples/common/Capsule.cpp | 7 ++++--- examples/common/Capsule.h | 2 +- examples/common/Cone.cpp | 5 +++-- examples/common/Cone.h | 2 +- examples/common/ConvexMesh.cpp | 5 +++-- examples/common/ConvexMesh.h | 2 +- examples/common/Cylinder.cpp | 5 +++-- examples/common/Cylinder.h | 2 +- examples/common/Sphere.cpp | 5 +++-- examples/common/Sphere.h | 2 +- examples/common/VisualContactPoint.cpp | 6 +++--- examples/common/VisualContactPoint.h | 2 +- .../common/opengl-framework/src/Shader.cpp | 1 - examples/cubes/CMakeLists.txt | 1 - examples/cubes/Cubes.cpp | 11 +++++++++- examples/cubes/Scene.cpp | 7 ++++--- examples/cubes/Scene.h | 2 +- examples/joints/Joints.cpp | 11 +++++++++- examples/joints/Scene.cpp | 8 ++++--- examples/joints/Scene.h | 2 +- 24 files changed, 82 insertions(+), 48 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 450ceb1e..edc71428 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,11 +4,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) # Set a variable for the directory of the opengl-framework SET(OPENGLFRAMEWORK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/common/opengl-framework") -# If we will use FREEGLUT -IF(NOT APPLE) - ADD_DEFINITIONS(-DUSE_FREEGLUT) -ENDIF() - ADD_SUBDIRECTORY(common/) ADD_SUBDIRECTORY(cubes/) ADD_SUBDIRECTORY(joints/) diff --git a/examples/collisionshapes/CollisionShapes.cpp b/examples/collisionshapes/CollisionShapes.cpp index bcbf0637..9d5bcb22 100644 --- a/examples/collisionshapes/CollisionShapes.cpp +++ b/examples/collisionshapes/CollisionShapes.cpp @@ -54,6 +54,17 @@ int main(int argc, char** argv) { viewer->init(argc, argv, "ReactPhysics3D Examples - Collision Shapes", windowsSize, windowsPosition, true); + // If the shaders and meshes folders are not specified as an argument + if (argc < 3) { + std::cerr << "Error : You need to specify the shaders folder as the first argument" + << " and the meshes folder as the second argument" << std::endl; + return 1; + } + + // Get the path of the shaders folder + std::string shaderFolderPath(argv[1]); + std::string meshFolderPath(argv[2]); + // Register callback methods viewer->registerUpdateFunction(update); viewer->registerKeyboardCallback(keyboard); @@ -62,7 +73,7 @@ int main(int argc, char** argv) { viewer->registerScrollingCallback(scroll); // Create the scene - scene = new Scene(viewer); + scene = new Scene(viewer, shaderFolderPath, meshFolderPath); init(); diff --git a/examples/collisionshapes/Scene.cpp b/examples/collisionshapes/Scene.cpp index 0c7dbc23..582c4040 100644 --- a/examples/collisionshapes/Scene.cpp +++ b/examples/collisionshapes/Scene.cpp @@ -30,9 +30,10 @@ using namespace openglframework; // Constructor -Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), - mPhongShader("shaders/phong.vert", - "shaders/phong.frag"), mIsRunning(false) { +Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::string& meshFolderPath) + : mViewer(viewer), mLight0(0), + mPhongShader(shaderFolderPath + "phong.vert", + shaderFolderPath +"phong.frag"), mIsRunning(false) { // Move the light 0 mLight0.translateWorld(Vector3(50, 50, 50)); @@ -57,7 +58,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), mDynamicsWorld->setNbIterationsVelocitySolver(15); // Create the static data for the visual contact points - VisualContactPoint::createStaticData(); + VisualContactPoint::createStaticData(meshFolderPath); float radius = 3.0f; @@ -91,7 +92,8 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), radius * sin(angle)); // Create a sphere and a corresponding rigid in the dynamics world - Sphere* sphere = new Sphere(SPHERE_RADIUS, position , BOX_MASS, mDynamicsWorld); + Sphere* sphere = new Sphere(SPHERE_RADIUS, position , BOX_MASS, mDynamicsWorld, + meshFolderPath); // Change the material properties of the rigid body rp3d::Material& material = sphere->getRigidBody()->getMaterial(); @@ -111,7 +113,8 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), radius * sin(angle)); // Create a cone and a corresponding rigid in the dynamics world - Cone* cone = new Cone(CONE_RADIUS, CONE_HEIGHT, position , CONE_MASS, mDynamicsWorld); + Cone* cone = new Cone(CONE_RADIUS, CONE_HEIGHT, position, CONE_MASS, mDynamicsWorld, + meshFolderPath); // Change the material properties of the rigid body rp3d::Material& material = cone->getRigidBody()->getMaterial(); @@ -132,7 +135,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), // Create a cylinder and a corresponding rigid in the dynamics world Cylinder* cylinder = new Cylinder(CYLINDER_RADIUS, CYLINDER_HEIGHT, position , - CYLINDER_MASS, mDynamicsWorld); + CYLINDER_MASS, mDynamicsWorld, meshFolderPath); // Change the material properties of the rigid body rp3d::Material& material = cylinder->getRigidBody()->getMaterial(); @@ -153,7 +156,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), // Create a cylinder and a corresponding rigid in the dynamics world Capsule* capsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, position , - CAPSULE_MASS, mDynamicsWorld); + CAPSULE_MASS, mDynamicsWorld, meshFolderPath); // Change the material properties of the rigid body rp3d::Material& material = capsule->getRigidBody()->getMaterial(); @@ -173,7 +176,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), radius * sin(angle)); // Create a convex mesh and a corresponding rigid in the dynamics world - ConvexMesh* mesh = new ConvexMesh(position, MESH_MASS, mDynamicsWorld); + ConvexMesh* mesh = new ConvexMesh(position, MESH_MASS, mDynamicsWorld, meshFolderPath); // Change the material properties of the rigid body rp3d::Material& material = mesh->getRigidBody()->getMaterial(); diff --git a/examples/collisionshapes/Scene.h b/examples/collisionshapes/Scene.h index 3010c13f..9d2959e8 100644 --- a/examples/collisionshapes/Scene.h +++ b/examples/collisionshapes/Scene.h @@ -108,7 +108,8 @@ class Scene { // -------------------- Methods -------------------- // /// Constructor - Scene(Viewer* viewer); + Scene(Viewer* viewer, const std::string& shaderFolderPath, + const std::string& meshFolderPath); /// Destructor ~Scene(); diff --git a/examples/common/Capsule.cpp b/examples/common/Capsule.cpp index bcf16200..ea0913e5 100644 --- a/examples/common/Capsule.cpp +++ b/examples/common/Capsule.cpp @@ -28,12 +28,13 @@ // Constructor -Capsule::Capsule(float radius, float height, const openglframework::Vector3 &position, - float mass, reactphysics3d::DynamicsWorld* dynamicsWorld) +Capsule::Capsule(float radius, float height, const openglframework::Vector3& position, + float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, + const std::string& meshFolderPath) : openglframework::Mesh(), mRadius(radius), mHeight(height) { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/capsule.obj", *this); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "capsule.obj", *this); // Calculate the normals of the mesh calculateNormals(); diff --git a/examples/common/Capsule.h b/examples/common/Capsule.h index e99f9fa4..21168f2f 100644 --- a/examples/common/Capsule.h +++ b/examples/common/Capsule.h @@ -57,7 +57,7 @@ class Capsule : public openglframework::Mesh { /// Constructor Capsule(float radius, float height, const openglframework::Vector3& position, - float mass, rp3d::DynamicsWorld* dynamicsWorld); + float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath); /// Destructor ~Capsule(); diff --git a/examples/common/Cone.cpp b/examples/common/Cone.cpp index 585b8c0d..736c06fe 100644 --- a/examples/common/Cone.cpp +++ b/examples/common/Cone.cpp @@ -29,11 +29,12 @@ // Constructor Cone::Cone(float radius, float height, const openglframework::Vector3 &position, - float mass, reactphysics3d::DynamicsWorld* dynamicsWorld) + float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, + const std::string& meshFolderPath) : openglframework::Mesh(), mRadius(radius), mHeight(height) { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/cone.obj", *this); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cone.obj", *this); // Calculate the normals of the mesh calculateNormals(); diff --git a/examples/common/Cone.h b/examples/common/Cone.h index fabb7157..c0053bf9 100644 --- a/examples/common/Cone.h +++ b/examples/common/Cone.h @@ -57,7 +57,7 @@ class Cone : public openglframework::Mesh { /// Constructor Cone(float radius, float height, const openglframework::Vector3& position, - float mass, rp3d::DynamicsWorld* dynamicsWorld); + float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath); /// Destructor ~Cone(); diff --git a/examples/common/ConvexMesh.cpp b/examples/common/ConvexMesh.cpp index 70acf445..c2fc7369 100644 --- a/examples/common/ConvexMesh.cpp +++ b/examples/common/ConvexMesh.cpp @@ -29,11 +29,12 @@ // Constructor ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, - reactphysics3d::DynamicsWorld* dynamicsWorld) + reactphysics3d::DynamicsWorld* dynamicsWorld, + const std::string& meshFolderPath) : openglframework::Mesh() { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/convexmesh.obj", *this); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "convexmesh.obj", *this); // Calculate the normals of the mesh calculateNormals(); diff --git a/examples/common/ConvexMesh.h b/examples/common/ConvexMesh.h index 46ae8c09..a558c0f5 100644 --- a/examples/common/ConvexMesh.h +++ b/examples/common/ConvexMesh.h @@ -48,7 +48,7 @@ class ConvexMesh : public openglframework::Mesh { /// Constructor ConvexMesh(const openglframework::Vector3& position, float mass, - rp3d::DynamicsWorld* dynamicsWorld); + rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath); /// Destructor ~ConvexMesh(); diff --git a/examples/common/Cylinder.cpp b/examples/common/Cylinder.cpp index cf9dc3cf..cfbdfec6 100644 --- a/examples/common/Cylinder.cpp +++ b/examples/common/Cylinder.cpp @@ -29,11 +29,12 @@ // Constructor Cylinder::Cylinder(float radius, float height, const openglframework::Vector3 &position, - float mass, reactphysics3d::DynamicsWorld* dynamicsWorld) + float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, + const std::string& meshFolderPath) : openglframework::Mesh(), mRadius(radius), mHeight(height) { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/cylinder.obj", *this); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "cylinder.obj", *this); // Calculate the normals of the mesh calculateNormals(); diff --git a/examples/common/Cylinder.h b/examples/common/Cylinder.h index e094580d..46988286 100644 --- a/examples/common/Cylinder.h +++ b/examples/common/Cylinder.h @@ -57,7 +57,7 @@ class Cylinder : public openglframework::Mesh { /// Constructor Cylinder(float radius, float height, const openglframework::Vector3& position, - float mass, rp3d::DynamicsWorld* dynamicsWorld); + float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string &meshFolderPath); /// Destructor ~Cylinder(); diff --git a/examples/common/Sphere.cpp b/examples/common/Sphere.cpp index 2d785444..f9fbb1d0 100644 --- a/examples/common/Sphere.cpp +++ b/examples/common/Sphere.cpp @@ -29,11 +29,12 @@ // Constructor Sphere::Sphere(float radius, const openglframework::Vector3 &position, - float mass, reactphysics3d::DynamicsWorld* dynamicsWorld) + float mass, reactphysics3d::DynamicsWorld* dynamicsWorld, + const std::string& meshFolderPath) : openglframework::Mesh(), mRadius(radius) { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/sphere.obj", *this); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", *this); // Calculate the normals of the mesh calculateNormals(); diff --git a/examples/common/Sphere.h b/examples/common/Sphere.h index dccef0eb..daabfd14 100644 --- a/examples/common/Sphere.h +++ b/examples/common/Sphere.h @@ -54,7 +54,7 @@ class Sphere : public openglframework::Mesh { /// Constructor Sphere(float radius, const openglframework::Vector3& position, - float mass, rp3d::DynamicsWorld* dynamicsWorld); + float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath); /// Destructor ~Sphere(); diff --git a/examples/common/VisualContactPoint.cpp b/examples/common/VisualContactPoint.cpp index 8cbfa489..32a11fde 100644 --- a/examples/common/VisualContactPoint.cpp +++ b/examples/common/VisualContactPoint.cpp @@ -32,7 +32,7 @@ bool VisualContactPoint::mIsMeshInitialized = false; openglframework::Mesh VisualContactPoint::mMesh; // Constructor -VisualContactPoint::VisualContactPoint(const openglframework::Vector3 &position) { +VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position) { assert(mIsMeshInitialized); @@ -46,12 +46,12 @@ VisualContactPoint::~VisualContactPoint() { } // Load and initialize the mesh for all the contact points -void VisualContactPoint::createStaticData() { +void VisualContactPoint::createStaticData(const std::string& meshFolderPath) { if (!mIsMeshInitialized) { // Load the mesh from a file - openglframework::MeshReaderWriter::loadMeshFromFile("meshes/sphere.obj", mMesh); + openglframework::MeshReaderWriter::loadMeshFromFile(meshFolderPath + "sphere.obj", mMesh); // Calculate the normals of the mesh mMesh.calculateNormals(); diff --git a/examples/common/VisualContactPoint.h b/examples/common/VisualContactPoint.h index 6ad1903a..e3e96a0d 100644 --- a/examples/common/VisualContactPoint.h +++ b/examples/common/VisualContactPoint.h @@ -60,7 +60,7 @@ class VisualContactPoint : public openglframework::Object3D { ~VisualContactPoint(); /// Load and initialize the mesh for all the contact points - static void createStaticData(); + static void createStaticData(const std::string& meshFolderPath); /// Destroy the mesh for the contact points static void destroyStaticData(); diff --git a/examples/common/opengl-framework/src/Shader.cpp b/examples/common/opengl-framework/src/Shader.cpp index 1ec1b4a9..137669f7 100644 --- a/examples/common/opengl-framework/src/Shader.cpp +++ b/examples/common/opengl-framework/src/Shader.cpp @@ -129,7 +129,6 @@ bool Shader::create(const std::string vertexShaderFilename, GLuint fragmentShaderID; std::ifstream fileFragmentShader; fileFragmentShader.open(fragmentShaderFilename.c_str(), std::ios::binary); - assert(fileFragmentShader.is_open()); if (fileFragmentShader.is_open()) { diff --git a/examples/cubes/CMakeLists.txt b/examples/cubes/CMakeLists.txt index edf19b86..5239dc56 100644 --- a/examples/cubes/CMakeLists.txt +++ b/examples/cubes/CMakeLists.txt @@ -20,7 +20,6 @@ INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../ SET(CUBES_SOURCES Cubes.cpp Scene.cpp - Scene.cpp Scene.h "../common/Box.cpp" "../common/Box.h" diff --git a/examples/cubes/Cubes.cpp b/examples/cubes/Cubes.cpp index 1fbc51b9..67622133 100644 --- a/examples/cubes/Cubes.cpp +++ b/examples/cubes/Cubes.cpp @@ -53,6 +53,15 @@ int main(int argc, char** argv) { Vector2 windowsPosition = Vector2(100, 100); viewer->init(argc, argv, "ReactPhysics3D Examples - Cubes", windowsSize, windowsPosition, true); + // If the shaders folder is not specified as an argument + if (argc < 2) { + std::cerr << "Error : You need to specify the shaders folder as argument !" << std::endl; + return 1; + } + + // Get the path of the shaders folder + std::string shaderFolderPath(argv[1]); + // Register callback methods viewer->registerUpdateFunction(update); viewer->registerKeyboardCallback(keyboard); @@ -61,7 +70,7 @@ int main(int argc, char** argv) { viewer->registerScrollingCallback(scroll); // Create the scene - scene = new Scene(viewer); + scene = new Scene(viewer, shaderFolderPath); init(); diff --git a/examples/cubes/Scene.cpp b/examples/cubes/Scene.cpp index 0b1172ba..838f4a0b 100644 --- a/examples/cubes/Scene.cpp +++ b/examples/cubes/Scene.cpp @@ -30,9 +30,10 @@ using namespace openglframework; // Constructor -Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), - mPhongShader("shaders/phong.vert", - "shaders/phong.frag"), mIsRunning(false) { +Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath) + : mViewer(viewer), mLight0(0), + mPhongShader(shaderFolderPath + "phong.vert", shaderFolderPath + "phong.frag"), + mIsRunning(false) { // Move the light 0 mLight0.translateWorld(Vector3(7, 15, 15)); diff --git a/examples/cubes/Scene.h b/examples/cubes/Scene.h index a3a3db38..f8f0dde0 100644 --- a/examples/cubes/Scene.h +++ b/examples/cubes/Scene.h @@ -72,7 +72,7 @@ class Scene { // -------------------- Methods -------------------- // /// Constructor - Scene(Viewer* viewer); + Scene(Viewer* viewer, const std::string& shaderFolderPath); /// Destructor ~Scene(); diff --git a/examples/joints/Joints.cpp b/examples/joints/Joints.cpp index bb210f8b..369143bd 100644 --- a/examples/joints/Joints.cpp +++ b/examples/joints/Joints.cpp @@ -53,6 +53,15 @@ int main(int argc, char** argv) { Vector2 windowsPosition = Vector2(100, 100); viewer->init(argc, argv, "ReactPhysics3D Examples - Joints", windowsSize, windowsPosition, true); + // If the shaders folder is not specified as an argument + if (argc < 2) { + std::cerr << "Error : You need to specify the shaders folder as argument !" << std::endl; + return 1; + } + + // Get the path of the shaders folder + std::string shaderFolderPath(argv[1]); + // Register callback methods viewer->registerUpdateFunction(update); viewer->registerKeyboardCallback(keyboard); @@ -61,7 +70,7 @@ int main(int argc, char** argv) { viewer->registerScrollingCallback(scroll); // Create the scene - scene = new Scene(viewer); + scene = new Scene(viewer, shaderFolderPath); init(); diff --git a/examples/joints/Scene.cpp b/examples/joints/Scene.cpp index 697cbe8b..a73e51be 100644 --- a/examples/joints/Scene.cpp +++ b/examples/joints/Scene.cpp @@ -31,9 +31,11 @@ using namespace openglframework; // Constructor -Scene::Scene(Viewer *viewer) : mViewer(viewer), mLight0(0), - mPhongShader("shaders/phong.vert", - "shaders/phong.frag"), mIsRunning(false) { +Scene::Scene(Viewer *viewer, const std::string& shaderFolderPath) + : mViewer(viewer), mLight0(0), mPhongShader(shaderFolderPath + "phong.vert", + shaderFolderPath + "phong.frag"), + mIsRunning(false) { + // Move the light 0 mLight0.translateWorld(Vector3(7, 15, 15)); diff --git a/examples/joints/Scene.h b/examples/joints/Scene.h index 97b862a4..22e51fae 100644 --- a/examples/joints/Scene.h +++ b/examples/joints/Scene.h @@ -126,7 +126,7 @@ class Scene { // -------------------- Methods -------------------- // /// Constructor - Scene(Viewer* viewer); + Scene(Viewer* viewer, const std::string& shaderFolderPath); /// Destructor ~Scene();