git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@363 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2010-07-19 19:42:47 +00:00
parent 35d95ddaeb
commit 7f4c6833cb
6 changed files with 184 additions and 149 deletions

View File

@ -29,19 +29,49 @@ using namespace reactphysics3d;
// Constructor of the class Context
Context::Context() {
Cube* cube1 = new Cube(Vector3D(5.0, 13.0, 1), Quaternion(1.0, 1.0, 0.0, 0.0), 4.0, Kilogram(3.0));
Cube* cube2 = new Cube(Vector3D(5.0, 13.0, 9), Quaternion(0.5, 0.5, 0.5, 0.0), 4.0, Kilogram(3.0));
cube1->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, 0.5));
cube2->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, -0.5));
/*
Cube* cube1 = new Cube(Vector3D(0.0, 10.0, 0.0), Quaternion(1.0, 1.0, 0.0, 0.0), 3.0, Kilogram(1.0));
Cube* cube2 = new Cube(Vector3D(0.0, 0.0, 0.0), Quaternion(1.0, 1.0, 0.0, 0.0), 3.0, Kilogram(1.0));
//cube1->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, 0.0));
//cube2->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, 0.0));
cube2->getRigidBody()->setIsMotionEnabled(false);
cube1->getRigidBody()->setRestitution(0.5);
cube2->getRigidBody()->setRestitution(0.5);
*/
for (int i=20; i>1; i=i-3) {
Cube* cube = new Cube(Vector3D(3.0, i, i*0.2), Quaternion(1.0, 1.0, 0.0, 0.0), 2.0, Kilogram(1.0));
cube->getRigidBody()->setRestitution(0.7);
addObject(cube);
}
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(1.0));
plane1->getRigidBody()->setRestitution(0.7);
plane1->getRigidBody()->setIsMotionEnabled(false);
addObject(plane1);
/*
Cube* cube1 = new Cube(Vector3D(4.0, 11.0, 5.0), Quaternion(1.0, 0.3, 0.8, 0.0), 2.0, Kilogram(3.0));
//Cube* cube2 = new Cube(Vector3D(3.0, 9, 3.0), Quaternion(1.0, 1.0, 0.0, 0.0), 2.0, Kilogram(2.0));
cube1->getRigidBody()->setRestitution(0.4);
//cube2->getRigidBody()->setRestitution(0.4);
//Cube* cube3 = new Cube(Vector3D(5.0, 13, 0.0), Quaternion(1.0, 1.0, 0.3, 0.0), 2.0, Kilogram(1.0));
//cube3->getRigidBody()->setRestitution(0.8);
Plane* plane1 = new Plane(Vector3D(0.0, 0.0, 0.0), Quaternion(0.0, 1.0, 0.2, 0.0), 20.0, 30.0, Vector3D(-1.0, 0.0, 0.0), Vector3D(0.0, 0.0, 1.0), Kilogram(1.0));
plane1->getRigidBody()->setRestitution(0.4);
plane1->getRigidBody()->setIsMotionEnabled(false);
//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));
addObject(cube1);
addObject(cube2);
//addObject(cube2);
//addObject(cube3);
//addObject(plane1);
addObject(plane1);
*/
}

View File

@ -56,7 +56,7 @@ Cube::Cube(const Vector3D& position, const Quaternion& orientation, float size,
:Object(position, orientation, 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), 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)) {
size/2.0, size/2.0, size/2)) {
this->size = size;
}

View File

@ -45,11 +45,11 @@ class Object {
};
// ----- Class Cube ----- //
// Represente a Cube in the simulation
// Represente a Box in the simulation
class Cube : public Object {
private :
float size; // Size of a side in the cube
static const Matrix3x3 inertiaTensor; // Inertia tensor of a cube
float size; // Size of a side in the box
static const Matrix3x3 inertiaTensor; // Inertia tensor of a box
public :
Cube(const Vector3D& position, const Quaternion& orientation, float size, const Kilogram& mass); // Constructor of the class cube
virtual ~Cube(); // Destructor of the class cube

View File

@ -25,10 +25,10 @@
OutSideCamera::OutSideCamera() {
// Initialize the attributes
heightFromFloor = 20.0;
horizontalAngleRotation = 0;
heightFromFloor = 10.0;
horizontalAngleRotation = 45;
verticalAngleRotation = 45;
distanceFromOrigin = 40.0;
distanceFromOrigin = 30.0;
lookAtPoint.setAllValues(0.0, 0.0, 0.0);
// Update the position of the camera

View File

@ -98,6 +98,7 @@ void Scene::display(const Context& context) const {
// Draw all objects in the context
for(int i=0; i<context.getNbObjects(); ++i)
{
// Copy the active matrix on the matrix stack
glPushMatrix();
@ -112,14 +113,16 @@ 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<Constraint*>::iterator it = world->getConstraintsBeginIterator(); it != world->getConstraintsEndIterator(); ++it) {
RigidBody* rigidBody1 = dynamic_cast<RigidBody*>((*it)->getBody1());
RigidBody* rigidBody2 = dynamic_cast<RigidBody*>((*it)->getBody2());
rigidBody1->setIsMotionEnabled(false);
rigidBody2->setIsMotionEnabled(false);
//rigidBody1->setIsMotionEnabled(false);
//rigidBody2->setIsMotionEnabled(false);
Contact* contact = dynamic_cast<Contact*>((*it));
assert(contact != 0);
@ -131,7 +134,9 @@ void Scene::display(const Context& context) const {
glPopMatrix();
}
// Change the buffers
glFlush();
// Swap the buffers
SDL_GL_SwapBuffers();
}

View File

@ -27,7 +27,7 @@ using namespace reactphysics3d;
// Constructor of the class Simulation
Simulation::Simulation()
:world(new PhysicsWorld(Vector3D(0.0, 0.0, 0.0))), engine(world, Time(0.01)), scene(this->world) {
:world(new PhysicsWorld(Vector3D(0.0, -9.8, 0.0))), engine(world, Time(0.01)), scene(this->world) { // TODO : Change the timestep here after debugging
simRunning = false;
mouseButtonPressed = false;
nbFrame = 0;
@ -84,7 +84,7 @@ void Simulation::start() {
pEngine->updateDisplayTime(Time(time));
// Update the physics
pEngine->updateCollision();
pEngine->update();
// Display the actual scene
scene.display(context);