From fcac6457a77f274208c643b7a499af0f1c6773b2 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 6 Aug 2012 22:34:42 +0200 Subject: [PATCH] Add documentation --- src/collision/broadphase/PairManager.h | 4 ++-- src/collision/broadphase/SweepAndPruneAlgorithm.h | 8 ++++++-- src/engine/PhysicsWorld.cpp | 3 +++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/collision/broadphase/PairManager.h b/src/collision/broadphase/PairManager.h index b39b521c..0121fda9 100644 --- a/src/collision/broadphase/PairManager.h +++ b/src/collision/broadphase/PairManager.h @@ -115,7 +115,6 @@ inline bool PairManager::isDifferentPair(const BroadPhasePair& pair1, bodyindex } // Return the next power of two of a 32bits integer using a SWAR algorithm -// TODO : Add documentation inline luint PairManager::computeNextPowerOfTwo(luint number) const { number |= (number >> 1); number |= (number >> 2); @@ -149,7 +148,8 @@ inline void PairManager::sortIDs(bodyindex &id1, bodyindex &id2) const { // This method returns an hash value for a 32 bits key // using Thomas Wang's hash technique. -// TODO : Add documentation here +// This hash function can be found at : +// http://www.concentric.net/~ttwang/tech/inthash.htm inline int PairManager::computeHash32Bits(int key) const { key += ~(key << 15); key ^= (key >> 10); diff --git a/src/collision/broadphase/SweepAndPruneAlgorithm.h b/src/collision/broadphase/SweepAndPruneAlgorithm.h index 35743a6d..a9066d45 100644 --- a/src/collision/broadphase/SweepAndPruneAlgorithm.h +++ b/src/collision/broadphase/SweepAndPruneAlgorithm.h @@ -112,8 +112,12 @@ class SweepAndPruneAlgorithm : public BroadPhaseAlgorithm { virtual void updateObject(Body* body, const AABB& aabb); // Notify the broad-phase that the AABB of an object has changed }; -// TODO : ADD Documentation for this method -// Encode a floating value into a integer value +// Encode a floating value into a integer value in order to +// work with integer comparison in the Sweep-And-Prune algorithm +// because it is faster. The main issue when encoding floating +// number into integer is to keep to sorting order. This is a +// problem for negative float number. This article describes +// how to solve this issue : http://www.stereopsis.com/radix.html inline uint encodeFloatIntoInteger(float number) { uint intNumber = (uint&) number; diff --git a/src/engine/PhysicsWorld.cpp b/src/engine/PhysicsWorld.cpp index 6b57ee9a..9f6e1ad3 100644 --- a/src/engine/PhysicsWorld.cpp +++ b/src/engine/PhysicsWorld.cpp @@ -56,6 +56,9 @@ RigidBody* PhysicsWorld::createRigidBody(const Transform& transform, decimal mas currentBodyID++; } + // Largest index cannot be used (it is used for invalid index) + assert(bodyID < std::numeric_limits::max()); + // Create the rigid body RigidBody* rigidBody = new (memoryPoolRigidBodies.allocateObject()) RigidBody(transform, mass, inertiaTensorLocal, collisionShape, bodyID);