2009-02-10 14:31:43 +00:00
/****************************************************************************
2009-06-05 14:25:12 +00:00
* 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/>. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-02-10 14:31:43 +00:00
# ifndef PHYSICSENGINE_H
# define PHYSICSENGINE_H
// Libraries
# include "PhysicsWorld.h"
2010-02-11 11:31:49 +00:00
# include "../collision/CollisionDetection.h"
2010-06-09 21:40:13 +00:00
# include "ConstraintSolver.h"
2010-02-11 11:31:49 +00:00
# include "../body/RigidBody.h"
2009-02-10 14:31:43 +00:00
# include "Timer.h"
// Namespace ReactPhysics3D
namespace reactphysics3d {
/* -------------------------------------------------------------------
Class PhysicsEngine :
2010-02-11 11:31:49 +00:00
This class represents the physics engine
2009-02-10 14:31:43 +00:00
of the library .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
class PhysicsEngine {
protected :
2010-02-11 11:31:49 +00:00
PhysicsWorld * world ; // Pointer to the physics world of the physics engine
Timer timer ; // Timer of the physics engine
CollisionDetection collisionDetection ; // Collision detection
2010-06-09 21:40:13 +00:00
ConstraintSolver constraintSolver ; // Constraint solver
2010-07-24 17:14:29 +00:00
// Update the state of a rigid body // TODO : Delete this
2010-07-05 20:52:16 +00:00
void updateAllBodiesMotion ( ) ; // Compute the motion of all bodies and update their positions and orientations
void updatePositionAndOrientationOfBody ( Body * body , const Vector3D & newLinVelocity , const Vector3D & newAngVelocity ) ; // Update the position and orientation of a body
void applyGravity ( ) ; // Apply the gravity force to all bodies
2009-02-10 14:31:43 +00:00
public :
2009-02-13 11:26:15 +00:00
PhysicsEngine ( PhysicsWorld * world , const Time & timeStep ) throw ( std : : invalid_argument ) ; // Constructor
2010-02-11 11:31:49 +00:00
~ PhysicsEngine ( ) ; // Destructor
2009-02-10 14:31:43 +00:00
2010-02-11 11:31:49 +00:00
void start ( ) ; // Start the physics simulation
void stop ( ) ; // Stop the physics simulation
void update ( ) ; // Update the physics simulation
2010-07-05 20:52:16 +00:00
//void updateDynamic(); // TODO : Delete this method
2010-02-11 11:31:49 +00:00
void updateCollision ( ) ; // TODO : Delete this collision
2009-02-13 11:26:15 +00:00
void initializeDisplayTime ( const Time & displayTime ) ; // Initialize the display time
void updateDisplayTime ( const Time & newDisplayTime ) ; // Update the display time
2009-02-10 14:31:43 +00:00
} ;
2009-02-13 11:26:15 +00:00
// --- Inline functions --- //
// Start the physics simulation
inline void PhysicsEngine : : start ( ) {
timer . setIsRunning ( true ) ;
}
inline void PhysicsEngine : : stop ( ) {
2009-07-21 20:31:18 +00:00
timer . setIsRunning ( false ) ;
2009-02-13 11:26:15 +00:00
}
// Initialize the display time
inline void PhysicsEngine : : initializeDisplayTime ( const Time & displayTime ) {
timer . setCurrentDisplayTime ( displayTime ) ;
}
// Update the display time
inline void PhysicsEngine : : updateDisplayTime ( const Time & newDisplayTime ) {
timer . updateDisplayTime ( newDisplayTime ) ;
}
2009-02-10 14:31:43 +00:00
}
# endif