Fix issues with the paths of the shaders and meshes in the examples

This commit is contained in:
Daniel Chappuis 2014-01-18 17:57:42 +01:00
parent 72d8a9af39
commit 6b8180b620
24 changed files with 82 additions and 48 deletions

View File

@ -4,11 +4,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# Set a variable for the directory of the opengl-framework # Set a variable for the directory of the opengl-framework
SET(OPENGLFRAMEWORK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/common/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(common/)
ADD_SUBDIRECTORY(cubes/) ADD_SUBDIRECTORY(cubes/)
ADD_SUBDIRECTORY(joints/) ADD_SUBDIRECTORY(joints/)

View File

@ -54,6 +54,17 @@ int main(int argc, char** argv) {
viewer->init(argc, argv, "ReactPhysics3D Examples - Collision Shapes", viewer->init(argc, argv, "ReactPhysics3D Examples - Collision Shapes",
windowsSize, windowsPosition, true); 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 // Register callback methods
viewer->registerUpdateFunction(update); viewer->registerUpdateFunction(update);
viewer->registerKeyboardCallback(keyboard); viewer->registerKeyboardCallback(keyboard);
@ -62,7 +73,7 @@ int main(int argc, char** argv) {
viewer->registerScrollingCallback(scroll); viewer->registerScrollingCallback(scroll);
// Create the scene // Create the scene
scene = new Scene(viewer); scene = new Scene(viewer, shaderFolderPath, meshFolderPath);
init(); init();

View File

@ -30,9 +30,10 @@
using namespace openglframework; using namespace openglframework;
// Constructor // Constructor
Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath, const std::string& meshFolderPath)
mPhongShader("shaders/phong.vert", : mViewer(viewer), mLight0(0),
"shaders/phong.frag"), mIsRunning(false) { mPhongShader(shaderFolderPath + "phong.vert",
shaderFolderPath +"phong.frag"), mIsRunning(false) {
// Move the light 0 // Move the light 0
mLight0.translateWorld(Vector3(50, 50, 50)); mLight0.translateWorld(Vector3(50, 50, 50));
@ -57,7 +58,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0),
mDynamicsWorld->setNbIterationsVelocitySolver(15); mDynamicsWorld->setNbIterationsVelocitySolver(15);
// Create the static data for the visual contact points // Create the static data for the visual contact points
VisualContactPoint::createStaticData(); VisualContactPoint::createStaticData(meshFolderPath);
float radius = 3.0f; float radius = 3.0f;
@ -91,7 +92,8 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0),
radius * sin(angle)); radius * sin(angle));
// Create a sphere and a corresponding rigid in the dynamics world // 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 // Change the material properties of the rigid body
rp3d::Material& material = sphere->getRigidBody()->getMaterial(); rp3d::Material& material = sphere->getRigidBody()->getMaterial();
@ -111,7 +113,8 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0),
radius * sin(angle)); radius * sin(angle));
// Create a cone and a corresponding rigid in the dynamics world // 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 // Change the material properties of the rigid body
rp3d::Material& material = cone->getRigidBody()->getMaterial(); 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 // Create a cylinder and a corresponding rigid in the dynamics world
Cylinder* cylinder = new Cylinder(CYLINDER_RADIUS, CYLINDER_HEIGHT, position , Cylinder* cylinder = new Cylinder(CYLINDER_RADIUS, CYLINDER_HEIGHT, position ,
CYLINDER_MASS, mDynamicsWorld); CYLINDER_MASS, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body // Change the material properties of the rigid body
rp3d::Material& material = cylinder->getRigidBody()->getMaterial(); 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 // Create a cylinder and a corresponding rigid in the dynamics world
Capsule* capsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, position , Capsule* capsule = new Capsule(CAPSULE_RADIUS, CAPSULE_HEIGHT, position ,
CAPSULE_MASS, mDynamicsWorld); CAPSULE_MASS, mDynamicsWorld, meshFolderPath);
// Change the material properties of the rigid body // Change the material properties of the rigid body
rp3d::Material& material = capsule->getRigidBody()->getMaterial(); rp3d::Material& material = capsule->getRigidBody()->getMaterial();
@ -173,7 +176,7 @@ Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0),
radius * sin(angle)); radius * sin(angle));
// Create a convex mesh and a corresponding rigid in the dynamics world // 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 // Change the material properties of the rigid body
rp3d::Material& material = mesh->getRigidBody()->getMaterial(); rp3d::Material& material = mesh->getRigidBody()->getMaterial();

View File

@ -108,7 +108,8 @@ class Scene {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
Scene(Viewer* viewer); Scene(Viewer* viewer, const std::string& shaderFolderPath,
const std::string& meshFolderPath);
/// Destructor /// Destructor
~Scene(); ~Scene();

View File

@ -28,12 +28,13 @@
// Constructor // Constructor
Capsule::Capsule(float radius, float height, const openglframework::Vector3 &position, Capsule::Capsule(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) { : openglframework::Mesh(), mRadius(radius), mHeight(height) {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
calculateNormals(); calculateNormals();

View File

@ -57,7 +57,7 @@ class Capsule : public openglframework::Mesh {
/// Constructor /// Constructor
Capsule(float radius, float height, const openglframework::Vector3& position, Capsule(float radius, float height, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld); float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor /// Destructor
~Capsule(); ~Capsule();

View File

@ -29,11 +29,12 @@
// Constructor // Constructor
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) float mass, reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath)
: openglframework::Mesh(), mRadius(radius), mHeight(height) { : openglframework::Mesh(), mRadius(radius), mHeight(height) {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
calculateNormals(); calculateNormals();

View File

@ -57,7 +57,7 @@ class Cone : public openglframework::Mesh {
/// Constructor /// Constructor
Cone(float radius, float height, const openglframework::Vector3& position, Cone(float radius, float height, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld); float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor /// Destructor
~Cone(); ~Cone();

View File

@ -29,11 +29,12 @@
// Constructor // Constructor
ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass, ConvexMesh::ConvexMesh(const openglframework::Vector3 &position, float mass,
reactphysics3d::DynamicsWorld* dynamicsWorld) reactphysics3d::DynamicsWorld* dynamicsWorld,
const std::string& meshFolderPath)
: openglframework::Mesh() { : openglframework::Mesh() {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
calculateNormals(); calculateNormals();

View File

@ -48,7 +48,7 @@ class ConvexMesh : public openglframework::Mesh {
/// Constructor /// Constructor
ConvexMesh(const openglframework::Vector3& position, float mass, ConvexMesh(const openglframework::Vector3& position, float mass,
rp3d::DynamicsWorld* dynamicsWorld); rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor /// Destructor
~ConvexMesh(); ~ConvexMesh();

View File

@ -29,11 +29,12 @@
// Constructor // Constructor
Cylinder::Cylinder(float radius, float height, const openglframework::Vector3 &position, 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) { : openglframework::Mesh(), mRadius(radius), mHeight(height) {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
calculateNormals(); calculateNormals();

View File

@ -57,7 +57,7 @@ class Cylinder : public openglframework::Mesh {
/// Constructor /// Constructor
Cylinder(float radius, float height, const openglframework::Vector3& position, Cylinder(float radius, float height, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld); float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string &meshFolderPath);
/// Destructor /// Destructor
~Cylinder(); ~Cylinder();

View File

@ -29,11 +29,12 @@
// Constructor // Constructor
Sphere::Sphere(float radius, const openglframework::Vector3 &position, 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) { : openglframework::Mesh(), mRadius(radius) {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
calculateNormals(); calculateNormals();

View File

@ -54,7 +54,7 @@ class Sphere : public openglframework::Mesh {
/// Constructor /// Constructor
Sphere(float radius, const openglframework::Vector3& position, Sphere(float radius, const openglframework::Vector3& position,
float mass, rp3d::DynamicsWorld* dynamicsWorld); float mass, rp3d::DynamicsWorld* dynamicsWorld, const std::string& meshFolderPath);
/// Destructor /// Destructor
~Sphere(); ~Sphere();

View File

@ -32,7 +32,7 @@ bool VisualContactPoint::mIsMeshInitialized = false;
openglframework::Mesh VisualContactPoint::mMesh; openglframework::Mesh VisualContactPoint::mMesh;
// Constructor // Constructor
VisualContactPoint::VisualContactPoint(const openglframework::Vector3 &position) { VisualContactPoint::VisualContactPoint(const openglframework::Vector3& position) {
assert(mIsMeshInitialized); assert(mIsMeshInitialized);
@ -46,12 +46,12 @@ VisualContactPoint::~VisualContactPoint() {
} }
// Load and initialize the mesh for all the contact points // Load and initialize the mesh for all the contact points
void VisualContactPoint::createStaticData() { void VisualContactPoint::createStaticData(const std::string& meshFolderPath) {
if (!mIsMeshInitialized) { if (!mIsMeshInitialized) {
// Load the mesh from a file // 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 // Calculate the normals of the mesh
mMesh.calculateNormals(); mMesh.calculateNormals();

View File

@ -60,7 +60,7 @@ class VisualContactPoint : public openglframework::Object3D {
~VisualContactPoint(); ~VisualContactPoint();
/// Load and initialize the mesh for all the contact points /// 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 /// Destroy the mesh for the contact points
static void destroyStaticData(); static void destroyStaticData();

View File

@ -129,7 +129,6 @@ bool Shader::create(const std::string vertexShaderFilename,
GLuint fragmentShaderID; GLuint fragmentShaderID;
std::ifstream fileFragmentShader; std::ifstream fileFragmentShader;
fileFragmentShader.open(fragmentShaderFilename.c_str(), std::ios::binary); fileFragmentShader.open(fragmentShaderFilename.c_str(), std::ios::binary);
assert(fileFragmentShader.is_open());
if (fileFragmentShader.is_open()) { if (fileFragmentShader.is_open()) {

View File

@ -20,7 +20,6 @@ INCLUDE_DIRECTORIES("${OPENGLFRAMEWORK_DIR}/src/" "../common/glfw/include/" "../
SET(CUBES_SOURCES SET(CUBES_SOURCES
Cubes.cpp Cubes.cpp
Scene.cpp Scene.cpp
Scene.cpp
Scene.h Scene.h
"../common/Box.cpp" "../common/Box.cpp"
"../common/Box.h" "../common/Box.h"

View File

@ -53,6 +53,15 @@ int main(int argc, char** argv) {
Vector2 windowsPosition = Vector2(100, 100); Vector2 windowsPosition = Vector2(100, 100);
viewer->init(argc, argv, "ReactPhysics3D Examples - Cubes", windowsSize, windowsPosition, true); 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 // Register callback methods
viewer->registerUpdateFunction(update); viewer->registerUpdateFunction(update);
viewer->registerKeyboardCallback(keyboard); viewer->registerKeyboardCallback(keyboard);
@ -61,7 +70,7 @@ int main(int argc, char** argv) {
viewer->registerScrollingCallback(scroll); viewer->registerScrollingCallback(scroll);
// Create the scene // Create the scene
scene = new Scene(viewer); scene = new Scene(viewer, shaderFolderPath);
init(); init();

View File

@ -30,9 +30,10 @@
using namespace openglframework; using namespace openglframework;
// Constructor // Constructor
Scene::Scene(Viewer* viewer) : mViewer(viewer), mLight0(0), Scene::Scene(Viewer* viewer, const std::string& shaderFolderPath)
mPhongShader("shaders/phong.vert", : mViewer(viewer), mLight0(0),
"shaders/phong.frag"), mIsRunning(false) { mPhongShader(shaderFolderPath + "phong.vert", shaderFolderPath + "phong.frag"),
mIsRunning(false) {
// Move the light 0 // Move the light 0
mLight0.translateWorld(Vector3(7, 15, 15)); mLight0.translateWorld(Vector3(7, 15, 15));

View File

@ -72,7 +72,7 @@ class Scene {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
Scene(Viewer* viewer); Scene(Viewer* viewer, const std::string& shaderFolderPath);
/// Destructor /// Destructor
~Scene(); ~Scene();

View File

@ -53,6 +53,15 @@ int main(int argc, char** argv) {
Vector2 windowsPosition = Vector2(100, 100); Vector2 windowsPosition = Vector2(100, 100);
viewer->init(argc, argv, "ReactPhysics3D Examples - Joints", windowsSize, windowsPosition, true); 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 // Register callback methods
viewer->registerUpdateFunction(update); viewer->registerUpdateFunction(update);
viewer->registerKeyboardCallback(keyboard); viewer->registerKeyboardCallback(keyboard);
@ -61,7 +70,7 @@ int main(int argc, char** argv) {
viewer->registerScrollingCallback(scroll); viewer->registerScrollingCallback(scroll);
// Create the scene // Create the scene
scene = new Scene(viewer); scene = new Scene(viewer, shaderFolderPath);
init(); init();

View File

@ -31,9 +31,11 @@
using namespace openglframework; using namespace openglframework;
// Constructor // Constructor
Scene::Scene(Viewer *viewer) : mViewer(viewer), mLight0(0), Scene::Scene(Viewer *viewer, const std::string& shaderFolderPath)
mPhongShader("shaders/phong.vert", : mViewer(viewer), mLight0(0), mPhongShader(shaderFolderPath + "phong.vert",
"shaders/phong.frag"), mIsRunning(false) { shaderFolderPath + "phong.frag"),
mIsRunning(false) {
// Move the light 0 // Move the light 0
mLight0.translateWorld(Vector3(7, 15, 15)); mLight0.translateWorld(Vector3(7, 15, 15));

View File

@ -126,7 +126,7 @@ class Scene {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
Scene(Viewer* viewer); Scene(Viewer* viewer, const std::string& shaderFolderPath);
/// Destructor /// Destructor
~Scene(); ~Scene();