git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@99 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
9cf084f4ce
commit
f4e061911c
|
@ -24,9 +24,13 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
DynamicEngine::DynamicEngine(DynamicWorld& world, const Time& timeStep)
|
||||
DynamicEngine::DynamicEngine(DynamicWorld* world, const Time& timeStep)
|
||||
:PhysicsEngine(world, timeStep) {
|
||||
|
||||
// Check if the pointer to the world is not NULL
|
||||
if (world == 0) {
|
||||
// Throw an exception
|
||||
throw std::invalid_argument("Exception in PhysicsEngine constructor : World pointer cannot be NULL");
|
||||
}
|
||||
}
|
||||
|
||||
// Copy-constructor
|
||||
|
@ -52,30 +56,33 @@ void DynamicEngine::updateBodyState(RigidBody* const rigidBody) {
|
|||
// Update the physics simulation
|
||||
void DynamicEngine::update() {
|
||||
|
||||
// While the time accumulator is not empty
|
||||
while(timer.getAccumulator() >= timer.getTimeStep().getValue()) {
|
||||
// Check if the physics simulation is running
|
||||
if (timer.getIsRunning()) {
|
||||
// While the time accumulator is not empty
|
||||
while(timer.getAccumulator() >= timer.getTimeStep().getValue()) {
|
||||
// For each body in the dynamic world
|
||||
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
||||
// If the body is a RigidBody and if the rigid body motion is enabled
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
if (rigidBody && rigidBody->getIsMotionEnabled()) {
|
||||
// Update the state of the rigid body
|
||||
updateBodyState(rigidBody);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the timer
|
||||
timer.update();
|
||||
}
|
||||
|
||||
// For each body in the dynamic world
|
||||
for(std::vector<Body*>::const_iterator it = world.getBodyListStartIterator(); it != world.getBodyListEndIterator(); ++it) {
|
||||
for(std::vector<Body*>::const_iterator it = world->getBodyListStartIterator(); it != world->getBodyListEndIterator(); ++it) {
|
||||
// If the body is a RigidBody and if the rigid body motion is enabled
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
if (rigidBody && rigidBody->getIsMotionEnabled()) {
|
||||
// Update the state of the rigid body
|
||||
updateBodyState(rigidBody);
|
||||
// Update the interpolation factor of the rigid body
|
||||
// This one will be used to compute the interpolated state
|
||||
rigidBody->setInterpolationFactor(timer.getInterpolationFactor());
|
||||
}
|
||||
}
|
||||
|
||||
// Update the timer
|
||||
timer.update();
|
||||
}
|
||||
|
||||
// For each body in the dynamic world
|
||||
for(std::vector<Body*>::const_iterator it = world.getBodyListStartIterator(); it != world.getBodyListEndIterator(); ++it) {
|
||||
// If the body is a RigidBody and if the rigid body motion is enabled
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
if (rigidBody && rigidBody->getIsMotionEnabled()) {
|
||||
// Update the interpolation factor of the rigid body
|
||||
// This one will be used to compute the interpolated state
|
||||
rigidBody->setInterpolationFactor(timer.getInterpolationFactor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class DynamicEngine : public PhysicsEngine {
|
|||
void updateBodyState(RigidBody* const rigidBody); // Update the state of a rigid body
|
||||
|
||||
public :
|
||||
DynamicEngine(DynamicWorld& world, const Time& timeStep); // Constructor
|
||||
DynamicEngine(DynamicWorld* world, const Time& timeStep); // Constructor
|
||||
DynamicEngine(const DynamicEngine& engine); // Copy-constructor
|
||||
virtual ~DynamicEngine(); // Destructor
|
||||
|
||||
|
|
|
@ -24,9 +24,13 @@
|
|||
using namespace reactphysics3d;
|
||||
|
||||
// Constructor
|
||||
PhysicsEngine::PhysicsEngine(PhysicsWorld& world, const Time& timeStep)
|
||||
PhysicsEngine::PhysicsEngine(PhysicsWorld* world, const Time& timeStep) throw (std::invalid_argument)
|
||||
: world(world), timer(Time(0.0), timeStep) {
|
||||
|
||||
// Check if the pointer to the world is not NULL
|
||||
if (world == 0) {
|
||||
// Throw an exception
|
||||
throw std::invalid_argument("Exception in PhysicsEngine constructor : World pointer cannot be NULL");
|
||||
}
|
||||
}
|
||||
|
||||
// Copy-constructor
|
||||
|
|
|
@ -35,17 +35,42 @@ namespace reactphysics3d {
|
|||
*/
|
||||
class PhysicsEngine {
|
||||
protected :
|
||||
PhysicsWorld world; // Physics world of the physics engine
|
||||
PhysicsWorld* world; // Pointer to the physics world of the physics engine
|
||||
Timer timer; // Timer of the physics engine
|
||||
|
||||
public :
|
||||
PhysicsEngine(PhysicsWorld& world, const Time& timeStep); // Constructor
|
||||
PhysicsEngine(const PhysicsEngine& engine); // Copy-constructor
|
||||
virtual ~PhysicsEngine(); // Destructor
|
||||
PhysicsEngine(PhysicsWorld* world, const Time& timeStep) throw (std::invalid_argument); // Constructor
|
||||
PhysicsEngine(const PhysicsEngine& engine); // Copy-constructor
|
||||
virtual ~PhysicsEngine(); // Destructor
|
||||
|
||||
virtual void update()=0; // Update the physics simulation
|
||||
virtual void start(); // Start the physics simulation
|
||||
virtual void stop(); // Stop the physics simulation
|
||||
virtual void update()=0; // Update the physics simulation
|
||||
void initializeDisplayTime(const Time& displayTime); // Initialize the display time
|
||||
void updateDisplayTime(const Time& newDisplayTime); // Update the display time
|
||||
};
|
||||
|
||||
// --- Inline functions --- //
|
||||
|
||||
// Start the physics simulation
|
||||
inline void PhysicsEngine::start() {
|
||||
timer.setIsRunning(true);
|
||||
}
|
||||
|
||||
inline void PhysicsEngine::stop() {
|
||||
// TODO : Implement this method
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,6 @@ Timer::Timer(const Time& initialTime, const Time& timeStep) throw(std::invalid_a
|
|||
if (timeStep.getValue() != 0.0) {
|
||||
accumulator = 0.0;
|
||||
isRunning = false;
|
||||
|
||||
}
|
||||
else {
|
||||
// We throw an exception
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
// Libraries
|
||||
#include "../physics/physics.h"
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
// Namespace ReactPhysics3D
|
||||
namespace reactphysics3d {
|
||||
|
@ -52,7 +53,8 @@ class Timer {
|
|||
void setTime(const Time& time); // Set the current time
|
||||
bool getIsRunning() const; // Return if the timer is running
|
||||
void setIsRunning(bool isRunning); // Set if the timer is running
|
||||
double getAccumulator() const; // Return the accumulator value
|
||||
double getAccumulator() const; // Return the accumulator value
|
||||
void setCurrentDisplayTime(const Time& displayTime); // Set the current display time
|
||||
|
||||
void update(); // Update the timer
|
||||
double getInterpolationFactor() const; // Compute and return the interpolation factor between two body states
|
||||
|
@ -103,6 +105,11 @@ inline double Timer::getAccumulator() const {
|
|||
return accumulator;
|
||||
}
|
||||
|
||||
// Set the current display time
|
||||
inline void Timer::setCurrentDisplayTime(const Time& currentDisplayTime) {
|
||||
this->currentDisplayTime = currentDisplayTime;
|
||||
}
|
||||
|
||||
// Update the timer
|
||||
inline void Timer::update() {
|
||||
// Update the current time of the physics engine
|
||||
|
|
Loading…
Reference in New Issue
Block a user