Small modifications
This commit is contained in:
parent
0b3abacb3c
commit
c56557898f
|
@ -158,10 +158,8 @@ inline int Shader::getUniformLocation(const std::string& variableName) const {
|
||||||
|
|
||||||
// Clear the shader
|
// Clear the shader
|
||||||
inline void Shader::destroy() {
|
inline void Shader::destroy() {
|
||||||
if (mProgramObjectID != 0) {
|
glDeleteProgram(mProgramObjectID);
|
||||||
glDeleteShader(mProgramObjectID);
|
mProgramObjectID = 0;
|
||||||
mProgramObjectID = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a float uniform value to this shader (be careful if the uniform is not
|
// Set a float uniform value to this shader (be careful if the uniform is not
|
||||||
|
|
|
@ -145,8 +145,6 @@ void CollisionBody::removeCollisionShape(const ProxyShape* proxyShape) {
|
||||||
// Remove all the collision shapes
|
// Remove all the collision shapes
|
||||||
void CollisionBody::removeAllCollisionShapes() {
|
void CollisionBody::removeAllCollisionShapes() {
|
||||||
|
|
||||||
// TODO : Remove all the contact manifolds at the end of this call
|
|
||||||
|
|
||||||
ProxyShape* current = mProxyCollisionShapes;
|
ProxyShape* current = mProxyCollisionShapes;
|
||||||
|
|
||||||
// Look for the proxy shape that contains the collision shape in parameter
|
// Look for the proxy shape that contains the collision shape in parameter
|
||||||
|
|
|
@ -134,7 +134,7 @@ void CollisionDetection::reportCollisionBetweenShapes(CollisionCallback* callbac
|
||||||
|
|
||||||
// Delete and remove the contact info from the memory allocator
|
// Delete and remove the contact info from the memory allocator
|
||||||
contactInfo->~ContactPointInfo();
|
contactInfo->~ContactPointInfo();
|
||||||
mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo));
|
mWorld->mMemoryAllocator.release(contactInfo, sizeof(ContactPointInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,8 @@ void CollisionDetection::computeNarrowPhase() {
|
||||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||||
++it;
|
++it;
|
||||||
|
|
||||||
|
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||||
|
|
||||||
// Destroy the overlapping pair
|
// Destroy the overlapping pair
|
||||||
itToRemove->second->~OverlappingPair();
|
itToRemove->second->~OverlappingPair();
|
||||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||||
|
@ -287,6 +289,8 @@ void CollisionDetection::computeNarrowPhaseBetweenShapes(CollisionCallback* call
|
||||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||||
++it;
|
++it;
|
||||||
|
|
||||||
|
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||||
|
|
||||||
// Destroy the overlapping pair
|
// Destroy the overlapping pair
|
||||||
itToRemove->second->~OverlappingPair();
|
itToRemove->second->~OverlappingPair();
|
||||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||||
|
@ -380,6 +384,8 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
std::map<overlappingpairid, OverlappingPair*>::iterator itToRemove = it;
|
||||||
++it;
|
++it;
|
||||||
|
|
||||||
|
// TODO : Remove all the contact manifold of the overlapping pair from the contact manifolds list of the two bodies involved
|
||||||
|
|
||||||
// Destroy the overlapping pair
|
// Destroy the overlapping pair
|
||||||
itToRemove->second->~OverlappingPair();
|
itToRemove->second->~OverlappingPair();
|
||||||
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
mWorld->mMemoryAllocator.release(itToRemove->second, sizeof(OverlappingPair));
|
||||||
|
|
|
@ -37,19 +37,19 @@ BroadPhaseAlgorithm::BroadPhaseAlgorithm(CollisionDetection& collisionDetection)
|
||||||
mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8),
|
mNbNonUsedMovedShapes(0), mNbPotentialPairs(0), mNbAllocatedPotentialPairs(8),
|
||||||
mCollisionDetection(collisionDetection) {
|
mCollisionDetection(collisionDetection) {
|
||||||
|
|
||||||
// Allocate memory for the array of non-static bodies IDs
|
// Allocate memory for the array of non-static proxy shapes IDs
|
||||||
mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int));
|
mMovedShapes = (int*) malloc(mNbAllocatedMovedShapes * sizeof(int));
|
||||||
assert(mMovedShapes != NULL);
|
assert(mMovedShapes != NULL);
|
||||||
|
|
||||||
// Allocate memory for the array of potential overlapping pairs
|
// Allocate memory for the array of potential overlapping pairs
|
||||||
mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair));
|
mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
|
||||||
assert(mPotentialPairs != NULL);
|
assert(mPotentialPairs != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
BroadPhaseAlgorithm::~BroadPhaseAlgorithm() {
|
BroadPhaseAlgorithm::~BroadPhaseAlgorithm() {
|
||||||
|
|
||||||
// Release the memory for the array of non-static bodies IDs
|
// Release the memory for the array of non-static proxy shapes IDs
|
||||||
free(mMovedShapes);
|
free(mMovedShapes);
|
||||||
|
|
||||||
// Release the memory for the array of potential overlapping pairs
|
// Release the memory for the array of potential overlapping pairs
|
||||||
|
@ -60,7 +60,7 @@ BroadPhaseAlgorithm::~BroadPhaseAlgorithm() {
|
||||||
// and that need to be tested again for broad-phase overlapping.
|
// and that need to be tested again for broad-phase overlapping.
|
||||||
void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
|
void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
|
||||||
|
|
||||||
// Allocate more elements in the array of bodies that have moved if necessary
|
// Allocate more elements in the array of shapes that have moved if necessary
|
||||||
if (mNbAllocatedMovedShapes == mNbMovedShapes) {
|
if (mNbAllocatedMovedShapes == mNbMovedShapes) {
|
||||||
mNbAllocatedMovedShapes *= 2;
|
mNbAllocatedMovedShapes *= 2;
|
||||||
int* oldArray = mMovedShapes;
|
int* oldArray = mMovedShapes;
|
||||||
|
@ -70,7 +70,7 @@ void BroadPhaseAlgorithm::addMovedCollisionShape(int broadPhaseID) {
|
||||||
free(oldArray);
|
free(oldArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the broad-phase ID into the array of bodies that have moved
|
// Store the broad-phase ID into the array of shapes that have moved
|
||||||
assert(mNbMovedShapes < mNbAllocatedMovedShapes);
|
assert(mNbMovedShapes < mNbAllocatedMovedShapes);
|
||||||
assert(mMovedShapes != NULL);
|
assert(mMovedShapes != NULL);
|
||||||
mMovedShapes[mNbMovedShapes] = broadPhaseID;
|
mMovedShapes[mNbMovedShapes] = broadPhaseID;
|
||||||
|
@ -83,7 +83,7 @@ void BroadPhaseAlgorithm::removeMovedCollisionShape(int broadPhaseID) {
|
||||||
|
|
||||||
assert(mNbNonUsedMovedShapes <= mNbMovedShapes);
|
assert(mNbNonUsedMovedShapes <= mNbMovedShapes);
|
||||||
|
|
||||||
// If less than the quarter of allocated elements of the non-static bodies IDs array
|
// If less than the quarter of allocated elements of the non-static shapes IDs array
|
||||||
// are used, we release some allocated memory
|
// are used, we release some allocated memory
|
||||||
if ((mNbMovedShapes - mNbNonUsedMovedShapes) < mNbAllocatedMovedShapes / 4 &&
|
if ((mNbMovedShapes - mNbNonUsedMovedShapes) < mNbAllocatedMovedShapes / 4 &&
|
||||||
mNbAllocatedMovedShapes > 8) {
|
mNbAllocatedMovedShapes > 8) {
|
||||||
|
@ -133,7 +133,7 @@ void BroadPhaseAlgorithm::removeProxyCollisionShape(ProxyShape* proxyShape) {
|
||||||
// Remove the collision shape from the dynamic AABB tree
|
// Remove the collision shape from the dynamic AABB tree
|
||||||
mDynamicAABBTree.removeObject(broadPhaseID);
|
mDynamicAABBTree.removeObject(broadPhaseID);
|
||||||
|
|
||||||
// Remove the collision shape into the array of bodies that have moved (or have been created)
|
// Remove the collision shape into the array of shapes that have moved (or have been created)
|
||||||
// during the last simulation step
|
// during the last simulation step
|
||||||
removeMovedCollisionShape(broadPhaseID);
|
removeMovedCollisionShape(broadPhaseID);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ void BroadPhaseAlgorithm::updateProxyCollisionShape(ProxyShape* proxyShape, cons
|
||||||
// into the tree).
|
// into the tree).
|
||||||
if (hasBeenReInserted) {
|
if (hasBeenReInserted) {
|
||||||
|
|
||||||
// Add the collision shape into the array of bodies that have moved (or have been created)
|
// Add the collision shape into the array of shapes that have moved (or have been created)
|
||||||
// during the last simulation step
|
// during the last simulation step
|
||||||
addMovedCollisionShape(broadPhaseID);
|
addMovedCollisionShape(broadPhaseID);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
||||||
mNbMovedShapes = 0;
|
mNbMovedShapes = 0;
|
||||||
|
|
||||||
// Sort the array of potential overlapping pairs in order to remove duplicate pairs
|
// Sort the array of potential overlapping pairs in order to remove duplicate pairs
|
||||||
std::sort(mPotentialPairs, mPotentialPairs + mNbPotentialPairs, BroadPair::smallerThan);
|
std::sort(mPotentialPairs, mPotentialPairs + mNbPotentialPairs, BroadPhasePair::smallerThan);
|
||||||
|
|
||||||
// Check all the potential overlapping pairs avoiding duplicates to report unique
|
// Check all the potential overlapping pairs avoiding duplicates to report unique
|
||||||
// overlapping pairs
|
// overlapping pairs
|
||||||
|
@ -194,7 +194,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
||||||
while (i < mNbPotentialPairs) {
|
while (i < mNbPotentialPairs) {
|
||||||
|
|
||||||
// Get a potential overlapping pair
|
// Get a potential overlapping pair
|
||||||
BroadPair* pair = mPotentialPairs + i;
|
BroadPhasePair* pair = mPotentialPairs + i;
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
// Get the two collision shapes of the pair
|
// Get the two collision shapes of the pair
|
||||||
|
@ -208,7 +208,7 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
||||||
while (i < mNbPotentialPairs) {
|
while (i < mNbPotentialPairs) {
|
||||||
|
|
||||||
// Get the next pair
|
// Get the next pair
|
||||||
BroadPair* nextPair = mPotentialPairs + i;
|
BroadPhasePair* nextPair = mPotentialPairs + i;
|
||||||
|
|
||||||
// If the next pair is different from the previous one, we stop skipping pairs
|
// If the next pair is different from the previous one, we stop skipping pairs
|
||||||
if (nextPair->collisionShape1ID != pair->collisionShape1ID ||
|
if (nextPair->collisionShape1ID != pair->collisionShape1ID ||
|
||||||
|
@ -224,11 +224,11 @@ void BroadPhaseAlgorithm::computeOverlappingPairs() {
|
||||||
if (mNbPotentialPairs < mNbAllocatedPotentialPairs / 4 && mNbPotentialPairs > 8) {
|
if (mNbPotentialPairs < mNbAllocatedPotentialPairs / 4 && mNbPotentialPairs > 8) {
|
||||||
|
|
||||||
// Reduce the number of allocated potential overlapping pairs
|
// Reduce the number of allocated potential overlapping pairs
|
||||||
BroadPair* oldPairs = mPotentialPairs;
|
BroadPhasePair* oldPairs = mPotentialPairs;
|
||||||
mNbAllocatedPotentialPairs /= 2;
|
mNbAllocatedPotentialPairs /= 2;
|
||||||
mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair));
|
mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
|
||||||
assert(mPotentialPairs);
|
assert(mPotentialPairs);
|
||||||
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPair));
|
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair));
|
||||||
free(oldPairs);
|
free(oldPairs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,11 +243,11 @@ void BroadPhaseAlgorithm::notifyOverlappingPair(int node1ID, int node2ID) {
|
||||||
if (mNbPotentialPairs == mNbAllocatedPotentialPairs) {
|
if (mNbPotentialPairs == mNbAllocatedPotentialPairs) {
|
||||||
|
|
||||||
// Allocate more memory for the array of potential pairs
|
// Allocate more memory for the array of potential pairs
|
||||||
BroadPair* oldPairs = mPotentialPairs;
|
BroadPhasePair* oldPairs = mPotentialPairs;
|
||||||
mNbAllocatedPotentialPairs *= 2;
|
mNbAllocatedPotentialPairs *= 2;
|
||||||
mPotentialPairs = (BroadPair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPair));
|
mPotentialPairs = (BroadPhasePair*) malloc(mNbAllocatedPotentialPairs * sizeof(BroadPhasePair));
|
||||||
assert(mPotentialPairs);
|
assert(mPotentialPairs);
|
||||||
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPair));
|
memcpy(mPotentialPairs, oldPairs, mNbPotentialPairs * sizeof(BroadPhasePair));
|
||||||
free(oldPairs);
|
free(oldPairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,20 +38,12 @@ namespace reactphysics3d {
|
||||||
// Declarations
|
// Declarations
|
||||||
class CollisionDetection;
|
class CollisionDetection;
|
||||||
|
|
||||||
// TODO : Check that when a kinematic or static body is manually moved, the dynamic aabb tree
|
// Structure BroadPhasePair
|
||||||
// is correctly updated
|
|
||||||
|
|
||||||
// TODO : Replace the names "body, bodies" by "collision shapes"
|
|
||||||
|
|
||||||
// TODO : Remove the pair manager
|
|
||||||
|
|
||||||
// TODO : RENAME THIS
|
|
||||||
// Structure BroadPair
|
|
||||||
/**
|
/**
|
||||||
* This structure represent a potential overlapping pair during the broad-phase collision
|
* This structure represent a potential overlapping pair during the
|
||||||
* detection.
|
* broad-phase collision detection.
|
||||||
*/
|
*/
|
||||||
struct BroadPair {
|
struct BroadPhasePair {
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
|
@ -64,13 +56,13 @@ struct BroadPair {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Method used to compare two pairs for sorting algorithm
|
/// Method used to compare two pairs for sorting algorithm
|
||||||
static bool smallerThan(const BroadPair& pair1, const BroadPair& pair2);
|
static bool smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class BroadPhaseAlgorithm
|
// Class BroadPhaseAlgorithm
|
||||||
/**
|
/**
|
||||||
* This class represents the broad-phase collision detection. The
|
* This class represents the broad-phase collision detection. The
|
||||||
* goal of the broad-phase collision detection is to compute the pairs of bodies
|
* goal of the broad-phase collision detection is to compute the pairs of proxy shapes
|
||||||
* that have their AABBs overlapping. Only those pairs of bodies will be tested
|
* that have their AABBs overlapping. Only those pairs of bodies will be tested
|
||||||
* later for collision during the narrow-phase collision detection. A dynamic AABB
|
* later for collision during the narrow-phase collision detection. A dynamic AABB
|
||||||
* tree data structure is used for fast broad-phase collision detection.
|
* tree data structure is used for fast broad-phase collision detection.
|
||||||
|
@ -102,7 +94,7 @@ class BroadPhaseAlgorithm {
|
||||||
uint mNbNonUsedMovedShapes;
|
uint mNbNonUsedMovedShapes;
|
||||||
|
|
||||||
/// Temporary array of potential overlapping pairs (with potential duplicates)
|
/// Temporary array of potential overlapping pairs (with potential duplicates)
|
||||||
BroadPair* mPotentialPairs;
|
BroadPhasePair* mPotentialPairs;
|
||||||
|
|
||||||
/// Number of potential overlapping pairs
|
/// Number of potential overlapping pairs
|
||||||
uint mNbPotentialPairs;
|
uint mNbPotentialPairs;
|
||||||
|
@ -164,7 +156,7 @@ class BroadPhaseAlgorithm {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Method used to compare two pairs for sorting algorithm
|
// Method used to compare two pairs for sorting algorithm
|
||||||
inline bool BroadPair::smallerThan(const BroadPair& pair1, const BroadPair& pair2) {
|
inline bool BroadPhasePair::smallerThan(const BroadPhasePair& pair1, const BroadPhasePair& pair2) {
|
||||||
|
|
||||||
if (pair1.collisionShape1ID < pair2.collisionShape1ID) return true;
|
if (pair1.collisionShape1ID < pair2.collisionShape1ID) return true;
|
||||||
if (pair1.collisionShape1ID == pair2.collisionShape1ID) {
|
if (pair1.collisionShape1ID == pair2.collisionShape1ID) {
|
||||||
|
@ -185,8 +177,7 @@ inline bool BroadPhaseAlgorithm::testOverlappingShapes(const ProxyShape* shape1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ray casting method
|
// Ray casting method
|
||||||
inline void BroadPhaseAlgorithm::raycast(const Ray& ray,
|
inline void BroadPhaseAlgorithm::raycast(const Ray& ray, RaycastTest& raycastTest,
|
||||||
RaycastTest& raycastTest,
|
|
||||||
unsigned short raycastWithCategoryMaskBits) const {
|
unsigned short raycastWithCategoryMaskBits) const {
|
||||||
mDynamicAABBTree.raycast(ray, raycastTest, raycastWithCategoryMaskBits);
|
mDynamicAABBTree.raycast(ray, raycastTest, raycastWithCategoryMaskBits);
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,10 +190,6 @@ void DynamicsWorld::integrateRigidBodiesPositions() {
|
||||||
mConstrainedOrientations[indexArray] = currentOrientation +
|
mConstrainedOrientations[indexArray] = currentOrientation +
|
||||||
Quaternion(0, newAngVelocity) *
|
Quaternion(0, newAngVelocity) *
|
||||||
currentOrientation * decimal(0.5) * dt;
|
currentOrientation * decimal(0.5) * dt;
|
||||||
|
|
||||||
// TODO : DELETE THIS
|
|
||||||
Vector3 newPos = mConstrainedPositions[indexArray];
|
|
||||||
Quaternion newOrientation = mConstrainedOrientations[indexArray];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,6 @@ class OverlappingPair {
|
||||||
Vector3 getCachedSeparatingAxis() const;
|
Vector3 getCachedSeparatingAxis() const;
|
||||||
|
|
||||||
/// Set the cached separating axis
|
/// Set the cached separating axis
|
||||||
// TODO : Check that this variable is correctly used allong the collision detection process
|
|
||||||
void setCachedSeparatingAxis(const Vector3& axis);
|
void setCachedSeparatingAxis(const Vector3& axis);
|
||||||
|
|
||||||
/// Return the number of contacts in the cache
|
/// Return the number of contacts in the cache
|
||||||
|
|
Loading…
Reference in New Issue
Block a user