Remove dynamic casting
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@449 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
9bfb44597f
commit
5467e09020
|
@ -79,8 +79,8 @@ bool CollisionDetection::computeCollisionDetection() {
|
|||
void CollisionDetection::computeBroadPhase() {
|
||||
|
||||
// Notify the broad-phase algorithm about new and removed bodies in the physics world
|
||||
broadPhaseAlgorithm->notifyAddedBodies(world->getAddedBodies());
|
||||
broadPhaseAlgorithm->notifyRemovedBodies(world->getRemovedBodies());
|
||||
broadPhaseAlgorithm->notifyAddedBodies(world->getAddedRigidBodies());
|
||||
broadPhaseAlgorithm->notifyRemovedBodies(world->getRemovedRigidBodies());
|
||||
|
||||
// Clear the set of the overlapping pairs in the current step
|
||||
currentStepOverlappingPairs.clear();
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
// Libraries
|
||||
#include <vector>
|
||||
#include "../../body/Body.h"
|
||||
#include "../../body/RigidBody.h"
|
||||
|
||||
// Namespace ReactPhysics3D
|
||||
namespace reactphysics3d {
|
||||
|
@ -56,9 +56,9 @@ class BroadPhaseAlgorithm {
|
|||
BroadPhaseAlgorithm(CollisionDetection& collisionDetection); // Constructor
|
||||
virtual ~BroadPhaseAlgorithm(); // Destructor
|
||||
|
||||
virtual void computePossibleCollisionPairs()=0; // Compute the possible collision pairs of bodies
|
||||
virtual void notifyAddedBodies(std::vector<Body*> bodies)=0; // Notify the broad-phase algorithm about new bodies in the physics world
|
||||
virtual void notifyRemovedBodies(std::vector<Body*> bodies)=0; // Notify the broad-phase algorithm about removed bodies in the physics world
|
||||
virtual void computePossibleCollisionPairs()=0; // Compute the possible collision pairs of bodies
|
||||
virtual void notifyAddedBodies(std::vector<RigidBody*> bodies)=0; // Notify the broad-phase algorithm about new bodies in the physics world
|
||||
virtual void notifyRemovedBodies(std::vector<RigidBody*> bodies)=0; // Notify the broad-phase algorithm about removed bodies in the physics world
|
||||
};
|
||||
|
||||
} // End of reactphysics3d namespace
|
||||
|
|
|
@ -47,12 +47,12 @@ SAPAlgorithm::~SAPAlgorithm() {
|
|||
|
||||
// Notify the broad-phase algorithm about new bodies in the physics world
|
||||
// This method removes the AABB representation of a given set of bodies from the sortedAABBs set
|
||||
void SAPAlgorithm::notifyRemovedBodies(vector<Body*> bodies) {
|
||||
void SAPAlgorithm::notifyRemovedBodies(vector<RigidBody*> bodies) {
|
||||
vector<const AABB*>::iterator elemToRemove;
|
||||
const AABB* aabb;
|
||||
|
||||
// Removed the AABB of the bodies that have been removed
|
||||
for (vector<Body*>::iterator it = bodies.begin(); it != bodies.end(); ++it) {
|
||||
for (vector<RigidBody*>::iterator it = bodies.begin(); it != bodies.end(); ++it) {
|
||||
aabb = (*it)->getAABB();
|
||||
assert(aabb);
|
||||
elemToRemove = find(sortedAABBs.begin(), sortedAABBs.end(), aabb);
|
||||
|
@ -63,10 +63,10 @@ void SAPAlgorithm::notifyRemovedBodies(vector<Body*> bodies) {
|
|||
|
||||
// Notify the broad-phase algorithm about new bodies in the physics world
|
||||
// This method adds the AABB representation of a given body in the sortedAABBs set
|
||||
void SAPAlgorithm::notifyAddedBodies(vector<Body*> bodies) {
|
||||
void SAPAlgorithm::notifyAddedBodies(vector<RigidBody*> bodies) {
|
||||
const AABB* aabb;
|
||||
|
||||
for (vector<Body*>::iterator it = bodies.begin(); it != bodies.end(); ++it) {
|
||||
for (vector<RigidBody*>::iterator it = bodies.begin(); it != bodies.end(); ++it) {
|
||||
aabb = 0;
|
||||
aabb = (*it)->getAABB();
|
||||
assert(aabb);
|
||||
|
|
|
@ -63,8 +63,8 @@ class SAPAlgorithm : public BroadPhaseAlgorithm {
|
|||
virtual ~SAPAlgorithm(); // Destructor
|
||||
|
||||
virtual void computePossibleCollisionPairs(); // Compute the possible collision pairs of bodies
|
||||
virtual void notifyAddedBodies(std::vector<Body*> bodies); // Notify the broad-phase algorithm about new bodies in the physics world
|
||||
virtual void notifyRemovedBodies(std::vector<Body*> bodies); // Notify the broad-phase algorithm about removed bodies in the physics world
|
||||
virtual void notifyAddedBodies(std::vector<RigidBody*> bodies); // Notify the broad-phase algorithm about new bodies in the physics world
|
||||
virtual void notifyRemovedBodies(std::vector<RigidBody*> bodies); // Notify the broad-phase algorithm about removed bodies in the physics world
|
||||
};
|
||||
|
||||
// Static method that compare two AABBs. This method will be used to compare to AABBs
|
||||
|
|
|
@ -100,9 +100,9 @@ void PhysicsEngine::updateAllBodiesMotion() {
|
|||
Vector3 newAngularVelocity;
|
||||
|
||||
// For each body of thephysics world
|
||||
for (vector<Body*>::iterator it=world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) {
|
||||
for (vector<RigidBody*>::iterator it=world->getRigidBodiesBeginIterator(); it != world->getRigidBodiesEndIterator(); ++it) {
|
||||
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
RigidBody* rigidBody = *it;
|
||||
assert(rigidBody);
|
||||
|
||||
// If the body is able to move
|
||||
|
@ -138,10 +138,9 @@ void PhysicsEngine::updateAllBodiesMotion() {
|
|||
// Update the position and orientation of a body
|
||||
// Use the Semi-Implicit Euler (Sympletic Euler) method to compute the new position and the new
|
||||
// orientation of the body
|
||||
void PhysicsEngine::updatePositionAndOrientationOfBody(Body* body, const Vector3& newLinVelocity, const Vector3& newAngVelocity) {
|
||||
void PhysicsEngine::updatePositionAndOrientationOfBody(RigidBody* rigidBody, const Vector3& newLinVelocity, const Vector3& newAngVelocity) {
|
||||
double dt = timer.getTimeStep();
|
||||
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(body);
|
||||
assert(rigidBody);
|
||||
|
||||
// Update the old position and orientation of the body
|
||||
|
@ -168,7 +167,7 @@ void PhysicsEngine::setInterpolationFactorToAllBodies() {
|
|||
assert(factor >= 0.0 && factor <= 1.0);
|
||||
|
||||
// Set the factor to all bodies
|
||||
for (vector<Body*>::iterator it=world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) {
|
||||
for (vector<RigidBody*>::iterator it=world->getRigidBodiesBeginIterator(); it != world->getRigidBodiesEndIterator(); ++it) {
|
||||
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
assert(rigidBody);
|
||||
|
@ -181,7 +180,7 @@ void PhysicsEngine::setInterpolationFactorToAllBodies() {
|
|||
void PhysicsEngine::applyGravity() {
|
||||
|
||||
// For each body of the physics world
|
||||
for (vector<Body*>::iterator it=world->getBodiesBeginIterator(); it != world->getBodiesEndIterator(); ++it) {
|
||||
for (vector<RigidBody*>::iterator it=world->getRigidBodiesBeginIterator(); it != world->getRigidBodiesEndIterator(); ++it) {
|
||||
|
||||
RigidBody* rigidBody = dynamic_cast<RigidBody*>(*it);
|
||||
assert(rigidBody);
|
||||
|
|
|
@ -50,7 +50,7 @@ class PhysicsEngine {
|
|||
ConstraintSolver constraintSolver; // Constraint solver
|
||||
|
||||
void updateAllBodiesMotion(); // Compute the motion of all bodies and update their positions and orientations
|
||||
void updatePositionAndOrientationOfBody(Body* body, const Vector3& newLinVelocity, const Vector3& newAngVelocity); // Update the position and orientation of a body
|
||||
void updatePositionAndOrientationOfBody(RigidBody* body, const Vector3& newLinVelocity, const Vector3& newAngVelocity); // Update the position and orientation of a body
|
||||
void setInterpolationFactorToAllBodies(); // Compute and set the interpolation factor to all bodies
|
||||
void applyGravity(); // Apply the gravity force to all bodies
|
||||
|
||||
|
|
|
@ -52,13 +52,13 @@ RigidBody* PhysicsWorld::createRigidBody(const Transform& transform, double mass
|
|||
currentBodyID++;
|
||||
|
||||
// Add the rigid body to the physics world and return it
|
||||
addBody(rigidBody);
|
||||
addRigidBody(rigidBody);
|
||||
return rigidBody;
|
||||
}
|
||||
|
||||
// Destroy a rigid body
|
||||
void PhysicsWorld::destroyRigidBody(RigidBody* rigidBody) {
|
||||
removeBody(rigidBody);
|
||||
removeRigidBody(rigidBody);
|
||||
delete rigidBody;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,16 +47,16 @@ namespace reactphysics3d {
|
|||
*/
|
||||
class PhysicsWorld {
|
||||
protected :
|
||||
std::vector<Body*> bodies; // All the rigid bodies of the physics world
|
||||
std::vector<Body*> addedBodies; // Added bodies since last update
|
||||
std::vector<Body*> removedBodies; // Removed bodies since last update
|
||||
std::vector<RigidBody*> rigidBodies; // All the rigid bodies of the physics world
|
||||
std::vector<RigidBody*> addedBodies; // Added bodies since last update
|
||||
std::vector<RigidBody*> removedBodies; // Removed bodies since last update
|
||||
std::vector<Constraint*> constraints; // List that contains all the current constraints
|
||||
Vector3 gravity; // Gravity vector of the world
|
||||
bool isGravityOn; // True if the gravity force is on
|
||||
long unsigned int currentBodyID; // Current body ID
|
||||
|
||||
void addBody(Body* body); // Add a body to the physics world
|
||||
void removeBody(Body* body); // Remove a body from the physics world
|
||||
void addRigidBody(RigidBody* body); // Add a body to the physics world
|
||||
void removeRigidBody(RigidBody* body); // Remove a body from the physics world
|
||||
|
||||
public :
|
||||
PhysicsWorld(const Vector3& gravity); // Constructor
|
||||
|
@ -75,23 +75,23 @@ class PhysicsWorld {
|
|||
void removeAllConstraints(); // Remove all constraints and delete them (free their memory)
|
||||
std::vector<Constraint*>::iterator getConstraintsBeginIterator(); // Return a start iterator on the constraint list
|
||||
std::vector<Constraint*>::iterator getConstraintsEndIterator(); // Return a end iterator on the constraint list
|
||||
std::vector<Body*>::iterator getBodiesBeginIterator(); // Return an iterator to the beginning of the bodies of the physics world
|
||||
std::vector<Body*>::iterator getBodiesEndIterator(); // Return an iterator to the end of the bodies of the physics world
|
||||
std::vector<Body*>& getAddedBodies(); // Return the added bodies since last update of the physics engine
|
||||
std::vector<Body*>& getRemovedBodies(); // Retrun the removed bodies since last update of the physics engine
|
||||
std::vector<RigidBody*>::iterator getRigidBodiesBeginIterator(); // Return an iterator to the beginning of the bodies of the physics world
|
||||
std::vector<RigidBody*>::iterator getRigidBodiesEndIterator(); // Return an iterator to the end of the bodies of the physics world
|
||||
std::vector<RigidBody*>& getAddedRigidBodies(); // Return the added bodies since last update of the physics engine
|
||||
std::vector<RigidBody*>& getRemovedRigidBodies(); // Retrun the removed bodies since last update of the physics engine
|
||||
};
|
||||
|
||||
|
||||
// Add a body to the physics world
|
||||
inline void PhysicsWorld::addBody(Body* body) {
|
||||
std::vector<Body*>::iterator it;
|
||||
inline void PhysicsWorld::addRigidBody(RigidBody* body) {
|
||||
std::vector<RigidBody*>::iterator it;
|
||||
|
||||
assert(body);
|
||||
it = std::find(bodies.begin(), bodies.end(), body);
|
||||
assert(it == bodies.end());
|
||||
it = std::find(rigidBodies.begin(), rigidBodies.end(), body);
|
||||
assert(it == rigidBodies.end());
|
||||
|
||||
// The body isn't already in the bodyList, therefore we add it to the list
|
||||
bodies.push_back(body);
|
||||
rigidBodies.push_back(body);
|
||||
addedBodies.push_back(body);
|
||||
it = std::find(removedBodies.begin(), removedBodies.end(), body);
|
||||
if (it != removedBodies.end()) {
|
||||
|
@ -100,13 +100,13 @@ inline void PhysicsWorld::addBody(Body* body) {
|
|||
}
|
||||
|
||||
// Remove a body from the physics world
|
||||
inline void PhysicsWorld::removeBody(Body* body) {
|
||||
std::vector<Body*>::iterator it;
|
||||
inline void PhysicsWorld::removeRigidBody(RigidBody* body) {
|
||||
std::vector<RigidBody*>::iterator it;
|
||||
|
||||
assert(body);
|
||||
it = std::find(bodies.begin(), bodies.end(), body);
|
||||
it = std::find(rigidBodies.begin(), rigidBodies.end(), body);
|
||||
assert(*it == body);
|
||||
bodies.erase(it);
|
||||
rigidBodies.erase(it);
|
||||
|
||||
it = std::find(addedBodies.begin(), addedBodies.end(), body);
|
||||
if (it != addedBodies.end()) {
|
||||
|
@ -165,22 +165,22 @@ inline std::vector<Constraint*>::iterator PhysicsWorld::getConstraintsEndIterato
|
|||
}
|
||||
|
||||
// Return an iterator to the beginning of the bodies of the physics world
|
||||
inline std::vector<Body*>::iterator PhysicsWorld::getBodiesBeginIterator() {
|
||||
return bodies.begin();
|
||||
inline std::vector<RigidBody*>::iterator PhysicsWorld::getRigidBodiesBeginIterator() {
|
||||
return rigidBodies.begin();
|
||||
}
|
||||
|
||||
// Return an iterator to the end of the bodies of the physics world
|
||||
inline std::vector<Body*>::iterator PhysicsWorld::getBodiesEndIterator() {
|
||||
return bodies.end();
|
||||
inline std::vector<RigidBody*>::iterator PhysicsWorld::getRigidBodiesEndIterator() {
|
||||
return rigidBodies.end();
|
||||
}
|
||||
|
||||
// Return the added bodies since last update of the physics engine
|
||||
inline std::vector<Body*>& PhysicsWorld::getAddedBodies() {
|
||||
inline std::vector<RigidBody*>& PhysicsWorld::getAddedRigidBodies() {
|
||||
return addedBodies;
|
||||
}
|
||||
|
||||
// Retrun the removed bodies since last update of the physics engine
|
||||
inline std::vector<Body*>& PhysicsWorld::getRemovedBodies() {
|
||||
inline std::vector<RigidBody*>& PhysicsWorld::getRemovedRigidBodies() {
|
||||
return removedBodies;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user