Fix issues with the paths of the shaders and meshes in the examples
This commit is contained in:
parent
72d8a9af39
commit
6b8180b620
|
@ -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/)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -108,7 +108,8 @@ class Scene {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
Scene(Viewer* viewer);
|
||||
Scene(Viewer* viewer, const std::string& shaderFolderPath,
|
||||
const std::string& meshFolderPath);
|
||||
|
||||
/// Destructor
|
||||
~Scene();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()) {
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -72,7 +72,7 @@ class Scene {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
Scene(Viewer* viewer);
|
||||
Scene(Viewer* viewer, const std::string& shaderFolderPath);
|
||||
|
||||
/// Destructor
|
||||
~Scene();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ class Scene {
|
|||
// -------------------- Methods -------------------- //
|
||||
|
||||
/// Constructor
|
||||
Scene(Viewer* viewer);
|
||||
Scene(Viewer* viewer, const std::string& shaderFolderPath);
|
||||
|
||||
/// Destructor
|
||||
~Scene();
|
||||
|
|
Loading…
Reference in New Issue
Block a user