2009-02-04 14:43:33 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2009 Daniel Chappuis *
|
|
|
|
****************************************************************************
|
|
|
|
* This file is part of ReactPhysics3D. *
|
|
|
|
* *
|
|
|
|
* ReactPhysics3D is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* ReactPhysics3D is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
// Libraries
|
|
|
|
#include "Context.h"
|
2009-02-13 11:26:51 +00:00
|
|
|
#include "../reactphysics3d/reactphysics3d.h"
|
2009-02-04 14:43:33 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2009-02-13 11:26:51 +00:00
|
|
|
|
|
|
|
// We want to use the ReactPhysics3D namespace
|
|
|
|
using namespace reactphysics3d;
|
2009-02-04 14:43:33 +00:00
|
|
|
|
|
|
|
// Constructor of the class Context
|
|
|
|
Context::Context() {
|
|
|
|
|
|
|
|
// We add some objects in the context at the beginning ---> THESE THINGS WILL BE STORE IN A TEXT FILE
|
2009-02-13 11:26:51 +00:00
|
|
|
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);
|
2009-02-04 14:43:33 +00:00
|
|
|
|
|
|
|
addObject(cube1);
|
|
|
|
addObject(cube2);
|
|
|
|
addObject(cube3);
|
|
|
|
addObject(plane1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor of the class Context
|
|
|
|
Context::~Context() {
|
|
|
|
// Delete all the objects in vectObjects
|
2009-02-13 11:26:51 +00:00
|
|
|
for(unsigned int i=0; i<vectObjects.size(); ++i) {
|
2009-02-25 17:18:08 +00:00
|
|
|
delete vectObjects[i];
|
2009-02-04 14:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method to get an object from the context
|
|
|
|
Object& Context::getObject(int objectIndex) const {
|
2009-02-25 17:18:08 +00:00
|
|
|
// TODO : WE HAVE TO ADD HERE AN EXCEPTION IMPLEMENTATION
|
2009-02-04 14:43:33 +00:00
|
|
|
|
|
|
|
// Return the object from the context
|
2009-02-25 17:18:08 +00:00
|
|
|
return (*vectObjects.at(objectIndex)); // TODO : THROWN AN EXCEPTION IF INDEX IS OUT OF THE BOUNDS
|
2009-02-04 14:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Method for adding an object into the context
|
|
|
|
void Context::addObject(Object* object) {
|
2009-02-25 17:18:08 +00:00
|
|
|
if (object != NULL) {
|
|
|
|
// Add the object into the context
|
|
|
|
vectObjects.push_back(object);
|
|
|
|
}
|
2009-02-04 14:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Method to remove an object from the context
|
|
|
|
void Context::removeObject(int objectIndex) {
|
|
|
|
// WE HAVE TO ADD HERE AN EXCEPTION IMPLEMENTATION
|
|
|
|
|
|
|
|
// Restore the memory of the element
|
|
|
|
delete vectObjects[objectIndex];
|
|
|
|
|
|
|
|
// Erase the element in the vector
|
|
|
|
vectObjects.erase(vectObjects.begin()+objectIndex);
|
|
|
|
}
|