git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@363 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
35d95ddaeb
commit
7f4c6833cb
|
@ -29,19 +29,49 @@ using namespace reactphysics3d;
|
||||||
// Constructor of the class Context
|
// Constructor of the class Context
|
||||||
Context::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));
|
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));
|
||||||
cube1->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, 0.5));
|
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));
|
||||||
cube2->getRigidBody()->setLinearVelocity(Vector3D(0.0, 0.0, -0.5));
|
//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(cube1);
|
||||||
addObject(cube2);
|
//addObject(cube2);
|
||||||
//addObject(cube3);
|
//addObject(cube3);
|
||||||
//addObject(plane1);
|
addObject(plane1);
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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,
|
: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, 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),
|
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;
|
this->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,11 @@ class Object {
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----- Class Cube ----- //
|
// ----- Class Cube ----- //
|
||||||
// Represente a Cube in the simulation
|
// Represente a Box in the simulation
|
||||||
class Cube : public Object {
|
class Cube : public Object {
|
||||||
private :
|
private :
|
||||||
float size; // Size of a side in the cube
|
float size; // Size of a side in the box
|
||||||
static const Matrix3x3 inertiaTensor; // Inertia tensor of a cube
|
static const Matrix3x3 inertiaTensor; // Inertia tensor of a box
|
||||||
public :
|
public :
|
||||||
Cube(const Vector3D& position, const Quaternion& orientation, float size, const Kilogram& mass); // Constructor of the class cube
|
Cube(const Vector3D& position, const Quaternion& orientation, float size, const Kilogram& mass); // Constructor of the class cube
|
||||||
virtual ~Cube(); // Destructor of the class cube
|
virtual ~Cube(); // Destructor of the class cube
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
OutSideCamera::OutSideCamera() {
|
OutSideCamera::OutSideCamera() {
|
||||||
|
|
||||||
// Initialize the attributes
|
// Initialize the attributes
|
||||||
heightFromFloor = 20.0;
|
heightFromFloor = 10.0;
|
||||||
horizontalAngleRotation = 0;
|
horizontalAngleRotation = 45;
|
||||||
verticalAngleRotation = 45;
|
verticalAngleRotation = 45;
|
||||||
distanceFromOrigin = 40.0;
|
distanceFromOrigin = 30.0;
|
||||||
lookAtPoint.setAllValues(0.0, 0.0, 0.0);
|
lookAtPoint.setAllValues(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
// Update the position of the camera
|
// Update the position of the camera
|
||||||
|
|
|
@ -98,6 +98,7 @@ void Scene::display(const Context& context) const {
|
||||||
// Draw all objects in the context
|
// Draw all objects in the context
|
||||||
for(int i=0; i<context.getNbObjects(); ++i)
|
for(int i=0; i<context.getNbObjects(); ++i)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Copy the active matrix on the matrix stack
|
// Copy the active matrix on the matrix stack
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
|
@ -112,14 +113,16 @@ void Scene::display(const Context& context) const {
|
||||||
|
|
||||||
// Remove the matrix on the top of the matrix stack
|
// Remove the matrix on the top of the matrix stack
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw all the contact points
|
// Draw all the contact points
|
||||||
for (std::vector<Constraint*>::iterator it = world->getConstraintsBeginIterator(); it != world->getConstraintsEndIterator(); ++it) {
|
for (std::vector<Constraint*>::iterator it = world->getConstraintsBeginIterator(); it != world->getConstraintsEndIterator(); ++it) {
|
||||||
RigidBody* rigidBody1 = dynamic_cast<RigidBody*>((*it)->getBody1());
|
RigidBody* rigidBody1 = dynamic_cast<RigidBody*>((*it)->getBody1());
|
||||||
RigidBody* rigidBody2 = dynamic_cast<RigidBody*>((*it)->getBody2());
|
RigidBody* rigidBody2 = dynamic_cast<RigidBody*>((*it)->getBody2());
|
||||||
rigidBody1->setIsMotionEnabled(false);
|
//rigidBody1->setIsMotionEnabled(false);
|
||||||
rigidBody2->setIsMotionEnabled(false);
|
//rigidBody2->setIsMotionEnabled(false);
|
||||||
|
|
||||||
Contact* contact = dynamic_cast<Contact*>((*it));
|
Contact* contact = dynamic_cast<Contact*>((*it));
|
||||||
assert(contact != 0);
|
assert(contact != 0);
|
||||||
|
@ -131,7 +134,9 @@ void Scene::display(const Context& context) const {
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change the buffers
|
glFlush();
|
||||||
|
|
||||||
|
// Swap the buffers
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace reactphysics3d;
|
||||||
|
|
||||||
// Constructor of the class Simulation
|
// Constructor of the class Simulation
|
||||||
Simulation::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;
|
simRunning = false;
|
||||||
mouseButtonPressed = false;
|
mouseButtonPressed = false;
|
||||||
nbFrame = 0;
|
nbFrame = 0;
|
||||||
|
@ -84,7 +84,7 @@ void Simulation::start() {
|
||||||
pEngine->updateDisplayTime(Time(time));
|
pEngine->updateDisplayTime(Time(time));
|
||||||
|
|
||||||
// Update the physics
|
// Update the physics
|
||||||
pEngine->updateCollision();
|
pEngine->update();
|
||||||
|
|
||||||
// Display the actual scene
|
// Display the actual scene
|
||||||
scene.display(context);
|
scene.display(context);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user