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

This commit is contained in:
chappuis.daniel 2010-02-08 19:06:45 +00:00
parent 1fb0912ed2
commit c1f25eed31
6 changed files with 36 additions and 14 deletions

View File

@ -29,7 +29,7 @@ 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));

View File

@ -20,9 +20,14 @@
// Librairies
#include "Scene.h"
#include "Objects.h"
#include <GL/gl.h>
#include <GL/glu.h>
// 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;
@ -109,6 +114,25 @@ void Scene::display(const Context& context) const {
glPopMatrix();
}
// Draw all the contact points
for (std::vector<Constraint*>::const_iterator it = world->getConstraintListStartIterator(); it != world->getConstraintListEndIterator(); ++it) {
RigidBody* rigidBody1 = dynamic_cast<RigidBody*>((*it)->getBody1());
RigidBody* rigidBody2 = dynamic_cast<RigidBody*>((*it)->getBody2());
rigidBody1->setIsMotionEnabled(false);
rigidBody2->setIsMotionEnabled(false);
Contact* contact = dynamic_cast<Contact*>((*it));
assert(contact != 0);
// Draw the contact points
for (unsigned int i=0; i<contact->getPoints().size(); ++i) {
glPushMatrix();
glTranslatef(contact->getPoints()[i].getX(), contact->getPoints()[i].getY(), contact->getPoints()[i].getZ());
contact->draw();
glPopMatrix();
}
}
// Change the buffers
SDL_GL_SwapBuffers();
}

View File

@ -38,9 +38,10 @@ class Scene {
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)
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

View File

@ -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;

View File

@ -28,10 +28,10 @@
// Class Simulation
class Simulation {
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

View File

@ -25,7 +25,6 @@
#include <iostream>
#include <SDL/SDL.h>
// Prototypes
int initSDL();
@ -56,8 +55,6 @@ int main(int argc, char** argv) {
(argv);
return (EXIT_SUCCESS);
return 0;
}
// Methode to initialise the SDL and the windows