From 3df13839519e7526ae76046c96e0a9eef9cb118a Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Tue, 10 Feb 2009 16:05:57 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@85 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../reactphysics3d/engine/DynamicEngine.cpp | 57 +++++++++++++++++++ sources/reactphysics3d/engine/DynamicEngine.h | 57 +++++++++++++++++++ sources/reactphysics3d/engine/DynamicWorld.h | 42 ++++++++++++++ .../reactphysics3d/engine/PhysicsEngine.cpp | 35 ++++++++++++ sources/reactphysics3d/engine/PhysicsEngine.h | 4 +- .../reactphysics3d/engine/PhysicsWorld.cpp | 8 ++- sources/reactphysics3d/engine/PhysicsWorld.h | 4 +- 7 files changed, 201 insertions(+), 6 deletions(-) create mode 100644 sources/reactphysics3d/engine/DynamicEngine.cpp create mode 100644 sources/reactphysics3d/engine/DynamicEngine.h create mode 100644 sources/reactphysics3d/engine/DynamicWorld.h create mode 100644 sources/reactphysics3d/engine/PhysicsEngine.cpp diff --git a/sources/reactphysics3d/engine/DynamicEngine.cpp b/sources/reactphysics3d/engine/DynamicEngine.cpp new file mode 100644 index 00000000..4c3da3f8 --- /dev/null +++ b/sources/reactphysics3d/engine/DynamicEngine.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +* 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 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +// Libraries +#include "DynamicEngine.h" + +// We want to use the ReactPhysics3D namespace +using namespace reactphysics3d; + +// Constructor +DynamicEngine::DynamicEngine(DynamicsWorld& world, const Time& timeStep) + :PhysicsEngine(world, timeStep) { + +} + +// Copy-constructor +DynamicEngine::DynamicEngine(const DynamicEngine& engine) + :PhysicsEngine(engine) { + numericalIntegrator = engine.numericalIntegrator; +} + +// Destructor +DynamicEngine::~DynamicEngine() { + +} + +// Compute the interpolation state between the previous body state and the current body state +// This is used to avoid visual stuttering when the display and physics framerates are out of synchronization +BodyState DynamicEngine::interpolateState(const BodyState& previousBodyState, const BodyState& currentBodyState) const { + // TODO : Implement this method +} + +// Update the state of a rigid body +void DynamicEngine::updateBodyState(RigidBody* const rigidBody) { + // TODO : Implement this method +} + +// Update the physics simulation +void DynamicEngine::update() { + // TODO : Implement this method +} diff --git a/sources/reactphysics3d/engine/DynamicEngine.h b/sources/reactphysics3d/engine/DynamicEngine.h new file mode 100644 index 00000000..4f6817d1 --- /dev/null +++ b/sources/reactphysics3d/engine/DynamicEngine.h @@ -0,0 +1,57 @@ +/**************************************************************************** +* 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 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +#ifndef DYNAMICENGINE_H +#define DYNAMICENGINE_H + +// Libraries +#include "PhysicsEngine.h" +#include "NumericalIntegrator.h" +#include "../body/Body.h" +#include "../body/RigidBody.h" +#include "../body/BodyState.h" + +// Namespace ReactPhysics3D +namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class DynamicEngine : + This class that represents a physics engine where we use + the dynamics to simulate the movement of bodies. The class + DynamicEngine inherits from the class PhysicsEngine. + ------------------------------------------------------------------- +*/ +class DynamicEngine : public PhysicsEngine { + protected : + NumericalIntegrator numericalIntegrator; // Numerical integrator used to solve differential equations of movement + + BodyState interpolateState(const BodyState& previousBodyState, const BodyState& currentBodyState) const; // Compute the interpolation state + void updateBodyState(RigidBody* const rigidBody); // Update the state of a rigid body + + public : + DynamicEngine(DynamicsWorld& world, const Time& timeStep); // Constructor + DynamicEngine(const DynamicEngine& engine); // Copy-constructor + virtual ~DynamicEngine(); // Destructor + + void update(); // Update the physics simulation +}; + +} + +#endif diff --git a/sources/reactphysics3d/engine/DynamicWorld.h b/sources/reactphysics3d/engine/DynamicWorld.h new file mode 100644 index 00000000..b44ed1b7 --- /dev/null +++ b/sources/reactphysics3d/engine/DynamicWorld.h @@ -0,0 +1,42 @@ +/**************************************************************************** +* 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 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +#ifndef DYNAMICWORLD_H +#define DYNAMICWORLD_H + +// Libraries +#include "PhysicsWorld.h" + +// Namespace ReactPhysics3D +namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class DynamicWorld : + This class represents the world of the physics engine where + bodies can moves. This class inherits from the class + PhysicsWorld. + ------------------------------------------------------------------- +*/ +class DynamicWorld : public PhysicsWorld { + +}; + +} + +#endif diff --git a/sources/reactphysics3d/engine/PhysicsEngine.cpp b/sources/reactphysics3d/engine/PhysicsEngine.cpp new file mode 100644 index 00000000..daab0aaf --- /dev/null +++ b/sources/reactphysics3d/engine/PhysicsEngine.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +* 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 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +// Libraries +#include "PhysicsEngine.h" + +// We want to use the ReactPhysics3D namespace +using namespace reactphysics3d; + +// Constructor +PhysicsEngine::PhysicsEngine(PhysicsWorld& world, const Time& timeStep) + : world(world), timer(Time(0.0), timeStep) { + +} + +// Destructor +PhysicsEngine::~PhysicsEngine() { + +} diff --git a/sources/reactphysics3d/engine/PhysicsEngine.h b/sources/reactphysics3d/engine/PhysicsEngine.h index ef94d4a3..92e66db1 100644 --- a/sources/reactphysics3d/engine/PhysicsEngine.h +++ b/sources/reactphysics3d/engine/PhysicsEngine.h @@ -42,8 +42,8 @@ class PhysicsEngine { Timer timer; // Timer of the physics engine public : - PhysicsEngine(); // Constructor - virtual ~PhysicsEngine(); // Destructor + PhysicsEngine(PhysicsWorld& world, const Time& timeStep); // Constructor + virtual ~PhysicsEngine(); // Destructor virtual void update()=0; // Update the physics simulation }; diff --git a/sources/reactphysics3d/engine/PhysicsWorld.cpp b/sources/reactphysics3d/engine/PhysicsWorld.cpp index 5461826e..4c6679bd 100644 --- a/sources/reactphysics3d/engine/PhysicsWorld.cpp +++ b/sources/reactphysics3d/engine/PhysicsWorld.cpp @@ -18,7 +18,7 @@ ***************************************************************************/ // Libraries -#include "World.h" +#include "PhysicsWorld.h" // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; @@ -28,6 +28,12 @@ PhysicsWorld::PhysicsWorld(const Vector3D& gravity) : gravity(gravity) { } +// Copy-constructor +PhysicsWorld::PhysicsWorld(const PhysicsWorld& world) { + bodyList = world.bodyList; + gravity = world.gravity; +} + // Destructor PhysicsWorld::~PhysicsWorld() { diff --git a/sources/reactphysics3d/engine/PhysicsWorld.h b/sources/reactphysics3d/engine/PhysicsWorld.h index af03d5ca..317756f2 100644 --- a/sources/reactphysics3d/engine/PhysicsWorld.h +++ b/sources/reactphysics3d/engine/PhysicsWorld.h @@ -37,15 +37,13 @@ namespace reactphysics3d { ------------------------------------------------------------------- */ class PhysicsWorld { - private : - PhysicsWorld(const PhysicsWorld&); // Copy-constructor is private because we don't want it to be used - protected : std::vector bodyList; // list that contains all bodies of the physics world Vector3D gravity; // Gravity vector of the world public : PhysicsWorld(const Vector3D& gravity); // Constructor + PhysicsWorld(const PhysicsWorld&); // Copy-constructor virtual ~PhysicsWorld(); // Destructor void addBody(Body* body) throw(std::invalid_argument); // Add a body to the physics world