diff --git a/sources/demo/Context.cpp b/sources/demo/Context.cpp index f9ff74f1..bfcee624 100755 --- a/sources/demo/Context.cpp +++ b/sources/demo/Context.cpp @@ -30,14 +30,14 @@ using namespace reactphysics3d; Context::Context() { // We add some objects in the context at the beginning ---> THESE THINGS WILL BE STORE IN A TEXT FILE - Cube* cube1 = new Cube(Vector3D(-2.0, 3, -6.0), 2.0, 10.0); - Cube* cube2 = new Cube(Vector3D(0.0, 3, 6.0), 3.0, 5.0); - Cube* cube3 = new Cube(Vector3D(4.0, 3.0, -2.0), 2.0, 0.01); - Plane* plane1 = new Plane(Vector3D(0.0, 0.0, 0.0), 20.0, 30.0, Vector3D(-1.0, 0.0, 0.0), Vector3D(0.0, 0.0, 1.0), 10.0); + Cube* cube1 = new Cube(Vector3D(-2.0, 10, -6.0), 3.0, Kilogram(30.0)); + //Cube* cube2 = new Cube(Vector3D(-3.0, 13, 1.0), 3.0, Kilogram(2.0)); + //Cube* cube3 = new Cube(Vector3D(4.0, 10, -2.0), 2.0, Kilogram(11.0)); + Plane* plane1 = new Plane(Vector3D(0.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); - addObject(cube3); + //addObject(cube2); + //addObject(cube3); addObject(plane1); } diff --git a/sources/demo/Objects.cpp b/sources/demo/Objects.cpp index caee1498..5ce60ae0 100755 --- a/sources/demo/Objects.cpp +++ b/sources/demo/Objects.cpp @@ -30,8 +30,8 @@ // ----- Class Object ----- // // Constructor of the class Object -Object::Object(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor) - :rigidBody(new RigidBody(position, mass, inertiaTensor)) { +Object::Object(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb) + :rigidBody(new RigidBody(position, mass, inertiaTensor, obb)) { } @@ -55,7 +55,8 @@ const Matrix3x3 Cube::inertiaTensor; Cube::Cube(const Vector3D& position, float size, const Kilogram& mass) :Object(position, mass, Matrix3x3(1.0/12.0*mass.getValue()*2*size*size, 0.0, 0.0, 0.0, 1.0/12.0*mass.getValue()*2*size*size, 0.0, - 0.0, 0.0, 1.0/12.0*mass.getValue()*2*size*size)) { + 0.0, 0.0, 1.0/12.0*mass.getValue()*2*size*size), OBB(position, Vector3D(1.0, 0.0, 0.0), Vector3D(0.0, 1.0, 0.0), Vector3D(0.0, 0.0, 1.0), + size/2, size/2, size/2)) { this->size = size; } @@ -97,7 +98,8 @@ void Cube::draw() const { Plane::Plane(const Vector3D& position, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass) :Object(position, mass, Matrix3x3(1.0/12.0*mass.getValue()*height*height, 0.0, 0.0, 0.0, 1.0/12.0*mass.getValue()*(width*width+height*height), 0.0, - 0.0, 0.0, 1.0/12.0*mass.getValue()*width*width)) { + 0.0, 0.0, 1.0/12.0*mass.getValue()*width*width), OBB(position, Vector3D(1.0, 0.0, 0.0), Vector3D(0.0, 1.0, 0.0), Vector3D(0.0, 0.0, 1.0), + width/2, 0.5, height/2)) { // TODO : Change the height of the OBB this->width = width; this->height = height; this->d1 = d1; diff --git a/sources/demo/Objects.h b/sources/demo/Objects.h index 743577c0..d1117163 100755 --- a/sources/demo/Objects.h +++ b/sources/demo/Objects.h @@ -37,11 +37,11 @@ class Object { RigidBody* rigidBody; // Rigid Body that represents the object public : - Object(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor); // Constructor of the class Object - virtual ~Object(); // Destructor of the class Object + Object(const Vector3D& position, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb); // Constructor of the class Object + virtual ~Object(); // Destructor of the class Object - virtual void draw() const =0; // pure virtual method to draw the object - RigidBody* getRigidBody(); // Return the pointer to the rigid body + virtual void draw() const =0; // pure virtual method to draw the object + RigidBody* getRigidBody(); // Return the pointer to the rigid body }; // ----- Class Cube ----- // @@ -61,11 +61,11 @@ class Cube : public Object { // Represent a plane in the simulation class Plane : public Object { private : - float width; // Width of the plane - float height; // Height of the plane - Vector3D d1; // Unit vector in the plane - Vector3D d2; // Unit vector in the plane - Vector3D normalVector; // Unit normal vector of the plane + float width; // Width of the plane + float height; // Height of the plane + Vector3D d1; // Unit vector in the plane + Vector3D d2; // Unit vector in the plane + Vector3D normalVector; // Unit normal vector of the plane public : Plane(const Vector3D& position, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass); // Constructor of the class Plane diff --git a/sources/demo/Scene.cpp b/sources/demo/Scene.cpp index 1a3a9900..5da40ec5 100755 --- a/sources/demo/Scene.cpp +++ b/sources/demo/Scene.cpp @@ -97,7 +97,13 @@ void Scene::display(const Context& context) const { glPushMatrix(); // Draw the object - context.getObject(i).draw(); + context.getObject(i).draw(); + + glPopMatrix(); + glPushMatrix(); + + // Draw the bounding volume + context.getObject(i).getRigidBody()->getOBB().draw(); // Remove the matrix on the top of the matrix stack glPopMatrix(); diff --git a/sources/demo/Simulation.cpp b/sources/demo/Simulation.cpp index 78804da7..e0395b57 100755 --- a/sources/demo/Simulation.cpp +++ b/sources/demo/Simulation.cpp @@ -26,7 +26,8 @@ using namespace reactphysics3d; // Constructor of the class Simulation -Simulation::Simulation() :world(new DynamicWorld(Vector3D(0.0, -2.81, 0.0))), engine(world, Time(0.01)) { +Simulation::Simulation() + :world(new CollisionWorld(Vector3D(0.0, -1.0, 0.0))), engine(world, Time(0.01)) { simRunning = false; mouseButtonPressed = false; nbFrame = 0; @@ -59,11 +60,13 @@ void Simulation::start() { // Get the current time lastFrameTime = SDL_GetTicks(); + DynamicEngine* pEngine = &engine; + // Initialize the display time - engine.initializeDisplayTime(Time(SDL_GetTicks()/1000.0)); + pEngine->initializeDisplayTime(Time(SDL_GetTicks()/1000.0)); // Start the physics simulation - engine.start(); + pEngine->start(); // Main loop of the simulation while(simRunning) { @@ -74,10 +77,10 @@ void Simulation::start() { std::cout << "Time : " << time << std::endl; // Update the display time - engine.updateDisplayTime(Time(time)); + pEngine->updateDisplayTime(Time(time)); // Update the physics - engine.update(); + pEngine->update(); // Display the actual scene scene.display(context); diff --git a/sources/demo/Simulation.h b/sources/demo/Simulation.h index 128de31b..cc906ca4 100755 --- a/sources/demo/Simulation.h +++ b/sources/demo/Simulation.h @@ -30,8 +30,8 @@ class Simulation { private : Scene scene; // Scene object for displaying the simulation Context context; // Context of the simulation - rp3d::DynamicWorld* world; // Pointer to the dynamic world that contains bodies of the simulation - rp3d::DynamicEngine engine; // Dynamic engine for the physics of the simulation + rp3d::CollisionWorld* world; // Pointer to the collision world that contains bodies 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