Change in the repository structure

git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@400 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
chappuis.daniel 2010-09-09 22:35:18 +00:00
parent 869c48db42
commit a5276ddcbb
14 changed files with 0 additions and 1268 deletions

View File

@ -1,34 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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 "Camera.h"
// Initialization of static variables
double Camera::speed=0.5;
// Constructor of the camera
Camera::Camera() {
}
// Destructor of the camera
Camera::~Camera() {
}

View File

@ -1,91 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef CAMERA_H
#define CAMERA_H
// Libraries
#include "../reactphysics3d/reactphysics3d.h" // We want the mathematics stuff of reactphysics3d
// Namespaces
using namespace reactphysics3d;
// Class Camera (abstract class)
// In the project we will use two different camera. This is the superclass of the two
// cameras. We will use a OutSideCamera that move arround the scene and an OnBoardCamera
// that will simulate the deplacement of a viewer inside the scene
class Camera {
protected :
Vector3D position; // Position of the camera
Vector3D lookAtPoint; // Point where the camera is looking
Vector3D viewVector; // Vector from the camera position to the view point
static double speed; // Speed movement of the camera
public :
Camera(); // Constructor
Camera(const Camera& camera); // Copy-constructor
virtual ~Camera(); // Destructor
virtual Vector3D getPosition() const; // Get the position of the camera
virtual void setPosition(const Vector3D& pos); // Set the position of the camera
virtual Vector3D getLookAtPoint() const; // Return the point where the camera is looking
virtual Vector3D getViewVector() const; // Return the view vector of the camera
virtual void updateViewVector()=0; // Update the view vector of the camera
static void increaseSpeed(); // Increase the speed of camera movement
static void decreaseSpeed(); // Decrease the speed of camera movement
};
// Get the position of the camera (inline function)
inline Vector3D Camera::getPosition() const {
// Return the position of the camera
return position;
}
// Set the position of the camera (inline function)
inline void Camera::setPosition(const Vector3D& pos) {
// Set the position of the camera
position = pos;
}
// Return the point where the camera is looking (inline function)
inline Vector3D Camera::getLookAtPoint() const {
return lookAtPoint;
}
// Return the view vector of the camera (inline function)
inline Vector3D Camera::getViewVector() const {
return viewVector;
}
// Increase the speed movement of the camera (inline function)
inline void Camera::increaseSpeed()
{
speed= speed+0.05;
if(speed>1)
speed=1;
}
// Decrease the speep movement of the camera (inline function)
inline void Camera::decreaseSpeed()
{
speed = speed-0.05;
if(speed<=0)
speed=0.005;
}
#endif

View File

@ -1,111 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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 "Context.h"
#include "../reactphysics3d/reactphysics3d.h"
#include <iostream>
#include <vector>
// We want to use the ReactPhysics3D namespace
using namespace reactphysics3d;
// Constructor of the class Context
Context::Context() {
/*
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);
addObject(cube1);
//addObject(cube2);
//addObject(cube3);
addObject(plane1);
*/
}
// Destructor of the class Context
Context::~Context() {
// Delete all the objects in vectObjects
for(unsigned int i=0; i<vectObjects.size(); ++i) {
delete vectObjects[i];
}
}
// Method to get an object from the context
Object& Context::getObject(int objectIndex) const {
// TODO : WE HAVE TO ADD HERE AN EXCEPTION IMPLEMENTATION
// Return the object from the context
return (*vectObjects.at(objectIndex)); // TODO : THROWN AN EXCEPTION IF INDEX IS OUT OF THE BOUNDS
}
// Method for adding an object into the context
void Context::addObject(Object* object) {
if (object != 0) {
// Add the object into the context
vectObjects.push_back(object);
}
}
// 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);
}

View File

@ -1,46 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef CONTEXT_H
#define CONTEXT_H
// Libraries
#include "Objects.h"
#include <vector>
// Class Context
class Context {
private :
std::vector<Object*> vectObjects; // Vector of Objects in the simulation
public :
Context(); // Constructor of the class
~Context(); // Destructor of the class
int getNbObjects() const; // Return the number of objects in the context
Object& getObject(int objectIndex) const; // Get an object from the context
void addObject(Object* object); // Add an object into the context
void removeObject(int objectIndex); // Remove an object from the context
};
// Method (inline) to get the number of objects in the context
inline int Context::getNbObjects() const {
return vectObjects.size();
}
#endif

View File

@ -1,152 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cmath>
#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() {
// Delete the rigid body object
delete rigidBody;
}
// Return the pointer to the rigid body
RigidBody* Object::getRigidBody() {
return rigidBody;
}
// ----- 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.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
BodyState state = rigidBody->getInterpolatedState();
// Position of the cube
double x = state.getPosition().getX();
double y = state.getPosition().getY();
double z = state.getPosition().getZ();
// Orientation of the cube
Vector3D orientationAxis;
double orientationAngle;
state.getOrientation().getRotationAngleAxis(orientationAngle, orientationAxis);
// 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)
: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;
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
void Plane::draw() const {
// Get the interpolated state of the rigid body
BodyState state = rigidBody->getInterpolatedState();
// Get the position of the rigid body
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();
}

View File

@ -1,76 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#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
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
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 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

View File

@ -1,112 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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 "OutSideCamera.h"
#include <cmath>
// Constructor
OutSideCamera::OutSideCamera() {
// Initialize the attributes
heightFromFloor = 10.0;
horizontalAngleRotation = 45;
verticalAngleRotation = 45;
distanceFromOrigin = 30.0;
lookAtPoint.setAllValues(0.0, 0.0, 0.0);
// Update the position of the camera
updatePosition();
// Update the view vector of the camera
updateViewVector();
}
// Destructor
OutSideCamera::~OutSideCamera() {
}
// Compute the new position of the camera
void OutSideCamera::updatePosition() {
// Compute the floor distance from origin
double floorDistance = distanceFromOrigin * cos(PI/180.0 * verticalAngleRotation);
// Update the position of the camera
position.setAllValues(floorDistance*cos(PI/180.0 * horizontalAngleRotation), distanceFromOrigin*sin(PI/180*verticalAngleRotation),
floorDistance*sin(PI/180.0 * horizontalAngleRotation));
}
// Set the camera rotation angle and update the position of the camera
void OutSideCamera::modifyHorizontalAngleRotation(int screenDistance, float fps) {
// Update the horizontal rotation angle of the camera
horizontalAngleRotation = (horizontalAngleRotation + int(screenDistance * 700.0 / fps)) % 360;
// Update the position and the view vector of the camera
updatePosition();
updateViewVector();
}
// Set the vertical camera rotation angle
void OutSideCamera::modifyVerticalAngleRotation(int screenDistance, float fps) {
// Update the vertical rotation angle of the camera
verticalAngleRotation = verticalAngleRotation + (screenDistance * 700.0 / fps);
// Vertical angle limits
if (verticalAngleRotation > 89) {
verticalAngleRotation = 89;
}
if (verticalAngleRotation < 1) {
verticalAngleRotation = 1;
}
// Update the position and the view vector of the camera
updatePosition();
updateViewVector();
}
// Increase the distance from origine of the camera (used for the zoom)
void OutSideCamera::increaseDistance(float fps) {
// Increase the distance from origin
distanceFromOrigin = distanceFromOrigin + (speed * 60 / fps);
// Update the position and the view vector of the camera
updatePosition();
updateViewVector();
}
// Decrease the distance from origine of the camera (used for the zoom)
void OutSideCamera::decreaseDistance(float fps) {
// Decrease the distance from origin
distanceFromOrigin = distanceFromOrigin - (speed * 60 / fps);
// Limit condition
if(distanceFromOrigin < 1) {
distanceFromOrigin=1;
}
// Update the position and the view vector of the camera
updatePosition();
updateViewVector();
}

View File

@ -1,64 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef OUTSIDE_CAMERA_H
#define OUTSIDE_CAMERA_H
// Libraries
#include "Camera.h"
// ---- Class OutSideCamera ----
// This camera can be move everywhere around the scene to obtain a outside view of the house
class OutSideCamera : public Camera {
private :
double heightFromFloor; // Height from the floor
int horizontalAngleRotation; // Horizontal rotation angle (in degree)
int verticalAngleRotation; // Vertical rotation angle (in degree)
double distanceFromOrigin; // Distance of the camera from the origin (used to zoom)
public :
OutSideCamera(); // Constructor
OutSideCamera(const OutSideCamera& camera); // Copy-constructor
virtual ~OutSideCamera(); // Destructor
void updatePosition(); // Compute the new position of the camera
void updateViewVector(); // Update the view vector of the camera
double getHeightFromFloor() const; // Get the height of the camera from the floor
void setHeightFromFloor(double height); // Set the height of the camera from the floor
void modifyHorizontalAngleRotation(int screenDistance, float fps); // Modify the horizontal camera rotation angle
void modifyVerticalAngleRotation(int screenDistance, float fps); // Modify the vertical camera rotation angle
void increaseDistance(float fps); // Increase the distance of the camera from the origin
void decreaseDistance(float fps); // Decrease the distance of the camera from the origin
};
// Compute the new view vector of the camera (inline function)
inline void OutSideCamera::updateViewVector() {
viewVector = Vector3D(0.0, 0.0, 0.0) - position;
}
// Get the height of the camera from the floor (inline function)
inline double OutSideCamera::getHeightFromFloor() const {
return heightFromFloor;
}
// Set the height of the camera from the floor (inline function)
inline void OutSideCamera::setHeightFromFloor(double height) {
heightFromFloor = height;
}
#endif

View File

@ -1,27 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef REACT_DEMO_H
#define REACT_DEMO_H
// Constants
const int WINWIDTH = 640; // Width of the OpenGL windows
const int WINHEIGHT = 480; // Height of the OpenGL windows
#endif

View File

@ -1,151 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
// Librairies
#include "Scene.h"
#include "Objects.h"
#include <GL/gl.h>
#include <GL/glu.h>
// Constructor of the class Scene
Scene::Scene(rp3d::PhysicsWorld* world) {
this->world = world;
// Initialise the material specular color
mat_specular[0] = 1.0;
mat_specular[1] = 1.0;
mat_specular[2] = 1.0;
mat_specular[3] = 1.0;
// Initialize the material shininess
mat_shininess[0] = 50.0;
// Initialise the light source position
light_position[0] = 20.0;
light_position[1] = 9.0;
light_position[2] = 15.0;
light_position[3] = 0.0;
// Initialise the ambient color of the light
ambient_color[0] = 1.0;
ambient_color[1] = 1.0;
ambient_color[2] = 1.0;
ambient_color[3] = 0.7;
// Initialise the diffuse light color
white_light[0] = 1.0;
white_light[1] = 1.0;
white_light[2] = 1.0;
white_light[3] = 1.0;
}
// Destructor of the class Scene
Scene::~Scene() {
}
// Init method
void Scene::init() {
glClearColor(0.0, 0.0, 0.0, 0.0); // Select the color for the background
glShadeModel(GL_SMOOTH);
glClearDepth(1.0);
// Lighting settings
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); // Specular color of the material
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // Shininess of the material
glLightfv(GL_LIGHT0, GL_POSITION, light_position); // Position of the light source
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); // Ambient color of the light
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); // Diffuse color of the light
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); // Specular color of the light
glEnable(GL_LIGHTING); // Activate the lighting
glEnable(GL_LIGHT0); // Activate a light source
glEnable(GL_DEPTH_TEST); // Activate the Depth buffer
//glEnable(GL_CULL_FACE);
}
// Display method
void Scene::display(const Context& context) const {
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Define the position and the direction of the camera
//gluLookAt(30,10,0,0,0,0,0,1,0);
double x = outsideCamera.getPosition().getX();
double y = outsideCamera.getPosition().getY();
double z = outsideCamera.getPosition().getZ();
gluLookAt(x,y,z,0,0,0,0,1,0);
// Draw all objects in the context
for(int i=0; i<context.getNbObjects(); ++i)
{
// Copy the active matrix on the matrix stack
glPushMatrix();
// Draw the object
context.getObject(i).draw();
glPopMatrix();
glPushMatrix();
// Draw the bounding volume
context.getObject(i).getRigidBody()->getOBB()->draw();
// 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);
Contact* contact = dynamic_cast<Contact*>((*it));
assert(contact != 0);
// Draw the contact points
glPushMatrix();
glTranslatef(contact->getPoint().getX(), contact->getPoint().getY(), contact->getPoint().getZ());
contact->draw();
glPopMatrix();
}
glFlush();
// Swap the buffers
SDL_GL_SwapBuffers();
}
// Reshape the window
void Scene::reshape(int width, int height) {
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION); // Specify the matrix that will be modified
glLoadIdentity(); // Load the identity matrix before the transformations
gluPerspective(45.0, (float) width/height, 0.1f, 150.0f);
glMatrixMode(GL_MODELVIEW); // Specify the matrix that will be modified
glLoadIdentity(); // Load the identity matrix before the transformations
}

View File

@ -1,61 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef SCENE_H
#define SCENE_H
// Libraries
#include "Context.h"
#include "OutSideCamera.h"
#include <SDL/SDL.h>
#include <GL/freeglut.h> // Used only to draw cubes
#include <GL/gl.h>
#include <GL/glu.h>
// Scene class
class Scene {
private :
GLfloat mat_specular[4]; // Material specular light color
GLfloat mat_shininess[1]; // Material shininess
GLfloat light_position[4]; // Position of the light source
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(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
void reshape(int width, int height); // Reshape the window
OutSideCamera& getOutSideCamera() ; // Return a reference to the outside camera
float getCameraAngle1() const; // Return the angle of the camera
float getCameraAngle2() const; // Return the angle of the camera
void setCameraAngle1(float angle); // Set the angle of the camera
void setCameraAngle2(float angle); // Set the angle of the camera
};
// Return a reference to the camera
inline OutSideCamera& Scene::getOutSideCamera() {
return outsideCamera;
}
#endif

View File

@ -1,190 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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 "Simulation.h"
#include "ReactDemo.h"
#include <iostream>
// We want to use the ReactPhysics3D namespace
using namespace reactphysics3d;
// Constructor of the class Simulation
Simulation::Simulation()
: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;
lastFrameTime = 0.0;
fps = 0.0;
}
// Destructor of the class Simulation
Simulation::~Simulation() {
// Delete the physics world object
delete world;
}
// Method to start the simulation
void Simulation::start() {
// Initialisation of the OpenGL settings for the scene
scene.init();
// Reshape the windows for the first time
scene.reshape(WINWIDTH, WINHEIGHT);
// Add every rigid body to the dynamic world
for (int i=0; i<context.getNbObjects(); ++i) {
world->addBody(context.getObject(i).getRigidBody());
}
// Activation of the simulation
simRunning = true;
// Get the current time
lastFrameTime = SDL_GetTicks();
PhysicsEngine* pEngine = &engine;
// Initialize the display time
pEngine->initializeDisplayTime(Time(SDL_GetTicks()/1000.0));
// Start the physics simulation
pEngine->start();
//double time = 1.0;
// Main loop of the simulation
while(simRunning) {
// Check if an SDL event occured and make the apropriate actions
checkEvents();
double time = SDL_GetTicks()/1000.0;
//time += 0.01;
//std::cout << "************************************************* Time : " << time << std::endl;
// Update the display time
pEngine->updateDisplayTime(Time(time));
// Update the physics
pEngine->update();
// Display the actual scene
scene.display(context);
// Compute the fps (framerate)
computeFps();
//std::cout << "FPS : " << fps << std::endl;
/*
BodyState state = context.getObject(0).getRigidBody()->getInterpolatedState();
Vector3D velocity = context.getObject(0).getRigidBody()->getInterpolatedState().getAngularVelocity();
//std::cout << "Velocity 0 : " << velocity.getX() << ", " << velocity.getY() << ", " << velocity.getZ() << ")" << std::endl;
double x = state.getPosition().getX();
double y = state.getPosition().getY();
double z = state.getPosition().getZ();
std::cout << "Position Cube 0 : (" << x << ", " << y << ", " << z << ")" << std::endl;
std::cout << "angular velocity 0 : " << velocity.length() << std::endl;;
BodyState state1 = context.getObject(1).getRigidBody()->getInterpolatedState();
Vector3D velocity1 = context.getObject(1).getRigidBody()->getInterpolatedState().getAngularVelocity();
//std::cout << "Velocity 1 : " << velocity1.getX() << ", " << velocity1.getY() << ", " << velocity1.getZ() << ")" << std::endl;
double x1 = state1.getPosition().getX();
double y1 = state1.getPosition().getY();
double z1 = state1.getPosition().getZ();
std::cout << "Position Cube 1 : (" << x1 << ", " << y1 << ", " << z1 << ")" << std::endl;
std::cout << "angular velocity 1 : " << velocity1.length() << std::endl;
BodyState state2 = context.getObject(2).getRigidBody()->getInterpolatedState();
Quaternion velocity2 = context.getObject(2).getRigidBody()->getInterpolatedState().getOrientation();
//std::cout << "Velocity 2 : " << velocity2.getX() << ", " << velocity2.getY() << ", " << velocity2.getZ() << ")" << std::endl;
double x2 = state2.getPosition().getX();
double y2 = state2.getPosition().getY();
double z2 = state2.getPosition().getZ();
std::cout << "Position Cube 2: (" << x2 << ", " << y2 << ", " << z2 << ")" << std::endl;
std::cout << "quaternion orientation 2 : " << velocity2.getX() << ", " << velocity2.getY() << ", " << velocity2.getZ() << ", " << velocity2.getW() << ")" << std::endl;;
*/
/*
double a;
if (time > 5.0) {
std::cin >> a;
}
*/
}
}
// This method checks if an events occur and call the apropriate method
void Simulation::checkEvents() {
SDL_Event event; // An SDL event
// Zoom of the outside camera
if (SDL_GetKeyState(NULL)[SDLK_UP]) {
scene.getOutSideCamera().decreaseDistance(fps);
}
else if(SDL_GetKeyState(NULL)[SDLK_DOWN]) {
scene.getOutSideCamera().increaseDistance(fps);
}
// Check in the stack of events
while(SDL_PollEvent(&event)) {
// Check an event
switch(event.type) {
// An QUIT event occur
case SDL_QUIT: simRunning = false;
break;
// A keyboard key has been pushed
case SDL_KEYDOWN: // The Esc key has been pushed then we end the simulation
if (event.key.keysym.sym == SDLK_ESCAPE)
simRunning = false;
break;
// The size of the windows changed then we reshape the windows
case SDL_VIDEORESIZE: scene.reshape(event.resize.w, event.resize.h);
break;
// If the mouse moved
case SDL_MOUSEMOTION: if (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) {
// Rotation of the outSideCamera
scene.getOutSideCamera().modifyHorizontalAngleRotation(event.motion.xrel, fps);
scene.getOutSideCamera().modifyVerticalAngleRotation(event.motion.yrel, fps);
}
}
}
}
// Compute the framerate (fps) of the application
void Simulation::computeFps() {
// Increment the number of frame in the last second
nbFrame++;
// Get the current time
double currentTime = SDL_GetTicks();
// Compute the framerate
if (currentTime - lastFrameTime > 1000.0) {
fps = nbFrame * 1000.0/(currentTime-lastFrameTime);
lastFrameTime = currentTime;
nbFrame = 0;
}
}

View File

@ -1,50 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with ReactPhysics3D. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef SIMULATION_H
#define SIMULATION_H
// Librairies
#include "Context.h"
#include "Scene.h"
#include "../reactphysics3d/reactphysics3d.h"
// 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::PhysicsEngine 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
int nbFrame; // Number of frame (used to compute the framerate)
double fps; // Framerate of the application
void computeFps(); // Compute the framerate of the application
public :
Simulation(); // Constructor of the class
~Simulation(); // Destructor of the class
void start(); // Start the simulation
void checkEvents(); // Check if SDL events occured and make the apropriate actions
};
#endif

View File

@ -1,103 +0,0 @@
/****************************************************************************
* 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 Lesser 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 Lesser General Public License for more details. *
* *
* 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 "../reactphysics3d/reactphysics3d.h"
#include "Simulation.h"
#include "ReactDemo.h"
#include <iostream>
#include <SDL/SDL.h>
// Prototypes
int initSDL();
// global variables
SDL_Surface * pScreen; // Pointer to the SDL windows
// Main function
int main(int argc, char** argv) {
if(initSDL() > 0) {
// If initSDL return an error then we exit the program
return EXIT_FAILURE;
}
// Initialize the glut library. We will use glut only to display shapes like cube or sphere
glutInit(&argc, argv);
// Create a Simulation object used to simulate a physic world
Simulation simulation;
// Start the simulation
simulation.start();
std::cerr << "Fin normale du programme" << std::endl;
// To avoid warnings notifying that argc et argv aren't used
(argc);
(argv);
return (EXIT_SUCCESS);
}
// Methode to initialise the SDL and the windows
int initSDL() {
// Initialisation of SDL
if( SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "Echec SDL_Init : " << SDL_GetError() << std::endl;
return 1;
}
// Select the method to exit
atexit( SDL_Quit );
// Active double buffer mode
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// Select the Depth Buffer size
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16);
// Activation of displaying in windows mode
SDL_Surface* pScreen = SDL_SetVideoMode(WINWIDTH, WINHEIGHT, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE | SDL_SWSURFACE);
// Check that displaying is activated
if( !pScreen ) {
std::cerr << "Echec de creation de la fenetre en 640x480 : " << SDL_GetError() << std::endl;
return 1;
}
// Define the window title and the window icon
SDL_WM_SetCaption("ReactPhysics3D Demo 0.01", NULL);
// Get the state of the Double Buffer parameter
int nValue;
if( SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &nValue) < 0) {
std::cerr << "Echec de recuperation du parametre SDL_GL_DOUBLEBUFFER : " << SDL_GetError() << std::endl;
return 1;
}
// Check that Double Buffer mode is activated
if(nValue != 1) {
std::cerr << "Erreur : SDL_GL_DOUBLEBUFFER inactif" << std::endl;
return 1;
}
return 0;
}