Take care of TODOs
This commit is contained in:
parent
d491665332
commit
59cdc6b8f8
|
@ -14,6 +14,9 @@
|
||||||
- DynamicsWorld::getContactsList(). You need to use the EventListener class to retrieve contacts now.
|
- DynamicsWorld::getContactsList(). You need to use the EventListener class to retrieve contacts now.
|
||||||
- The DynamicsWorld::getNbJoints() method has been removed.
|
- The DynamicsWorld::getNbJoints() method has been removed.
|
||||||
- The DynamicsWorld::getNbRigidBodies() method has been removed.
|
- The DynamicsWorld::getNbRigidBodies() method has been removed.
|
||||||
|
- The EventListener::beginInternalTick() method has been removed (because internal ticks do not exist anymore).
|
||||||
|
- The EventListener::endInternalTick() method has been removed (because internal ticks do not exist anymore).
|
||||||
|
- The RigidBody::getJointsList() method has been removed.
|
||||||
|
|
||||||
## Release Candidate
|
## Release Candidate
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ ProxyShape* CollisionBody::addCollisionShape(CollisionShape* collisionShape, con
|
||||||
Vector3 localBoundsMax;
|
Vector3 localBoundsMax;
|
||||||
// TODO : Maybe this method can directly returns an AABB
|
// TODO : Maybe this method can directly returns an AABB
|
||||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||||
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, -1,
|
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape,
|
||||||
AABB(localBoundsMin, localBoundsMax),
|
AABB(localBoundsMin, localBoundsMax),
|
||||||
transform, collisionShape, decimal(1), 0x0001, 0xFFFF);
|
transform, collisionShape, decimal(1), 0x0001, 0xFFFF);
|
||||||
bool isActive = mWorld.mCollisionBodyComponents.getIsActive(mEntity);
|
bool isActive = mWorld.mCollisionBodyComponents.getIsActive(mEntity);
|
||||||
|
@ -208,8 +208,6 @@ void CollisionBody::removeAllCollisionShapes() {
|
||||||
*/
|
*/
|
||||||
const Transform& CollisionBody::getTransform() const {
|
const Transform& CollisionBody::getTransform() const {
|
||||||
|
|
||||||
// TODO : Make sure we do not call this method from the internal physics engine
|
|
||||||
|
|
||||||
return mWorld.mTransformComponents.getTransform(mEntity);
|
return mWorld.mTransformComponents.getTransform(mEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,8 +352,6 @@ AABB CollisionBody::getAABB() const {
|
||||||
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
const List<Entity>& proxyShapesEntities = mWorld.mCollisionBodyComponents.getProxyShapes(mEntity);
|
||||||
if (proxyShapesEntities.size() == 0) return bodyAABB;
|
if (proxyShapesEntities.size() == 0) return bodyAABB;
|
||||||
|
|
||||||
// TODO : Make sure we compute this in a system
|
|
||||||
|
|
||||||
const Transform& transform = mWorld.mTransformComponents.getTransform(mEntity);
|
const Transform& transform = mWorld.mTransformComponents.getTransform(mEntity);
|
||||||
|
|
||||||
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[0]);
|
ProxyShape* proxyShape = mWorld.mProxyShapesComponents.getProxyShape(proxyShapesEntities[0]);
|
||||||
|
@ -384,8 +380,6 @@ AABB CollisionBody::getAABB() const {
|
||||||
*/
|
*/
|
||||||
void CollisionBody::setTransform(const Transform& transform) {
|
void CollisionBody::setTransform(const Transform& transform) {
|
||||||
|
|
||||||
// TODO : Make sure this method is never called from the internal physics engine
|
|
||||||
|
|
||||||
// Update the transform of the body
|
// Update the transform of the body
|
||||||
mWorld.mTransformComponents.setTransform(mEntity, transform);
|
mWorld.mTransformComponents.setTransform(mEntity, transform);
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,6 @@ void RigidBody::setInverseInertiaTensorLocal(const Matrix3x3& inverseInertiaTens
|
||||||
*/
|
*/
|
||||||
void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
||||||
|
|
||||||
// TODO : Check if we need to update the postion of the body here at the end (transform of the body)
|
|
||||||
|
|
||||||
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) != BodyType::DYNAMIC) return;
|
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) != BodyType::DYNAMIC) return;
|
||||||
|
|
||||||
mIsCenterOfMassSetByUser = true;
|
mIsCenterOfMassSetByUser = true;
|
||||||
|
@ -270,8 +268,7 @@ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
||||||
mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMassLocal);
|
mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMassLocal);
|
||||||
|
|
||||||
// Compute the center of mass in world-space coordinates
|
// Compute the center of mass in world-space coordinates
|
||||||
const Vector3& updatedCenterOfMassLocal = mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity);
|
mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * centerOfMassLocal);
|
||||||
mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * updatedCenterOfMassLocal);
|
|
||||||
|
|
||||||
// Update the linear velocity of the center of mass
|
// Update the linear velocity of the center of mass
|
||||||
Vector3 linearVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
Vector3 linearVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
|
@ -340,7 +337,7 @@ ProxyShape* RigidBody::addCollisionShape(CollisionShape* collisionShape,
|
||||||
// TODO : Maybe this method can directly returns an AABB
|
// TODO : Maybe this method can directly returns an AABB
|
||||||
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
collisionShape->getLocalBounds(localBoundsMin, localBoundsMax);
|
||||||
|
|
||||||
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape, -1,
|
ProxyShapeComponents::ProxyShapeComponent proxyShapeComponent(mEntity, proxyShape,
|
||||||
AABB(localBoundsMin, localBoundsMax),
|
AABB(localBoundsMin, localBoundsMax),
|
||||||
transform, collisionShape, mass, 0x0001, 0xFFFF);
|
transform, collisionShape, mass, 0x0001, 0xFFFF);
|
||||||
bool isSleeping = mWorld.mRigidBodyComponents.getIsSleeping(mEntity);
|
bool isSleeping = mWorld.mRigidBodyComponents.getIsSleeping(mEntity);
|
||||||
|
@ -438,18 +435,6 @@ void RigidBody::setAngularDamping(decimal angularDamping) {
|
||||||
"Body " + std::to_string(mEntity.id) + ": Set angularDamping=" + std::to_string(angularDamping));
|
"Body " + std::to_string(mEntity.id) + ": Set angularDamping=" + std::to_string(angularDamping));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the transform of the body after a change of the center of mass
|
|
||||||
void RigidBody::updateTransformWithCenterOfMass() {
|
|
||||||
|
|
||||||
// TODO : Make sure we compute this in a system
|
|
||||||
|
|
||||||
// Translate the body according to the translation of the center of mass position
|
|
||||||
Transform& transform = mWorld.mTransformComponents.getTransform(mEntity);
|
|
||||||
const Vector3& centerOfMassWorld = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);
|
|
||||||
const Vector3& centerOfMassLocal = mWorld.mRigidBodyComponents.getCenterOfMassLocal(mEntity);
|
|
||||||
transform.setPosition(centerOfMassWorld - transform.getOrientation() * centerOfMassLocal);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a new material for this rigid body
|
// Set a new material for this rigid body
|
||||||
/**
|
/**
|
||||||
* @param material The material you want to set to the body
|
* @param material The material you want to set to the body
|
||||||
|
@ -488,8 +473,6 @@ void RigidBody::setLinearVelocity(const Vector3& linearVelocity) {
|
||||||
*/
|
*/
|
||||||
void RigidBody::setAngularVelocity(const Vector3& angularVelocity) {
|
void RigidBody::setAngularVelocity(const Vector3& angularVelocity) {
|
||||||
|
|
||||||
// TODO : Make sure this method is not called from the internal physics engine
|
|
||||||
|
|
||||||
// If it is a static body, we do nothing
|
// If it is a static body, we do nothing
|
||||||
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,6 @@ class RigidBody : public CollisionBody {
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Update the transform of the body after a change of the center of mass
|
|
||||||
void updateTransformWithCenterOfMass();
|
|
||||||
|
|
||||||
/// Set the variable to know whether or not the body is sleeping
|
/// Set the variable to know whether or not the body is sleeping
|
||||||
void setIsSleeping(bool isSleeping);
|
void setIsSleeping(bool isSleeping);
|
||||||
|
|
||||||
|
@ -161,14 +158,6 @@ class RigidBody : public CollisionBody {
|
||||||
/// Set the angular damping factor
|
/// Set the angular damping factor
|
||||||
void setAngularDamping(decimal angularDamping);
|
void setAngularDamping(decimal angularDamping);
|
||||||
|
|
||||||
/// Return the first element of the linked list of joints involving this body
|
|
||||||
// TODO : Remove this
|
|
||||||
const JointListElement* getJointsList() const;
|
|
||||||
|
|
||||||
/// Return the first element of the linked list of joints involving this body
|
|
||||||
// TODO : Remove this
|
|
||||||
JointListElement* getJointsList();
|
|
||||||
|
|
||||||
/// Apply an external force to the body at its center of mass.
|
/// Apply an external force to the body at its center of mass.
|
||||||
void applyForceToCenterOfMass(const Vector3& force);
|
void applyForceToCenterOfMass(const Vector3& force);
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,6 @@ void ProxyShape::setCollideWithMaskBits(unsigned short collideWithMaskBits) {
|
||||||
// Set the local to parent body transform
|
// Set the local to parent body transform
|
||||||
void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
void ProxyShape::setLocalToBodyTransform(const Transform& transform) {
|
||||||
|
|
||||||
// TODO : Make sure this method is never called by the internal physics engine
|
|
||||||
|
|
||||||
mBody->mWorld.mProxyShapesComponents.setLocalToBodyTransform(mEntity, transform);
|
mBody->mWorld.mProxyShapesComponents.setLocalToBodyTransform(mEntity, transform);
|
||||||
|
|
||||||
RigidBody* rigidBody = static_cast<RigidBody*>(mBody);
|
RigidBody* rigidBody = static_cast<RigidBody*>(mBody);
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Initialization of static variables
|
// Initialization of static variables
|
||||||
const int TreeNode::NULL_TREE_NODE = -1;
|
const int32 TreeNode::NULL_TREE_NODE = -1;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
DynamicAABBTree::DynamicAABBTree(MemoryAllocator& allocator, decimal extraAABBGap)
|
DynamicAABBTree::DynamicAABBTree(MemoryAllocator& allocator, decimal extraAABBGap)
|
||||||
|
@ -45,7 +45,7 @@ DynamicAABBTree::DynamicAABBTree(MemoryAllocator& allocator, decimal extraAABBGa
|
||||||
DynamicAABBTree::~DynamicAABBTree() {
|
DynamicAABBTree::~DynamicAABBTree() {
|
||||||
|
|
||||||
// Free the allocated memory for the nodes
|
// Free the allocated memory for the nodes
|
||||||
mAllocator.release(mNodes, mNbAllocatedNodes * sizeof(TreeNode));
|
mAllocator.release(mNodes, static_cast<size_t>(mNbAllocatedNodes) * sizeof(TreeNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the tree
|
// Initialize the tree
|
||||||
|
@ -56,12 +56,12 @@ void DynamicAABBTree::init() {
|
||||||
mNbAllocatedNodes = 8;
|
mNbAllocatedNodes = 8;
|
||||||
|
|
||||||
// Allocate memory for the nodes of the tree
|
// Allocate memory for the nodes of the tree
|
||||||
mNodes = static_cast<TreeNode*>(mAllocator.allocate(mNbAllocatedNodes * sizeof(TreeNode)));
|
mNodes = static_cast<TreeNode*>(mAllocator.allocate(static_cast<size_t>(mNbAllocatedNodes) * sizeof(TreeNode)));
|
||||||
assert(mNodes);
|
assert(mNodes);
|
||||||
std::memset(mNodes, 0, mNbAllocatedNodes * sizeof(TreeNode));
|
std::memset(mNodes, 0, static_cast<size_t>(mNbAllocatedNodes) * sizeof(TreeNode));
|
||||||
|
|
||||||
// Initialize the allocated nodes
|
// Initialize the allocated nodes
|
||||||
for (int i=0; i<mNbAllocatedNodes - 1; i++) {
|
for (int32 i=0; i<mNbAllocatedNodes - 1; i++) {
|
||||||
mNodes[i].nextNodeID = i + 1;
|
mNodes[i].nextNodeID = i + 1;
|
||||||
mNodes[i].height = -1;
|
mNodes[i].height = -1;
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,14 @@ void DynamicAABBTree::init() {
|
||||||
void DynamicAABBTree::reset() {
|
void DynamicAABBTree::reset() {
|
||||||
|
|
||||||
// Free the allocated memory for the nodes
|
// Free the allocated memory for the nodes
|
||||||
mAllocator.release(mNodes, mNbAllocatedNodes * sizeof(TreeNode));
|
mAllocator.release(mNodes, static_cast<size_t>(mNbAllocatedNodes) * sizeof(TreeNode));
|
||||||
|
|
||||||
// Initialize the tree
|
// Initialize the tree
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate and return a new node in the tree
|
// Allocate and return a new node in the tree
|
||||||
int DynamicAABBTree::allocateNode() {
|
int32 DynamicAABBTree::allocateNode() {
|
||||||
|
|
||||||
// If there is no more allocated node to use
|
// If there is no more allocated node to use
|
||||||
if (mFreeNodeID == TreeNode::NULL_TREE_NODE) {
|
if (mFreeNodeID == TreeNode::NULL_TREE_NODE) {
|
||||||
|
@ -89,16 +89,16 @@ int DynamicAABBTree::allocateNode() {
|
||||||
assert(mNbNodes == mNbAllocatedNodes);
|
assert(mNbNodes == mNbAllocatedNodes);
|
||||||
|
|
||||||
// Allocate more nodes in the tree
|
// Allocate more nodes in the tree
|
||||||
uint oldNbAllocatedNodes = mNbAllocatedNodes;
|
int32 oldNbAllocatedNodes = mNbAllocatedNodes;
|
||||||
mNbAllocatedNodes *= 2;
|
mNbAllocatedNodes *= 2;
|
||||||
TreeNode* oldNodes = mNodes;
|
TreeNode* oldNodes = mNodes;
|
||||||
mNodes = static_cast<TreeNode*>(mAllocator.allocate(mNbAllocatedNodes * sizeof(TreeNode)));
|
mNodes = static_cast<TreeNode*>(mAllocator.allocate(static_cast<size_t>(mNbAllocatedNodes) * sizeof(TreeNode)));
|
||||||
assert(mNodes);
|
assert(mNodes);
|
||||||
memcpy(mNodes, oldNodes, mNbNodes * sizeof(TreeNode));
|
memcpy(mNodes, oldNodes, static_cast<size_t>(mNbNodes) * sizeof(TreeNode));
|
||||||
mAllocator.release(oldNodes, oldNbAllocatedNodes * sizeof(TreeNode));
|
mAllocator.release(oldNodes, static_cast<size_t>(oldNbAllocatedNodes) * sizeof(TreeNode));
|
||||||
|
|
||||||
// Initialize the allocated nodes
|
// Initialize the allocated nodes
|
||||||
for (int i=mNbNodes; i<mNbAllocatedNodes - 1; i++) {
|
for (int32 i=mNbNodes; i<mNbAllocatedNodes - 1; i++) {
|
||||||
mNodes[i].nextNodeID = i + 1;
|
mNodes[i].nextNodeID = i + 1;
|
||||||
mNodes[i].height = -1;
|
mNodes[i].height = -1;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ int DynamicAABBTree::allocateNode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the next free node
|
// Get the next free node
|
||||||
int freeNodeID = mFreeNodeID;
|
int32 freeNodeID = mFreeNodeID;
|
||||||
mFreeNodeID = mNodes[freeNodeID].nextNodeID;
|
mFreeNodeID = mNodes[freeNodeID].nextNodeID;
|
||||||
mNodes[freeNodeID].parentID = TreeNode::NULL_TREE_NODE;
|
mNodes[freeNodeID].parentID = TreeNode::NULL_TREE_NODE;
|
||||||
mNodes[freeNodeID].height = 0;
|
mNodes[freeNodeID].height = 0;
|
||||||
|
@ -130,10 +130,10 @@ void DynamicAABBTree::releaseNode(int nodeID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internally add an object into the tree
|
// Internally add an object into the tree
|
||||||
int DynamicAABBTree::addObjectInternal(const AABB& aabb) {
|
int32 DynamicAABBTree::addObjectInternal(const AABB& aabb) {
|
||||||
|
|
||||||
// Get the next available node (or allocate new ones if necessary)
|
// Get the next available node (or allocate new ones if necessary)
|
||||||
int nodeID = allocateNode();
|
int32 nodeID = allocateNode();
|
||||||
|
|
||||||
// Create the fat aabb to use in the tree
|
// Create the fat aabb to use in the tree
|
||||||
const Vector3 gap(mExtraAABBGap, mExtraAABBGap, mExtraAABBGap);
|
const Vector3 gap(mExtraAABBGap, mExtraAABBGap, mExtraAABBGap);
|
||||||
|
@ -154,7 +154,7 @@ int DynamicAABBTree::addObjectInternal(const AABB& aabb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove an object from the tree
|
// Remove an object from the tree
|
||||||
void DynamicAABBTree::removeObject(int nodeID) {
|
void DynamicAABBTree::removeObject(int32 nodeID) {
|
||||||
|
|
||||||
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
||||||
assert(mNodes[nodeID].isLeaf());
|
assert(mNodes[nodeID].isLeaf());
|
||||||
|
@ -170,7 +170,7 @@ void DynamicAABBTree::removeObject(int nodeID) {
|
||||||
/// The method returns true if the object has been reinserted into the tree. The "displacement"
|
/// The method returns true if the object has been reinserted into the tree. The "displacement"
|
||||||
/// argument is the linear velocity of the AABB multiplied by the elapsed time between two
|
/// argument is the linear velocity of the AABB multiplied by the elapsed time between two
|
||||||
/// frames.
|
/// frames.
|
||||||
bool DynamicAABBTree::updateObject(int nodeID, const AABB& newAABB, const Vector3& displacement) {
|
bool DynamicAABBTree::updateObject(int32 nodeID, const AABB& newAABB, const Vector3& displacement) {
|
||||||
|
|
||||||
RP3D_PROFILE("DynamicAABBTree::updateObject()", mProfiler);
|
RP3D_PROFILE("DynamicAABBTree::updateObject()", mProfiler);
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ void DynamicAABBTree::removeLeafNode(int nodeID) {
|
||||||
// Balance the sub-tree of a given node using left or right rotations.
|
// Balance the sub-tree of a given node using left or right rotations.
|
||||||
/// The rotation schemes are described in the book "Introduction to Game Physics
|
/// The rotation schemes are described in the book "Introduction to Game Physics
|
||||||
/// with Box2D" by Ian Parberry. This method returns the new root node ID.
|
/// with Box2D" by Ian Parberry. This method returns the new root node ID.
|
||||||
int DynamicAABBTree::balanceSubTreeAtNode(int nodeID) {
|
int32 DynamicAABBTree::balanceSubTreeAtNode(int32 nodeID) {
|
||||||
|
|
||||||
assert(nodeID != TreeNode::NULL_TREE_NODE);
|
assert(nodeID != TreeNode::NULL_TREE_NODE);
|
||||||
|
|
||||||
|
@ -593,11 +593,11 @@ int DynamicAABBTree::balanceSubTreeAtNode(int nodeID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take a list of shapes to be tested for broad-phase overlap and return a list of pair of overlapping shapes
|
/// Take a list of shapes to be tested for broad-phase overlap and return a list of pair of overlapping shapes
|
||||||
void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List<int>& nodesToTest, size_t startIndex,
|
void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List<int32>& nodesToTest, size_t startIndex,
|
||||||
size_t endIndex, List<Pair<int, int>>& outOverlappingNodes) const {
|
size_t endIndex, List<Pair<int32, int32>>& outOverlappingNodes) const {
|
||||||
|
|
||||||
// Create a stack with the nodes to visit
|
// Create a stack with the nodes to visit
|
||||||
Stack<int> stack(mAllocator, 64);
|
Stack<int32> stack(mAllocator, 64);
|
||||||
|
|
||||||
// For each shape to be tested for overlap
|
// For each shape to be tested for overlap
|
||||||
for (uint i=startIndex; i < endIndex; i++) {
|
for (uint i=startIndex; i < endIndex; i++) {
|
||||||
|
@ -612,7 +612,7 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List<int>& node
|
||||||
while(stack.size() > 0) {
|
while(stack.size() > 0) {
|
||||||
|
|
||||||
// Get the next node ID to visit
|
// Get the next node ID to visit
|
||||||
const int nodeIDToVisit = stack.pop();
|
const int32 nodeIDToVisit = stack.pop();
|
||||||
|
|
||||||
// Skip it if it is a null node
|
// Skip it if it is a null node
|
||||||
if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue;
|
if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue;
|
||||||
|
@ -627,7 +627,7 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List<int>& node
|
||||||
if (nodeToVisit->isLeaf()) {
|
if (nodeToVisit->isLeaf()) {
|
||||||
|
|
||||||
// Add the node in the list of overlapping nodes
|
// Add the node in the list of overlapping nodes
|
||||||
outOverlappingNodes.add(Pair<int, int>(nodesToTest[i], nodeIDToVisit));
|
outOverlappingNodes.add(Pair<int32, int32>(nodesToTest[i], nodeIDToVisit));
|
||||||
}
|
}
|
||||||
else { // If the node is not a leaf
|
else { // If the node is not a leaf
|
||||||
|
|
||||||
|
@ -643,17 +643,17 @@ void DynamicAABBTree::reportAllShapesOverlappingWithShapes(const List<int>& node
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report all shapes overlapping with the AABB given in parameter.
|
// Report all shapes overlapping with the AABB given in parameter.
|
||||||
void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb, List<int>& overlappingNodes) const {
|
void DynamicAABBTree::reportAllShapesOverlappingWithAABB(const AABB& aabb, List<int32>& overlappingNodes) const {
|
||||||
|
|
||||||
// Create a stack with the nodes to visit
|
// Create a stack with the nodes to visit
|
||||||
Stack<int> stack(mAllocator, 64);
|
Stack<int32> stack(mAllocator, 64);
|
||||||
stack.push(mRootNodeID);
|
stack.push(mRootNodeID);
|
||||||
|
|
||||||
// While there are still nodes to visit
|
// While there are still nodes to visit
|
||||||
while(stack.size() > 0) {
|
while(stack.size() > 0) {
|
||||||
|
|
||||||
// Get the next node ID to visit
|
// Get the next node ID to visit
|
||||||
const int nodeIDToVisit = stack.pop();
|
const int32 nodeIDToVisit = stack.pop();
|
||||||
|
|
||||||
// Skip it if it is a null node
|
// Skip it if it is a null node
|
||||||
if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue;
|
if (nodeIDToVisit == TreeNode::NULL_TREE_NODE) continue;
|
||||||
|
@ -687,7 +687,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca
|
||||||
|
|
||||||
decimal maxFraction = ray.maxFraction;
|
decimal maxFraction = ray.maxFraction;
|
||||||
|
|
||||||
Stack<int> stack(mAllocator, 128);
|
Stack<int32> stack(mAllocator, 128);
|
||||||
stack.push(mRootNodeID);
|
stack.push(mRootNodeID);
|
||||||
|
|
||||||
// Walk through the tree from the root looking for proxy shapes
|
// Walk through the tree from the root looking for proxy shapes
|
||||||
|
@ -695,7 +695,7 @@ void DynamicAABBTree::raycast(const Ray& ray, DynamicAABBTreeRaycastCallback& ca
|
||||||
while (stack.size() > 0) {
|
while (stack.size() > 0) {
|
||||||
|
|
||||||
// Get the next node in the stack
|
// Get the next node in the stack
|
||||||
int nodeID = stack.pop();
|
int32 nodeID = stack.pop();
|
||||||
|
|
||||||
// If it is a null node, skip it
|
// If it is a null node, skip it
|
||||||
if (nodeID == TreeNode::NULL_TREE_NODE) continue;
|
if (nodeID == TreeNode::NULL_TREE_NODE) continue;
|
||||||
|
@ -750,8 +750,8 @@ void DynamicAABBTree::check() const {
|
||||||
// Recursively check each node
|
// Recursively check each node
|
||||||
checkNode(mRootNodeID);
|
checkNode(mRootNodeID);
|
||||||
|
|
||||||
int nbFreeNodes = 0;
|
int32 nbFreeNodes = 0;
|
||||||
int freeNodeID = mFreeNodeID;
|
int32 freeNodeID = mFreeNodeID;
|
||||||
|
|
||||||
// Check the free nodes
|
// Check the free nodes
|
||||||
while(freeNodeID != TreeNode::NULL_TREE_NODE) {
|
while(freeNodeID != TreeNode::NULL_TREE_NODE) {
|
||||||
|
@ -764,7 +764,7 @@ void DynamicAABBTree::check() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the node structure is valid (for debugging purpose)
|
// Check if the node structure is valid (for debugging purpose)
|
||||||
void DynamicAABBTree::checkNode(int nodeID) const {
|
void DynamicAABBTree::checkNode(int32 nodeID) const {
|
||||||
|
|
||||||
if (nodeID == TreeNode::NULL_TREE_NODE) return;
|
if (nodeID == TreeNode::NULL_TREE_NODE) return;
|
||||||
|
|
||||||
|
@ -776,8 +776,8 @@ void DynamicAABBTree::checkNode(int nodeID) const {
|
||||||
// Get the children nodes
|
// Get the children nodes
|
||||||
TreeNode* pNode = mNodes + nodeID;
|
TreeNode* pNode = mNodes + nodeID;
|
||||||
assert(!pNode->isLeaf());
|
assert(!pNode->isLeaf());
|
||||||
int leftChild = pNode->children[0];
|
int32 leftChild = pNode->children[0];
|
||||||
int rightChild = pNode->children[1];
|
int32 rightChild = pNode->children[1];
|
||||||
|
|
||||||
assert(pNode->height >= 0);
|
assert(pNode->height >= 0);
|
||||||
assert(pNode->aabb.getVolume() > 0);
|
assert(pNode->aabb.getVolume() > 0);
|
||||||
|
@ -822,7 +822,7 @@ int DynamicAABBTree::computeHeight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the height of a given node in the tree
|
// Compute the height of a given node in the tree
|
||||||
int DynamicAABBTree::computeHeight(int nodeID) {
|
int DynamicAABBTree::computeHeight(int32 nodeID) {
|
||||||
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
||||||
TreeNode* node = mNodes + nodeID;
|
TreeNode* node = mNodes + nodeID;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct TreeNode {
|
||||||
// -------------------- Constants -------------------- //
|
// -------------------- Constants -------------------- //
|
||||||
|
|
||||||
/// Null tree node constant
|
/// Null tree node constant
|
||||||
const static int NULL_TREE_NODE;
|
const static int32 NULL_TREE_NODE;
|
||||||
|
|
||||||
// -------------------- Attributes -------------------- //
|
// -------------------- Attributes -------------------- //
|
||||||
|
|
||||||
|
@ -148,16 +148,16 @@ class DynamicAABBTree {
|
||||||
TreeNode* mNodes;
|
TreeNode* mNodes;
|
||||||
|
|
||||||
/// ID of the root node of the tree
|
/// ID of the root node of the tree
|
||||||
int mRootNodeID;
|
int32 mRootNodeID;
|
||||||
|
|
||||||
/// ID of the first node of the list of free (allocated) nodes in the tree that we can use
|
/// ID of the first node of the list of free (allocated) nodes in the tree that we can use
|
||||||
int mFreeNodeID;
|
int32 mFreeNodeID;
|
||||||
|
|
||||||
/// Number of allocated nodes in the tree
|
/// Number of allocated nodes in the tree
|
||||||
int mNbAllocatedNodes;
|
int32 mNbAllocatedNodes;
|
||||||
|
|
||||||
/// Number of nodes in the tree
|
/// Number of nodes in the tree
|
||||||
int mNbNodes;
|
int32 mNbNodes;
|
||||||
|
|
||||||
/// Extra AABB Gap used to allow the collision shape to move a little bit
|
/// Extra AABB Gap used to allow the collision shape to move a little bit
|
||||||
/// without triggering a large modification of the tree which can be costly
|
/// without triggering a large modification of the tree which can be costly
|
||||||
|
@ -173,25 +173,25 @@ class DynamicAABBTree {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Allocate and return a node to use in the tree
|
/// Allocate and return a node to use in the tree
|
||||||
int allocateNode();
|
int32 allocateNode();
|
||||||
|
|
||||||
/// Release a node
|
/// Release a node
|
||||||
void releaseNode(int nodeID);
|
void releaseNode(int32 nodeID);
|
||||||
|
|
||||||
/// Insert a leaf node in the tree
|
/// Insert a leaf node in the tree
|
||||||
void insertLeafNode(int nodeID);
|
void insertLeafNode(int32 nodeID);
|
||||||
|
|
||||||
/// Remove a leaf node from the tree
|
/// Remove a leaf node from the tree
|
||||||
void removeLeafNode(int nodeID);
|
void removeLeafNode(int32 nodeID);
|
||||||
|
|
||||||
/// Balance the sub-tree of a given node using left or right rotations.
|
/// Balance the sub-tree of a given node using left or right rotations.
|
||||||
int balanceSubTreeAtNode(int nodeID);
|
int32 balanceSubTreeAtNode(int32 nodeID);
|
||||||
|
|
||||||
/// Compute the height of a given node in the tree
|
/// Compute the height of a given node in the tree
|
||||||
int computeHeight(int nodeID);
|
int computeHeight(int32 nodeID);
|
||||||
|
|
||||||
/// Internally add an object into the tree
|
/// Internally add an object into the tree
|
||||||
int addObjectInternal(const AABB& aabb);
|
int32 addObjectInternal(const AABB& aabb);
|
||||||
|
|
||||||
/// Initialize the tree
|
/// Initialize the tree
|
||||||
void init();
|
void init();
|
||||||
|
@ -202,7 +202,7 @@ class DynamicAABBTree {
|
||||||
void check() const;
|
void check() const;
|
||||||
|
|
||||||
/// Check if the node structure is valid (for debugging purpose)
|
/// Check if the node structure is valid (for debugging purpose)
|
||||||
void checkNode(int nodeID) const;
|
void checkNode(int32 nodeID) const;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -217,29 +217,29 @@ class DynamicAABBTree {
|
||||||
~DynamicAABBTree();
|
~DynamicAABBTree();
|
||||||
|
|
||||||
/// Add an object into the tree (where node data are two integers)
|
/// Add an object into the tree (where node data are two integers)
|
||||||
int addObject(const AABB& aabb, int32 data1, int32 data2);
|
int32 addObject(const AABB& aabb, int32 data1, int32 data2);
|
||||||
|
|
||||||
/// Add an object into the tree (where node data is a pointer)
|
/// Add an object into the tree (where node data is a pointer)
|
||||||
int addObject(const AABB& aabb, void* data);
|
int32 addObject(const AABB& aabb, void* data);
|
||||||
|
|
||||||
/// Remove an object from the tree
|
/// Remove an object from the tree
|
||||||
void removeObject(int nodeID);
|
void removeObject(int32 nodeID);
|
||||||
|
|
||||||
/// Update the dynamic tree after an object has moved.
|
/// Update the dynamic tree after an object has moved.
|
||||||
bool updateObject(int nodeID, const AABB& newAABB, const Vector3& displacement);
|
bool updateObject(int32 nodeID, const AABB& newAABB, const Vector3& displacement);
|
||||||
|
|
||||||
/// Return the fat AABB corresponding to a given node ID
|
/// Return the fat AABB corresponding to a given node ID
|
||||||
const AABB& getFatAABB(int nodeID) const;
|
const AABB& getFatAABB(int32 nodeID) const;
|
||||||
|
|
||||||
/// Return the pointer to the data array of a given leaf node of the tree
|
/// Return the pointer to the data array of a given leaf node of the tree
|
||||||
int32* getNodeDataInt(int nodeID) const;
|
int32* getNodeDataInt(int32 nodeID) const;
|
||||||
|
|
||||||
/// Return the data pointer of a given leaf node of the tree
|
/// Return the data pointer of a given leaf node of the tree
|
||||||
void* getNodeDataPointer(int nodeID) const;
|
void* getNodeDataPointer(int32 nodeID) const;
|
||||||
|
|
||||||
/// Report all shapes overlapping with all the shapes in the map in parameter
|
/// Report all shapes overlapping with all the shapes in the map in parameter
|
||||||
void reportAllShapesOverlappingWithShapes(const List<int>& nodesToTest, size_t startIndex,
|
void reportAllShapesOverlappingWithShapes(const List<int32>& nodesToTest, size_t startIndex,
|
||||||
size_t endIndex, List<Pair<int, int>>& outOverlappingNodes) const;
|
size_t endIndex, List<Pair<int32, int32>>& outOverlappingNodes) const;
|
||||||
|
|
||||||
/// Report all shapes overlapping with the AABB given in parameter.
|
/// Report all shapes overlapping with the AABB given in parameter.
|
||||||
void reportAllShapesOverlappingWithAABB(const AABB& aabb, List<int>& overlappingNodes) const;
|
void reportAllShapesOverlappingWithAABB(const AABB& aabb, List<int>& overlappingNodes) const;
|
||||||
|
@ -271,20 +271,20 @@ inline bool TreeNode::isLeaf() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the fat AABB corresponding to a given node ID
|
// Return the fat AABB corresponding to a given node ID
|
||||||
inline const AABB& DynamicAABBTree::getFatAABB(int nodeID) const {
|
inline const AABB& DynamicAABBTree::getFatAABB(int32 nodeID) const {
|
||||||
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
||||||
return mNodes[nodeID].aabb;
|
return mNodes[nodeID].aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the pointer to the data array of a given leaf node of the tree
|
// Return the pointer to the data array of a given leaf node of the tree
|
||||||
inline int32* DynamicAABBTree::getNodeDataInt(int nodeID) const {
|
inline int32* DynamicAABBTree::getNodeDataInt(int32 nodeID) const {
|
||||||
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
||||||
assert(mNodes[nodeID].isLeaf());
|
assert(mNodes[nodeID].isLeaf());
|
||||||
return mNodes[nodeID].dataInt;
|
return mNodes[nodeID].dataInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the pointer to the data pointer of a given leaf node of the tree
|
// Return the pointer to the data pointer of a given leaf node of the tree
|
||||||
inline void* DynamicAABBTree::getNodeDataPointer(int nodeID) const {
|
inline void* DynamicAABBTree::getNodeDataPointer(int32 nodeID) const {
|
||||||
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
assert(nodeID >= 0 && nodeID < mNbAllocatedNodes);
|
||||||
assert(mNodes[nodeID].isLeaf());
|
assert(mNodes[nodeID].isLeaf());
|
||||||
return mNodes[nodeID].dataPointer;
|
return mNodes[nodeID].dataPointer;
|
||||||
|
@ -297,9 +297,9 @@ inline AABB DynamicAABBTree::getRootAABB() const {
|
||||||
|
|
||||||
// Add an object into the tree. This method creates a new leaf node in the tree and
|
// Add an object into the tree. This method creates a new leaf node in the tree and
|
||||||
// returns the ID of the corresponding node.
|
// returns the ID of the corresponding node.
|
||||||
inline int DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2) {
|
inline int32 DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2) {
|
||||||
|
|
||||||
int nodeId = addObjectInternal(aabb);
|
int32 nodeId = addObjectInternal(aabb);
|
||||||
|
|
||||||
mNodes[nodeId].dataInt[0] = data1;
|
mNodes[nodeId].dataInt[0] = data1;
|
||||||
mNodes[nodeId].dataInt[1] = data2;
|
mNodes[nodeId].dataInt[1] = data2;
|
||||||
|
@ -309,9 +309,9 @@ inline int DynamicAABBTree::addObject(const AABB& aabb, int32 data1, int32 data2
|
||||||
|
|
||||||
// Add an object into the tree. This method creates a new leaf node in the tree and
|
// Add an object into the tree. This method creates a new leaf node in the tree and
|
||||||
// returns the ID of the corresponding node.
|
// returns the ID of the corresponding node.
|
||||||
inline int DynamicAABBTree::addObject(const AABB& aabb, void* data) {
|
inline int32 DynamicAABBTree::addObject(const AABB& aabb, void* data) {
|
||||||
|
|
||||||
int nodeId = addObjectInternal(aabb);
|
int32 nodeId = addObjectInternal(aabb);
|
||||||
|
|
||||||
mNodes[nodeId].dataPointer = data;
|
mNodes[nodeId].dataPointer = data;
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
||||||
Entity* newProxyShapesEntities = static_cast<Entity*>(newBuffer);
|
Entity* newProxyShapesEntities = static_cast<Entity*>(newBuffer);
|
||||||
Entity* newBodiesEntities = reinterpret_cast<Entity*>(newProxyShapesEntities + nbComponentsToAllocate);
|
Entity* newBodiesEntities = reinterpret_cast<Entity*>(newProxyShapesEntities + nbComponentsToAllocate);
|
||||||
ProxyShape** newProxyShapes = reinterpret_cast<ProxyShape**>(newBodiesEntities + nbComponentsToAllocate);
|
ProxyShape** newProxyShapes = reinterpret_cast<ProxyShape**>(newBodiesEntities + nbComponentsToAllocate);
|
||||||
int* newBroadPhaseIds = reinterpret_cast<int*>(newProxyShapes + nbComponentsToAllocate);
|
int32* newBroadPhaseIds = reinterpret_cast<int32*>(newProxyShapes + nbComponentsToAllocate);
|
||||||
Transform* newLocalToBodyTransforms = reinterpret_cast<Transform*>(newBroadPhaseIds + nbComponentsToAllocate);
|
Transform* newLocalToBodyTransforms = reinterpret_cast<Transform*>(newBroadPhaseIds + nbComponentsToAllocate);
|
||||||
CollisionShape** newCollisionShapes = reinterpret_cast<CollisionShape**>(newLocalToBodyTransforms + nbComponentsToAllocate);
|
CollisionShape** newCollisionShapes = reinterpret_cast<CollisionShape**>(newLocalToBodyTransforms + nbComponentsToAllocate);
|
||||||
decimal* newMasses = reinterpret_cast<decimal*>(newCollisionShapes + nbComponentsToAllocate);
|
decimal* newMasses = reinterpret_cast<decimal*>(newCollisionShapes + nbComponentsToAllocate);
|
||||||
|
@ -73,7 +73,7 @@ void ProxyShapeComponents::allocate(uint32 nbComponentsToAllocate) {
|
||||||
memcpy(newProxyShapesEntities, mProxyShapesEntities, mNbComponents * sizeof(Entity));
|
memcpy(newProxyShapesEntities, mProxyShapesEntities, mNbComponents * sizeof(Entity));
|
||||||
memcpy(newBodiesEntities, mBodiesEntities, mNbComponents * sizeof(Entity));
|
memcpy(newBodiesEntities, mBodiesEntities, mNbComponents * sizeof(Entity));
|
||||||
memcpy(newProxyShapes, mProxyShapes, mNbComponents * sizeof(ProxyShape*));
|
memcpy(newProxyShapes, mProxyShapes, mNbComponents * sizeof(ProxyShape*));
|
||||||
memcpy(newBroadPhaseIds, mBroadPhaseIds, mNbComponents * sizeof(int));
|
memcpy(newBroadPhaseIds, mBroadPhaseIds, mNbComponents * sizeof(int32));
|
||||||
memcpy(newLocalToBodyTransforms, mLocalToBodyTransforms, mNbComponents * sizeof(Transform));
|
memcpy(newLocalToBodyTransforms, mLocalToBodyTransforms, mNbComponents * sizeof(Transform));
|
||||||
memcpy(newCollisionShapes, mCollisionShapes, mNbComponents * sizeof(CollisionShape*));
|
memcpy(newCollisionShapes, mCollisionShapes, mNbComponents * sizeof(CollisionShape*));
|
||||||
memcpy(newMasses, mMasses, mNbComponents * sizeof(decimal));
|
memcpy(newMasses, mMasses, mNbComponents * sizeof(decimal));
|
||||||
|
@ -109,7 +109,7 @@ void ProxyShapeComponents::addComponent(Entity proxyShapeEntity, bool isSleeping
|
||||||
new (mProxyShapesEntities + index) Entity(proxyShapeEntity);
|
new (mProxyShapesEntities + index) Entity(proxyShapeEntity);
|
||||||
new (mBodiesEntities + index) Entity(component.bodyEntity);
|
new (mBodiesEntities + index) Entity(component.bodyEntity);
|
||||||
mProxyShapes[index] = component.proxyShape;
|
mProxyShapes[index] = component.proxyShape;
|
||||||
new (mBroadPhaseIds + index) int(component.broadPhaseId);
|
new (mBroadPhaseIds + index) int32(-1);
|
||||||
new (mLocalToBodyTransforms + index) Transform(component.localToBodyTransform);
|
new (mLocalToBodyTransforms + index) Transform(component.localToBodyTransform);
|
||||||
mCollisionShapes[index] = component.collisionShape;
|
mCollisionShapes[index] = component.collisionShape;
|
||||||
new (mMasses + index) decimal(component.mass);
|
new (mMasses + index) decimal(component.mass);
|
||||||
|
@ -134,7 +134,7 @@ void ProxyShapeComponents::moveComponentToIndex(uint32 srcIndex, uint32 destInde
|
||||||
new (mProxyShapesEntities + destIndex) Entity(mProxyShapesEntities[srcIndex]);
|
new (mProxyShapesEntities + destIndex) Entity(mProxyShapesEntities[srcIndex]);
|
||||||
new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
|
new (mBodiesEntities + destIndex) Entity(mBodiesEntities[srcIndex]);
|
||||||
mProxyShapes[destIndex] = mProxyShapes[srcIndex];
|
mProxyShapes[destIndex] = mProxyShapes[srcIndex];
|
||||||
new (mBroadPhaseIds + destIndex) int(mBroadPhaseIds[srcIndex]);
|
new (mBroadPhaseIds + destIndex) int32(mBroadPhaseIds[srcIndex]);
|
||||||
new (mLocalToBodyTransforms + destIndex) Transform(mLocalToBodyTransforms[srcIndex]);
|
new (mLocalToBodyTransforms + destIndex) Transform(mLocalToBodyTransforms[srcIndex]);
|
||||||
mCollisionShapes[destIndex] = mCollisionShapes[srcIndex];
|
mCollisionShapes[destIndex] = mCollisionShapes[srcIndex];
|
||||||
new (mMasses + destIndex) decimal(mMasses[srcIndex]);
|
new (mMasses + destIndex) decimal(mMasses[srcIndex]);
|
||||||
|
@ -159,7 +159,7 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) {
|
||||||
Entity proxyShapeEntity1(mProxyShapesEntities[index1]);
|
Entity proxyShapeEntity1(mProxyShapesEntities[index1]);
|
||||||
Entity bodyEntity1(mBodiesEntities[index1]);
|
Entity bodyEntity1(mBodiesEntities[index1]);
|
||||||
ProxyShape* proxyShape1 = mProxyShapes[index1];
|
ProxyShape* proxyShape1 = mProxyShapes[index1];
|
||||||
int broadPhaseId1 = mBroadPhaseIds[index1];
|
int32 broadPhaseId1 = mBroadPhaseIds[index1];
|
||||||
Transform localToBodyTransform1 = mLocalToBodyTransforms[index1];
|
Transform localToBodyTransform1 = mLocalToBodyTransforms[index1];
|
||||||
CollisionShape* collisionShape1 = mCollisionShapes[index1];
|
CollisionShape* collisionShape1 = mCollisionShapes[index1];
|
||||||
decimal mass1 = mMasses[index1];
|
decimal mass1 = mMasses[index1];
|
||||||
|
@ -175,7 +175,7 @@ void ProxyShapeComponents::swapComponents(uint32 index1, uint32 index2) {
|
||||||
new (mProxyShapesEntities + index2) Entity(proxyShapeEntity1);
|
new (mProxyShapesEntities + index2) Entity(proxyShapeEntity1);
|
||||||
new (mBodiesEntities + index2) Entity(bodyEntity1);
|
new (mBodiesEntities + index2) Entity(bodyEntity1);
|
||||||
mProxyShapes[index2] = proxyShape1;
|
mProxyShapes[index2] = proxyShape1;
|
||||||
new (mBroadPhaseIds + index2) int(broadPhaseId1);
|
new (mBroadPhaseIds + index2) int32(broadPhaseId1);
|
||||||
new (mLocalToBodyTransforms + index2) Transform(localToBodyTransform1);
|
new (mLocalToBodyTransforms + index2) Transform(localToBodyTransform1);
|
||||||
mCollisionShapes[index2] = collisionShape1;
|
mCollisionShapes[index2] = collisionShape1;
|
||||||
new (mMasses + index2) decimal(mass1);
|
new (mMasses + index2) decimal(mass1);
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ProxyShapeComponents : public Components {
|
||||||
|
|
||||||
/// Ids of the proxy-shapes for the broad-phase algorithm
|
/// Ids of the proxy-shapes for the broad-phase algorithm
|
||||||
// TODO : Try to change type to uint32
|
// TODO : Try to change type to uint32
|
||||||
int* mBroadPhaseIds;
|
int32* mBroadPhaseIds;
|
||||||
|
|
||||||
/// Transform from local-space of the proxy-shape to the body-space of its body
|
/// Transform from local-space of the proxy-shape to the body-space of its body
|
||||||
Transform* mLocalToBodyTransforms;
|
Transform* mLocalToBodyTransforms;
|
||||||
|
@ -111,7 +111,6 @@ class ProxyShapeComponents : public Components {
|
||||||
|
|
||||||
Entity bodyEntity;
|
Entity bodyEntity;
|
||||||
ProxyShape* proxyShape;
|
ProxyShape* proxyShape;
|
||||||
int broadPhaseId;
|
|
||||||
AABB localBounds;
|
AABB localBounds;
|
||||||
Transform localToBodyTransform;
|
Transform localToBodyTransform;
|
||||||
CollisionShape* collisionShape;
|
CollisionShape* collisionShape;
|
||||||
|
@ -120,10 +119,10 @@ class ProxyShapeComponents : public Components {
|
||||||
unsigned short collideWithMaskBits;
|
unsigned short collideWithMaskBits;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ProxyShapeComponent(Entity bodyEntity, ProxyShape* proxyShape, int broadPhaseId, AABB localBounds, Transform localToBodyTransform,
|
ProxyShapeComponent(Entity bodyEntity, ProxyShape* proxyShape, AABB localBounds, Transform localToBodyTransform,
|
||||||
CollisionShape* collisionShape, decimal mass, unsigned short collisionCategoryBits,
|
CollisionShape* collisionShape, decimal mass, unsigned short collisionCategoryBits,
|
||||||
unsigned short collideWithMaskBits)
|
unsigned short collideWithMaskBits)
|
||||||
:bodyEntity(bodyEntity), proxyShape(proxyShape), broadPhaseId(broadPhaseId), localBounds(localBounds), localToBodyTransform(localToBodyTransform),
|
:bodyEntity(bodyEntity), proxyShape(proxyShape), localBounds(localBounds), localToBodyTransform(localToBodyTransform),
|
||||||
collisionShape(collisionShape), mass(mass), collisionCategoryBits(collisionCategoryBits), collideWithMaskBits(collideWithMaskBits) {
|
collisionShape(collisionShape), mass(mass), collisionCategoryBits(collisionCategoryBits), collideWithMaskBits(collideWithMaskBits) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -159,10 +158,10 @@ class ProxyShapeComponents : public Components {
|
||||||
CollisionShape* getCollisionShape(Entity proxyShapeEntity) const;
|
CollisionShape* getCollisionShape(Entity proxyShapeEntity) const;
|
||||||
|
|
||||||
/// Return the broad-phase id of a given proxy shape
|
/// Return the broad-phase id of a given proxy shape
|
||||||
int getBroadPhaseId(Entity proxyShapeEntity) const;
|
int32 getBroadPhaseId(Entity proxyShapeEntity) const;
|
||||||
|
|
||||||
/// Set the broad-phase id of a given proxy shape
|
/// Set the broad-phase id of a given proxy shape
|
||||||
void setBroadPhaseId(Entity proxyShapeEntity, int broadPhaseId);
|
void setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId);
|
||||||
|
|
||||||
/// Return the collision category bits of a given proxy-shape
|
/// Return the collision category bits of a given proxy-shape
|
||||||
unsigned short getCollisionCategoryBits(Entity proxyShapeEntity) const;
|
unsigned short getCollisionCategoryBits(Entity proxyShapeEntity) const;
|
||||||
|
@ -230,7 +229,7 @@ inline CollisionShape* ProxyShapeComponents::getCollisionShape(Entity proxyShape
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the broad-phase id of a given proxy shape
|
// Return the broad-phase id of a given proxy shape
|
||||||
inline int ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const {
|
inline int32 ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const {
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@ inline int ProxyShapeComponents::getBroadPhaseId(Entity proxyShapeEntity) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the broad-phase id of a given proxy shape
|
// Set the broad-phase id of a given proxy shape
|
||||||
inline void ProxyShapeComponents::setBroadPhaseId(Entity proxyShapeEntity, int broadPhaseId) {
|
inline void ProxyShapeComponents::setBroadPhaseId(Entity proxyShapeEntity, int32 broadPhaseId) {
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
assert(mMapEntityToComponentIndex.containsKey(proxyShapeEntity));
|
||||||
|
|
||||||
|
|
|
@ -214,8 +214,6 @@ void CollisionWorld::setBodyDisabled(Entity bodyEntity, bool isDisabled) {
|
||||||
|
|
||||||
if (isDisabled == mCollisionBodyComponents.getIsEntityDisabled(bodyEntity)) return;
|
if (isDisabled == mCollisionBodyComponents.getIsEntityDisabled(bodyEntity)) return;
|
||||||
|
|
||||||
// TODO : Make sure we notify all the components here ...
|
|
||||||
|
|
||||||
// Notify all the components
|
// Notify all the components
|
||||||
mCollisionBodyComponents.setIsEntityDisabled(bodyEntity, isDisabled);
|
mCollisionBodyComponents.setIsEntityDisabled(bodyEntity, isDisabled);
|
||||||
mTransformComponents.setIsEntityDisabled(bodyEntity, isDisabled);
|
mTransformComponents.setIsEntityDisabled(bodyEntity, isDisabled);
|
||||||
|
@ -238,8 +236,8 @@ void CollisionWorld::setBodyDisabled(Entity bodyEntity, bool isDisabled) {
|
||||||
const List<Entity>& joints = mRigidBodyComponents.getJoints(bodyEntity);
|
const List<Entity>& joints = mRigidBodyComponents.getJoints(bodyEntity);
|
||||||
for(uint32 i=0; i < joints.size(); i++) {
|
for(uint32 i=0; i < joints.size(); i++) {
|
||||||
|
|
||||||
Entity body1Entity = mJointsComponents.getBody1Entity(joints[i]);
|
const Entity body1Entity = mJointsComponents.getBody1Entity(joints[i]);
|
||||||
Entity body2Entity = mJointsComponents.getBody2Entity(joints[i]);
|
const Entity body2Entity = mJointsComponents.getBody2Entity(joints[i]);
|
||||||
|
|
||||||
// If both bodies of the joint are disabled
|
// If both bodies of the joint are disabled
|
||||||
if (mRigidBodyComponents.getIsEntityDisabled(body1Entity) &&
|
if (mRigidBodyComponents.getIsEntityDisabled(body1Entity) &&
|
||||||
|
@ -262,7 +260,6 @@ void CollisionWorld::setJointDisabled(Entity jointEntity, bool isDisabled) {
|
||||||
|
|
||||||
if (isDisabled == mJointsComponents.getIsEntityDisabled(jointEntity)) return;
|
if (isDisabled == mJointsComponents.getIsEntityDisabled(jointEntity)) return;
|
||||||
|
|
||||||
// TODO : Make sure we notify all the components here ...
|
|
||||||
mJointsComponents.setIsEntityDisabled(jointEntity, isDisabled);
|
mJointsComponents.setIsEntityDisabled(jointEntity, isDisabled);
|
||||||
if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) {
|
if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) {
|
||||||
mBallAndSocketJointsComponents.setIsEntityDisabled(jointEntity, isDisabled);
|
mBallAndSocketJointsComponents.setIsEntityDisabled(jointEntity, isDisabled);
|
||||||
|
|
|
@ -115,9 +115,6 @@ void DynamicsWorld::update(decimal timeStep) {
|
||||||
|
|
||||||
RP3D_PROFILE("DynamicsWorld::update()", mProfiler);
|
RP3D_PROFILE("DynamicsWorld::update()", mProfiler);
|
||||||
|
|
||||||
// Notify the event listener about the beginning of an internal tick
|
|
||||||
if (mEventListener != nullptr) mEventListener->beginInternalTick();
|
|
||||||
|
|
||||||
// Compute the collision detection
|
// Compute the collision detection
|
||||||
mCollisionDetection.computeCollisionDetection();
|
mCollisionDetection.computeCollisionDetection();
|
||||||
|
|
||||||
|
@ -153,9 +150,6 @@ void DynamicsWorld::update(decimal timeStep) {
|
||||||
|
|
||||||
if (mIsSleepingEnabled) updateSleepingBodies(timeStep);
|
if (mIsSleepingEnabled) updateSleepingBodies(timeStep);
|
||||||
|
|
||||||
// Notify the event listener about the end of an internal tick
|
|
||||||
if (mEventListener != nullptr) mEventListener->endInternalTick();
|
|
||||||
|
|
||||||
// Reset the external force and torque applied to the bodies
|
// Reset the external force and torque applied to the bodies
|
||||||
mDynamicsSystem.resetBodiesForceAndTorque();
|
mDynamicsSystem.resetBodiesForceAndTorque();
|
||||||
|
|
||||||
|
@ -463,10 +457,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) {
|
||||||
Entity jointEntity = joint->getEntity();
|
Entity jointEntity = joint->getEntity();
|
||||||
|
|
||||||
// Destroy the corresponding entity and its components
|
// Destroy the corresponding entity and its components
|
||||||
// TODO : Make sure we remove all its components here
|
|
||||||
mJointsComponents.removeComponent(jointEntity);
|
mJointsComponents.removeComponent(jointEntity);
|
||||||
mEntityManager.destroyEntity(jointEntity);
|
|
||||||
|
|
||||||
if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) {
|
if (mBallAndSocketJointsComponents.hasComponent(jointEntity)) {
|
||||||
mBallAndSocketJointsComponents.removeComponent(jointEntity);
|
mBallAndSocketJointsComponents.removeComponent(jointEntity);
|
||||||
}
|
}
|
||||||
|
@ -479,6 +470,7 @@ void DynamicsWorld::destroyJoint(Joint* joint) {
|
||||||
if (mSliderJointsComponents.hasComponent(jointEntity)) {
|
if (mSliderJointsComponents.hasComponent(jointEntity)) {
|
||||||
mSliderJointsComponents.removeComponent(jointEntity);
|
mSliderJointsComponents.removeComponent(jointEntity);
|
||||||
}
|
}
|
||||||
|
mEntityManager.destroyEntity(jointEntity);
|
||||||
|
|
||||||
// Call the destructor of the joint
|
// Call the destructor of the joint
|
||||||
joint->~Joint();
|
joint->~Joint();
|
||||||
|
|
|
@ -54,20 +54,6 @@ class EventListener : public CollisionCallback {
|
||||||
* @param collisionInfo Information about the contacts
|
* @param collisionInfo Information about the contacts
|
||||||
*/
|
*/
|
||||||
virtual void onContact(const CollisionCallback::CallbackData& callbackData) override {}
|
virtual void onContact(const CollisionCallback::CallbackData& callbackData) override {}
|
||||||
|
|
||||||
// TODO : Remove this method (no internal steps anymore)
|
|
||||||
/// Called at the beginning of an internal tick of the simulation step.
|
|
||||||
/// Each time the DynamicsWorld::update() method is called, the physics
|
|
||||||
/// engine will do several internal simulation steps. This method is
|
|
||||||
/// called at the beginning of each internal simulation step.
|
|
||||||
virtual void beginInternalTick() {}
|
|
||||||
|
|
||||||
// TODO : Remove this method (no internal steps anymore)
|
|
||||||
/// Called at the end of an internal tick of the simulation step.
|
|
||||||
/// Each time the DynamicsWorld::update() metho is called, the physics
|
|
||||||
/// engine will do several internal simulation steps. This method is
|
|
||||||
/// called at the end of each internal simulation step.
|
|
||||||
virtual void endInternalTick() {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ void BroadPhaseSystem::updateProxyShapes(decimal timeStep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the broad-phase that a collision shape has moved and need to be updated
|
// Notify the broad-phase that a collision shape has moved and need to be updated
|
||||||
void BroadPhaseSystem::updateProxyShapeInternal(int broadPhaseId, const AABB& aabb, const Vector3& displacement) {
|
void BroadPhaseSystem::updateProxyShapeInternal(int32 broadPhaseId, const AABB& aabb, const Vector3& displacement) {
|
||||||
|
|
||||||
assert(broadPhaseId >= 0);
|
assert(broadPhaseId >= 0);
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 nbI
|
||||||
// For each proxy-shape component to update
|
// For each proxy-shape component to update
|
||||||
for (uint32 i = startIndex; i < startIndex + nbItems; i++) {
|
for (uint32 i = startIndex; i < startIndex + nbItems; i++) {
|
||||||
|
|
||||||
const int broadPhaseId = mProxyShapesComponents.mBroadPhaseIds[i];
|
const int32 broadPhaseId = mProxyShapesComponents.mBroadPhaseIds[i];
|
||||||
if (broadPhaseId != -1) {
|
if (broadPhaseId != -1) {
|
||||||
|
|
||||||
const Entity& bodyEntity = mProxyShapesComponents.mBodiesEntities[i];
|
const Entity& bodyEntity = mProxyShapesComponents.mBodiesEntities[i];
|
||||||
|
|
|
@ -140,7 +140,7 @@ class BroadPhaseSystem {
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Notify the Dynamic AABB tree that a proxy-shape needs to be updated
|
/// Notify the Dynamic AABB tree that a proxy-shape needs to be updated
|
||||||
void updateProxyShapeInternal(int broadPhaseId, const AABB& aabb, const Vector3& displacement);
|
void updateProxyShapeInternal(int32 broadPhaseId, const AABB& aabb, const Vector3& displacement);
|
||||||
|
|
||||||
/// Update the broad-phase state of some proxy-shapes components
|
/// Update the broad-phase state of some proxy-shapes components
|
||||||
void updateProxyShapesComponents(uint32 startIndex, uint32 nbItems, decimal timeStep);
|
void updateProxyShapesComponents(uint32 startIndex, uint32 nbItems, decimal timeStep);
|
||||||
|
|
|
@ -45,9 +45,7 @@ ConstraintSolverSystem::ConstraintSolverSystem(DynamicsWorld& world, Islands& is
|
||||||
mSolveBallAndSocketJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, ballAndSocketJointComponents),
|
mSolveBallAndSocketJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, ballAndSocketJointComponents),
|
||||||
mSolveFixedJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, fixedJointComponents),
|
mSolveFixedJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, fixedJointComponents),
|
||||||
mSolveHingeJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, hingeJointComponents),
|
mSolveHingeJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, hingeJointComponents),
|
||||||
mSolveSliderJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, sliderJointComponents),
|
mSolveSliderJointSystem(world, rigidBodyComponents, transformComponents, jointComponents, sliderJointComponents) {
|
||||||
mJointComponents(jointComponents), mBallAndSocketJointComponents(ballAndSocketJointComponents),
|
|
||||||
mFixedJointComponents(fixedJointComponents), mHingeJointComponents(hingeJointComponents) {
|
|
||||||
|
|
||||||
#ifdef IS_PROFILING_ACTIVE
|
#ifdef IS_PROFILING_ACTIVE
|
||||||
|
|
||||||
|
|
|
@ -173,18 +173,6 @@ class ConstraintSolverSystem {
|
||||||
/// Solver for the SliderJoint constraints
|
/// Solver for the SliderJoint constraints
|
||||||
SolveSliderJointSystem mSolveSliderJointSystem;
|
SolveSliderJointSystem mSolveSliderJointSystem;
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
JointComponents& mJointComponents;
|
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
BallAndSocketJointComponents& mBallAndSocketJointComponents;
|
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
FixedJointComponents& mFixedJointComponents;
|
|
||||||
|
|
||||||
// TODO : Delete this
|
|
||||||
HingeJointComponents& mHingeJointComponents;
|
|
||||||
|
|
||||||
#ifdef IS_PROFILING_ACTIVE
|
#ifdef IS_PROFILING_ACTIVE
|
||||||
|
|
||||||
/// Pointer to the profiler
|
/// Pointer to the profiler
|
||||||
|
|
|
@ -68,7 +68,6 @@ void ContactSolverSystem::init(List<ContactManifold>* contactManifolds, List<Con
|
||||||
|
|
||||||
mTimeStep = timeStep;
|
mTimeStep = timeStep;
|
||||||
|
|
||||||
// TODO : Try not to count manifolds and contact points here
|
|
||||||
uint nbContactManifolds = mAllContactManifolds->size();
|
uint nbContactManifolds = mAllContactManifolds->size();
|
||||||
uint nbContactPoints = mAllContactPoints->size();
|
uint nbContactPoints = mAllContactPoints->size();
|
||||||
|
|
||||||
|
@ -80,7 +79,6 @@ void ContactSolverSystem::init(List<ContactManifold>* contactManifolds, List<Con
|
||||||
|
|
||||||
if (nbContactManifolds == 0 || nbContactPoints == 0) return;
|
if (nbContactManifolds == 0 || nbContactPoints == 0) return;
|
||||||
|
|
||||||
// TODO : Count exactly the number of constraints to allocate here
|
|
||||||
mContactPoints = static_cast<ContactPointSolver*>(mMemoryManager.allocate(MemoryManager::AllocationType::Frame,
|
mContactPoints = static_cast<ContactPointSolver*>(mMemoryManager.allocate(MemoryManager::AllocationType::Frame,
|
||||||
sizeof(ContactPointSolver) * nbContactPoints));
|
sizeof(ContactPointSolver) * nbContactPoints));
|
||||||
assert(mContactPoints != nullptr);
|
assert(mContactPoints != nullptr);
|
||||||
|
|
|
@ -73,8 +73,6 @@ void DynamicsSystem::updateBodiesState() {
|
||||||
|
|
||||||
RP3D_PROFILE("DynamicsSystem::updateBodiesState()", mProfiler);
|
RP3D_PROFILE("DynamicsSystem::updateBodiesState()", mProfiler);
|
||||||
|
|
||||||
// TODO : Make sure we compute this in a system
|
|
||||||
|
|
||||||
for (uint32 i=0; i < mRigidBodyComponents.getNbEnabledComponents(); i++) {
|
for (uint32 i=0; i < mRigidBodyComponents.getNbEnabledComponents(); i++) {
|
||||||
|
|
||||||
// Update the linear and angular velocity of the body
|
// Update the linear and angular velocity of the body
|
||||||
|
|
Loading…
Reference in New Issue
Block a user