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
|
||||
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);
|
||||
*/
|
||||
|
||||
//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));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
addObject(cube1);
|
||||
addObject(cube2);
|
||||
//addObject(cube2);
|
||||
//addObject(cube3);
|
||||
//addObject(plane1);
|
||||
addObject(plane1);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,56 +16,56 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
// Libraries
|
||||
#include "Objects.h"
|
||||
|
||||
//#include <windows.h> // To avoid an error due to the #include <GL/glut.h>
|
||||
|
||||
// Libraries
|
||||
#include "Objects.h"
|
||||
|
||||
//#include <windows.h> // To avoid an error due to the #include <GL/glut.h>
|
||||
#include <GL/freeglut.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glu.h>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
// ----- Class Object ----- //
|
||||
|
||||
// Constructor of the class Object
|
||||
#include <iostream>
|
||||
|
||||
// ----- Class Object ----- //
|
||||
|
||||
// Constructor of the class Object
|
||||
Object::Object(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb)
|
||||
:rigidBody(new RigidBody(position, orientation, mass, inertiaTensor, obb)) {
|
||||
|
||||
}
|
||||
|
||||
// Destructor of the class Object
|
||||
Object::~Object() {
|
||||
:rigidBody(new RigidBody(position, orientation, mass, inertiaTensor, obb)) {
|
||||
|
||||
}
|
||||
|
||||
// Destructor of the class Object
|
||||
Object::~Object() {
|
||||
// Delete the rigid body object
|
||||
delete rigidBody;
|
||||
delete rigidBody;
|
||||
}
|
||||
|
||||
// Return the pointer to the rigid body
|
||||
RigidBody* Object::getRigidBody() {
|
||||
return rigidBody;
|
||||
}
|
||||
|
||||
// ----- Class Cube ----- //
|
||||
}
|
||||
|
||||
// ----- Class Cube ----- //
|
||||
|
||||
// Static attributes
|
||||
const Matrix3x3 Cube::inertiaTensor;
|
||||
|
||||
// Constructor of the class Cube
|
||||
Cube::Cube(const Vector3D& position, const Quaternion& orientation, float size, const Kilogram& mass)
|
||||
: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)) {
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
// Destructor of the classe Cube
|
||||
Cube::~Cube() {
|
||||
|
||||
}
|
||||
|
||||
// Method to draw the cube
|
||||
|
||||
// Constructor of the class Cube
|
||||
Cube::Cube(const Vector3D& position, const Quaternion& orientation, float size, const Kilogram& mass)
|
||||
: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.0, size/2.0, size/2)) {
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
// Destructor of the classe Cube
|
||||
Cube::~Cube() {
|
||||
|
||||
}
|
||||
|
||||
// Method to draw the cube
|
||||
void Cube::draw() const {
|
||||
|
||||
// Get the interpolated state of the rigid body
|
||||
|
@ -80,44 +80,44 @@ void Cube::draw() const {
|
|||
Vector3D orientationAxis;
|
||||
double orientationAngle;
|
||||
state.getOrientation().getRotationAngleAxis(orientationAngle, orientationAxis);
|
||||
|
||||
// Translation of the cube to its position
|
||||
|
||||
// Translation of the cube to its position
|
||||
glTranslatef(x, y, z);
|
||||
|
||||
// Rotation of the cube according to its orientation
|
||||
glRotatef(orientationAngle/PI*180.0, orientationAxis.getX(), orientationAxis.getY(), orientationAxis.getZ());
|
||||
|
||||
// Draw the cube
|
||||
glutSolidCube(size);
|
||||
}
|
||||
|
||||
|
||||
// ----- Class Plane ----- //
|
||||
|
||||
// Constructor of the class Plane
|
||||
Plane::Plane(const Vector3D& position, const Quaternion& orientation, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass)
|
||||
glRotatef(orientationAngle/PI*180.0, orientationAxis.getX(), orientationAxis.getY(), orientationAxis.getZ());
|
||||
|
||||
// Draw the cube
|
||||
glutSolidCube(size);
|
||||
}
|
||||
|
||||
|
||||
// ----- Class Plane ----- //
|
||||
|
||||
// Constructor of the class Plane
|
||||
Plane::Plane(const Vector3D& position, const Quaternion& orientation, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass)
|
||||
:Object(position, orientation, 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), 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;
|
||||
width/2, 0.5, height/2)) { // TODO : Change the height of the OBB
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->d1 = d1;
|
||||
this->d2 = d2;
|
||||
|
||||
// By default Planes in the demo cannot move
|
||||
rigidBody->setIsMotionEnabled(false);
|
||||
|
||||
// Compute the unit normal vector of the plane by a cross product
|
||||
normalVector = d1.crossProduct(d2).getUnit();
|
||||
}
|
||||
|
||||
// Destructor of the class Plane
|
||||
Plane::~Plane() {
|
||||
|
||||
}
|
||||
|
||||
// Method used to draw the plane
|
||||
rigidBody->setIsMotionEnabled(false);
|
||||
|
||||
// Compute the unit normal vector of the plane by a cross product
|
||||
normalVector = d1.crossProduct(d2).getUnit();
|
||||
}
|
||||
|
||||
// Destructor of the class Plane
|
||||
Plane::~Plane() {
|
||||
|
||||
}
|
||||
|
||||
// Method used to draw the plane
|
||||
void Plane::draw() const {
|
||||
|
||||
// Get the interpolated state of the rigid body
|
||||
|
@ -127,26 +127,26 @@ void Plane::draw() const {
|
|||
double x = state.getPosition().getX();
|
||||
double y = state.getPosition().getY();
|
||||
double z = state.getPosition().getZ();
|
||||
|
||||
|
||||
// Translation of the cube to its position
|
||||
glTranslatef(x, y, z);
|
||||
|
||||
float halfWidth = width / 2.0;
|
||||
float halfHeight = height / 2.0;
|
||||
|
||||
// Draw the plane
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glVertex3f(x + d1.getX() * halfWidth + d2.getX() * halfHeight , y + d1.getY() * halfWidth + d2.getY() * halfHeight
|
||||
, z + d1.getZ() * halfWidth + d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x + d1.getX() * halfWidth - d2.getX() * halfHeight , y + d1.getY() * halfWidth - d2.getY() * halfHeight
|
||||
, z + d1.getZ() * halfWidth - d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x - d1.getX() * halfWidth - d2.getX() * halfHeight , y - d1.getY() * halfWidth - d2.getY() * halfHeight
|
||||
, z - d1.getZ() * halfWidth - d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x - d1.getX() * halfWidth + d2.getX() * halfHeight , y - d1.getY() * halfWidth + d2.getY() * halfHeight
|
||||
, z - d1.getZ() * halfWidth + d2.getZ() * halfHeight);
|
||||
glEnd();
|
||||
glTranslatef(x, y, z);
|
||||
|
||||
float halfWidth = width / 2.0;
|
||||
float halfHeight = height / 2.0;
|
||||
|
||||
// Draw the plane
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glVertex3f(x + d1.getX() * halfWidth + d2.getX() * halfHeight , y + d1.getY() * halfWidth + d2.getY() * halfHeight
|
||||
, z + d1.getZ() * halfWidth + d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x + d1.getX() * halfWidth - d2.getX() * halfHeight , y + d1.getY() * halfWidth - d2.getY() * halfHeight
|
||||
, z + d1.getZ() * halfWidth - d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x - d1.getX() * halfWidth - d2.getX() * halfHeight , y - d1.getY() * halfWidth - d2.getY() * halfHeight
|
||||
, z - d1.getZ() * halfWidth - d2.getZ() * halfHeight);
|
||||
glNormal3f(normalVector.getX(), normalVector.getY(), normalVector.getZ());
|
||||
glVertex3f(x - d1.getX() * halfWidth + d2.getX() * halfHeight , y - d1.getY() * halfWidth + d2.getY() * halfHeight
|
||||
, z - d1.getZ() * halfWidth + d2.getZ() * halfHeight);
|
||||
glEnd();
|
||||
}
|
||||
|
|
|
@ -17,60 +17,60 @@
|
|||
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef OBJECTS_H
|
||||
#define OBJECTS_H
|
||||
#ifndef OBJECTS_H
|
||||
#define OBJECTS_H
|
||||
|
||||
// Libraries
|
||||
#include "../reactphysics3d/reactphysics3d.h"
|
||||
|
||||
// Namespaces
|
||||
using namespace reactphysics3d;
|
||||
|
||||
/*
|
||||
Here we define all the objects that can appear in the simulation like cube, sphere, plane, ...
|
||||
*/
|
||||
|
||||
// ----- Class Object (abstract) ----- //
|
||||
// Represent an object of the simulation
|
||||
|
||||
/*
|
||||
Here we define all the objects that can appear in the simulation like cube, sphere, plane, ...
|
||||
*/
|
||||
|
||||
// ----- Class Object (abstract) ----- //
|
||||
// Represent an object of the simulation
|
||||
class Object {
|
||||
protected :
|
||||
RigidBody* rigidBody; // Rigid Body that represents the object
|
||||
|
||||
public :
|
||||
Object(const Vector3D& position, const Quaternion& orientation, const Kilogram& mass, const Matrix3x3& inertiaTensor, const OBB& obb); // Constructor of the class Object
|
||||
virtual ~Object(); // Destructor of the class Object
|
||||
|
||||
public :
|
||||
Object(const Vector3D& position, const Quaternion& orientation, 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
|
||||
};
|
||||
|
||||
// ----- Class Cube ----- //
|
||||
// Represente a Cube 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
|
||||
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
|
||||
virtual void draw() const; // Method to draw the cube
|
||||
};
|
||||
|
||||
|
||||
// ----- Class Plane ---- //
|
||||
// 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
|
||||
RigidBody* getRigidBody(); // Return the pointer to the rigid body
|
||||
};
|
||||
|
||||
// ----- Class Cube ----- //
|
||||
// Represente a Box in the simulation
|
||||
class Cube : public Object {
|
||||
private :
|
||||
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
|
||||
virtual void draw() const; // Method to draw the cube
|
||||
};
|
||||
|
||||
|
||||
// ----- Class Plane ---- //
|
||||
// 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
|
||||
|
||||
public :
|
||||
Plane(const Vector3D& position, const Quaternion& orientation, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass); // Constructor of the class Plane
|
||||
virtual ~Plane(); // Destructor of the class Plane
|
||||
virtual void draw() const; // Method to draw the plane
|
||||
};
|
||||
|
||||
#endif
|
||||
public :
|
||||
Plane(const Vector3D& position, const Quaternion& orientation, float width, float height, const Vector3D& d1, const Vector3D& d2, const Kilogram& mass); // Constructor of the class Plane
|
||||
virtual ~Plane(); // Destructor of the class Plane
|
||||
virtual void draw() const; // Method to draw the plane
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,8 +134,10 @@ void Scene::display(const Context& context) const {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
// Change the buffers
|
||||
SDL_GL_SwapBuffers();
|
||||
glFlush();
|
||||
|
||||
// Swap the buffers
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
// Reshape the window
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user