diff --git a/sources/demo/Context.cpp b/sources/demo/Context.cpp index 55dff409..8f7d9144 100755 --- a/sources/demo/Context.cpp +++ b/sources/demo/Context.cpp @@ -29,12 +29,12 @@ using namespace reactphysics3d; // Constructor of the class Context Context::Context() { - Cube* cube1 = new Cube(Vector3D(0.0,14.0, 5.0), Quaternion(0.0, 1.0, 0.0, 0.0), 3.0, Kilogram(3.0)); + Cube* cube1 = new Cube(Vector3D(11.0,14.0, 4.0), Quaternion(1.0, 1.0, 0.0, 0.0), 4.0, Kilogram(3.0)); cube1->getRigidBody()->setLinearVelocity(Vector3D(0.0, -5.0, 0.0)); //Cube* cube2 = new Cube(Vector3D(0.0, 17, 8.0), Quaternion(0.0, 1.0, 0.0, 0.0), 3.0, Kilogram(2.0)); //Cube* cube3 = new Cube(Vector3D(4.0, 17, -2.0), Quaternion(0.0, 1.0, 0.0, 0.0), 2.0, Kilogram(11.0)); - Plane* plane1 = new Plane(Vector3D(0.0, 0.0, 0.0), Quaternion(0.0, 1.0, 0.0, 0.0), 20.0, 30.0, Vector3D(-1.0, 0.0, 0.0), Vector3D(0.0, 0.0, 1.0), Kilogram(10.0)); + Plane* plane1 = new Plane(Vector3D(0.0, 0.0, 0.0), Quaternion(0.0, 1.0, 0.0, 0.0), 20.0, 30.0, Vector3D(-1.0, 0.0, 0.0), Vector3D(0.0, 0.0, 1.0), Kilogram(10.0)); addObject(cube1); //addObject(cube2); diff --git a/sources/demo/Scene.cpp b/sources/demo/Scene.cpp index 5da40ec5..2ab5cfdf 100755 --- a/sources/demo/Scene.cpp +++ b/sources/demo/Scene.cpp @@ -19,10 +19,15 @@ // Librairies #include "Scene.h" -#include "Objects.h" +#include "Objects.h" +#include +#include // Constructor of the class Scene -Scene::Scene() { +Scene::Scene(rp3d::PhysicsWorld* world) { + + this->world = world; + // Initialise the material specular color mat_specular[0] = 1.0; mat_specular[1] = 1.0; @@ -107,6 +112,25 @@ void Scene::display(const Context& context) const { // Remove the matrix on the top of the matrix stack glPopMatrix(); + } + + // Draw all the contact points + for (std::vector::const_iterator it = world->getConstraintListStartIterator(); it != world->getConstraintListEndIterator(); ++it) { + RigidBody* rigidBody1 = dynamic_cast((*it)->getBody1()); + RigidBody* rigidBody2 = dynamic_cast((*it)->getBody2()); + rigidBody1->setIsMotionEnabled(false); + rigidBody2->setIsMotionEnabled(false); + + Contact* contact = dynamic_cast((*it)); + assert(contact != 0); + + // Draw the contact points + for (unsigned int i=0; igetPoints().size(); ++i) { + glPushMatrix(); + glTranslatef(contact->getPoints()[i].getX(), contact->getPoints()[i].getY(), contact->getPoints()[i].getZ()); + contact->draw(); + glPopMatrix(); + } } // Change the buffers diff --git a/sources/demo/Scene.h b/sources/demo/Scene.h index ac326fc5..dc9409a9 100755 --- a/sources/demo/Scene.h +++ b/sources/demo/Scene.h @@ -37,10 +37,11 @@ class Scene { GLfloat light_position[4]; // Position of the light source GLfloat ambient_color[4]; // Ambient color of the light GLfloat white_light[4]; // White light color - OutSideCamera outsideCamera; // OutSide camera (Camera that can move around the scene) + OutSideCamera outsideCamera; // OutSide camera (Camera that can move around the scene) + rp3d::PhysicsWorld* world; //"Pointer to the physics world public : - Scene(); // constructor of the class + Scene(rp3d::PhysicsWorld* world); // constructor of the class ~Scene(); // Destructor of the class void init(); // Initialize the values of OpenGL void display(const Context& context) const; // display the scene diff --git a/sources/demo/Simulation.cpp b/sources/demo/Simulation.cpp index fd1b7aed..c0cddde8 100755 --- a/sources/demo/Simulation.cpp +++ b/sources/demo/Simulation.cpp @@ -27,7 +27,7 @@ using namespace reactphysics3d; // Constructor of the class Simulation Simulation::Simulation() - :world(new DynamicWorld(Vector3D(0.0, -0.6, 0.0))), engine(world, Time(0.01)) { + :world(new PhysicsWorld(Vector3D(0.0, -0.6, 0.0))), engine(world, Time(0.01)), scene(this->world) { simRunning = false; mouseButtonPressed = false; nbFrame = 0; diff --git a/sources/demo/Simulation.h b/sources/demo/Simulation.h index 4704bf2a..b5e70afe 100755 --- a/sources/demo/Simulation.h +++ b/sources/demo/Simulation.h @@ -27,11 +27,11 @@ // Class Simulation class Simulation { - private : + private : + rp3d::PhysicsWorld* world; // Pointer to the collision world that contains bodies of the simulation Scene scene; // Scene object for displaying the simulation Context context; // Context of the simulation - rp3d::DynamicWorld* world; // Pointer to the collision world that contains bodies of the simulation - rp3d::DynamicEngine engine; // Collision engine for the physics of the simulation + rp3d::CollisionEngine engine; // Collision engine for the physics of the simulation bool simRunning; // True if the simulation is running and false otherwise bool mouseButtonPressed; // True if the left mouse button is pressed double lastFrameTime; // Last frame time diff --git a/sources/demo/main.cpp b/sources/demo/main.cpp index 0a5dff67..02120d89 100755 --- a/sources/demo/main.cpp +++ b/sources/demo/main.cpp @@ -25,7 +25,6 @@ #include #include - // Prototypes int initSDL(); @@ -33,7 +32,7 @@ int initSDL(); SDL_Surface * pScreen; // Pointer to the SDL windows // Main function -int main(int argc, char** argv) { +int main(int argc, char** argv) { if(initSDL() > 0) { // If initSDL return an error then we exit the program @@ -56,8 +55,6 @@ int main(int argc, char** argv) { (argv); return (EXIT_SUCCESS); - - return 0; } // Methode to initialise the SDL and the windows