Move attributes from RigidBodyComponents to DynamicsComponents
This commit is contained in:
parent
466455d15a
commit
6f9adc3a32
@ -86,8 +86,8 @@ void RigidBody::setType(BodyType type) {
|
|||||||
if (type == BodyType::STATIC) {
|
if (type == BodyType::STATIC) {
|
||||||
|
|
||||||
// Reset the velocity to zero
|
// Reset the velocity to zero
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, Vector3::zero());
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, Vector3::zero());
|
||||||
mWorld.mDynamicsComponents.setAngularVelocity(mEntity, Vector3::zero());
|
mWorld.mRigidBodyComponents.setAngularVelocity(mEntity, Vector3::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is a static or a kinematic body
|
// If it is a static or a kinematic body
|
||||||
@ -295,11 +295,11 @@ void RigidBody::setCenterOfMassLocal(const Vector3& centerOfMassLocal) {
|
|||||||
mWorld.mDynamicsComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * updatedCenterOfMassLocal);
|
mWorld.mDynamicsComponents.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.mDynamicsComponents.getAngularVelocity(mEntity);
|
Vector3 linearVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
const Vector3& angularVelocity = mWorld.mDynamicsComponents.getAngularVelocity(mEntity);
|
const Vector3& angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
const Vector3& centerOfMassWorld = mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity);
|
const Vector3& centerOfMassWorld = mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity);
|
||||||
linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMass);
|
linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMass);
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, linearVelocity);
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
|
||||||
|
|
||||||
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body,
|
RP3D_LOG(mLogger, Logger::Level::Information, Logger::Category::Body,
|
||||||
"Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMassLocal.to_string());
|
"Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMassLocal.to_string());
|
||||||
@ -536,7 +536,7 @@ void RigidBody::setLinearVelocity(const Vector3& linearVelocity) {
|
|||||||
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
||||||
|
|
||||||
// Update the linear velocity of the current body state
|
// Update the linear velocity of the current body state
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, linearVelocity);
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
|
||||||
|
|
||||||
// If the linear velocity is not zero, awake the body
|
// If the linear velocity is not zero, awake the body
|
||||||
if (linearVelocity.lengthSquare() > decimal(0.0)) {
|
if (linearVelocity.lengthSquare() > decimal(0.0)) {
|
||||||
@ -559,7 +559,7 @@ void RigidBody::setAngularVelocity(const Vector3& angularVelocity) {
|
|||||||
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
if (mWorld.mRigidBodyComponents.getBodyType(mEntity) == BodyType::STATIC) return;
|
||||||
|
|
||||||
// Set the angular velocity
|
// Set the angular velocity
|
||||||
mWorld.mDynamicsComponents.setAngularVelocity(mEntity, angularVelocity);
|
mWorld.mRigidBodyComponents.setAngularVelocity(mEntity, angularVelocity);
|
||||||
|
|
||||||
// If the velocity is not zero, awake the body
|
// If the velocity is not zero, awake the body
|
||||||
if (angularVelocity.lengthSquare() > decimal(0.0)) {
|
if (angularVelocity.lengthSquare() > decimal(0.0)) {
|
||||||
@ -584,11 +584,11 @@ void RigidBody::setTransform(const Transform& transform) {
|
|||||||
mWorld.mDynamicsComponents.setCenterOfMassWorld(mEntity, transform * centerOfMassLocal);
|
mWorld.mDynamicsComponents.setCenterOfMassWorld(mEntity, transform * centerOfMassLocal);
|
||||||
|
|
||||||
// Update the linear velocity of the center of mass
|
// Update the linear velocity of the center of mass
|
||||||
Vector3 linearVelocity = mWorld.mDynamicsComponents.getLinearVelocity(mEntity);
|
Vector3 linearVelocity = mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
|
||||||
const Vector3& angularVelocity = mWorld.mDynamicsComponents.getAngularVelocity(mEntity);
|
const Vector3& angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
const Vector3& centerOfMassWorld = mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity);
|
const Vector3& centerOfMassWorld = mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity);
|
||||||
linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMass);
|
linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMass);
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, linearVelocity);
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
|
||||||
|
|
||||||
CollisionBody::setTransform(transform);
|
CollisionBody::setTransform(transform);
|
||||||
|
|
||||||
@ -695,10 +695,10 @@ void RigidBody::recomputeMassInformation() {
|
|||||||
updateInertiaTensorInverseWorld();
|
updateInertiaTensorInverseWorld();
|
||||||
|
|
||||||
// Update the linear velocity of the center of mass
|
// Update the linear velocity of the center of mass
|
||||||
Vector3 linearVelocity = mWorld.mDynamicsComponents.getLinearVelocity(mEntity);
|
Vector3 linearVelocity = mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
|
||||||
Vector3 angularVelocity = mWorld.mDynamicsComponents.getAngularVelocity(mEntity);
|
Vector3 angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
linearVelocity += angularVelocity.cross(mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity) - oldCenterOfMass);
|
linearVelocity += angularVelocity.cross(mWorld.mDynamicsComponents.getCenterOfMassWorld(mEntity) - oldCenterOfMass);
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, linearVelocity);
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the linear velocity
|
// Return the linear velocity
|
||||||
@ -706,7 +706,7 @@ void RigidBody::recomputeMassInformation() {
|
|||||||
* @return The linear velocity vector of the body
|
* @return The linear velocity vector of the body
|
||||||
*/
|
*/
|
||||||
Vector3 RigidBody::getLinearVelocity() const {
|
Vector3 RigidBody::getLinearVelocity() const {
|
||||||
return mWorld.mDynamicsComponents.getLinearVelocity(mEntity);
|
return mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the angular velocity of the body
|
// Return the angular velocity of the body
|
||||||
@ -714,7 +714,7 @@ Vector3 RigidBody::getLinearVelocity() const {
|
|||||||
* @return The angular velocity vector of the body
|
* @return The angular velocity vector of the body
|
||||||
*/
|
*/
|
||||||
Vector3 RigidBody::getAngularVelocity() const {
|
Vector3 RigidBody::getAngularVelocity() const {
|
||||||
return mWorld.mDynamicsComponents.getAngularVelocity(mEntity);
|
return mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the gravity needs to be applied to this rigid body
|
// Return true if the gravity needs to be applied to this rigid body
|
||||||
@ -777,8 +777,8 @@ void RigidBody::setIsSleeping(bool isSleeping) {
|
|||||||
|
|
||||||
if (isSleeping) {
|
if (isSleeping) {
|
||||||
|
|
||||||
mWorld.mDynamicsComponents.setLinearVelocity(mEntity, Vector3::zero());
|
mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, Vector3::zero());
|
||||||
mWorld.mDynamicsComponents.setAngularVelocity(mEntity, Vector3::zero());
|
mWorld.mRigidBodyComponents.setAngularVelocity(mEntity, Vector3::zero());
|
||||||
mWorld.mDynamicsComponents.setExternalForce(mEntity, Vector3::zero());
|
mWorld.mDynamicsComponents.setExternalForce(mEntity, Vector3::zero());
|
||||||
mWorld.mDynamicsComponents.setExternalTorque(mEntity, Vector3::zero());
|
mWorld.mDynamicsComponents.setExternalTorque(mEntity, Vector3::zero());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,11 +53,11 @@ using namespace std;
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
CollisionDetection::CollisionDetection(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents, TransformComponents& transformComponents,
|
CollisionDetection::CollisionDetection(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents, TransformComponents& transformComponents,
|
||||||
DynamicsComponents& dynamicsComponents, MemoryManager& memoryManager)
|
RigidBodyComponents& rigidBodyComponents, MemoryManager& memoryManager)
|
||||||
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents),
|
: mMemoryManager(memoryManager), mProxyShapesComponents(proxyShapesComponents),
|
||||||
mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
mCollisionDispatch(mMemoryManager.getPoolAllocator()), mWorld(world),
|
||||||
mOverlappingPairs(mMemoryManager.getPoolAllocator()),
|
mOverlappingPairs(mMemoryManager.getPoolAllocator()),
|
||||||
mBroadPhaseSystem(*this, mProxyShapesComponents, transformComponents, dynamicsComponents),
|
mBroadPhaseSystem(*this, mProxyShapesComponents, transformComponents, rigidBodyComponents),
|
||||||
mNoCollisionPairs(mMemoryManager.getPoolAllocator()), mMapBroadPhaseIdToProxyShapeEntity(memoryManager.getPoolAllocator()),
|
mNoCollisionPairs(mMemoryManager.getPoolAllocator()), mMapBroadPhaseIdToProxyShapeEntity(memoryManager.getPoolAllocator()),
|
||||||
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator()), mPotentialContactPoints(mMemoryManager.getSingleFrameAllocator()),
|
mNarrowPhaseInput(mMemoryManager.getSingleFrameAllocator()), mPotentialContactPoints(mMemoryManager.getSingleFrameAllocator()),
|
||||||
// TODO : We should probably use single frame allocator for mPotentialContactPoints, mPotentialContactManifolds, mMapPairIdToOverlappingPairContacts
|
// TODO : We should probably use single frame allocator for mPotentialContactPoints, mPotentialContactManifolds, mMapPairIdToOverlappingPairContacts
|
||||||
|
|||||||
@ -270,7 +270,7 @@ class CollisionDetection {
|
|||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
CollisionDetection(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents,
|
CollisionDetection(CollisionWorld* world, ProxyShapeComponents& proxyShapesComponents,
|
||||||
TransformComponents& transformComponents, DynamicsComponents& dynamicsComponents,
|
TransformComponents& transformComponents, RigidBodyComponents& rigidBodyComponents,
|
||||||
MemoryManager& memoryManager);
|
MemoryManager& memoryManager);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
|
|||||||
@ -32,11 +32,10 @@
|
|||||||
// We want to use the ReactPhysics3D namespace
|
// We want to use the ReactPhysics3D namespace
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
DynamicsComponents::DynamicsComponents(MemoryAllocator& allocator)
|
DynamicsComponents::DynamicsComponents(MemoryAllocator& allocator)
|
||||||
:Components(allocator, sizeof(Entity) + sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) +
|
:Components(allocator, sizeof(Entity) + sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) +
|
||||||
sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) + sizeof(Vector3) + sizeof(decimal) +
|
sizeof(Vector3) + sizeof(Vector3) + sizeof(decimal) +
|
||||||
sizeof(decimal) + sizeof(decimal) + sizeof(decimal) + sizeof(Matrix3x3) + sizeof(Matrix3x3) +
|
sizeof(decimal) + sizeof(decimal) + sizeof(decimal) + sizeof(Matrix3x3) + sizeof(Matrix3x3) +
|
||||||
sizeof(Vector3) + sizeof(Quaternion) + sizeof(Vector3) + sizeof(Vector3) + sizeof(bool) +
|
sizeof(Vector3) + sizeof(Quaternion) + sizeof(Vector3) + sizeof(Vector3) + sizeof(bool) +
|
||||||
sizeof(bool)) {
|
sizeof(bool)) {
|
||||||
@ -59,9 +58,7 @@ void DynamicsComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
|
|
||||||
// New pointers to components data
|
// New pointers to components data
|
||||||
Entity* newBodies = static_cast<Entity*>(newBuffer);
|
Entity* newBodies = static_cast<Entity*>(newBuffer);
|
||||||
Vector3* newLinearVelocities = reinterpret_cast<Vector3*>(newBodies + nbComponentsToAllocate);
|
Vector3* newConstrainedLinearVelocities = reinterpret_cast<Vector3*>(newBodies + nbComponentsToAllocate);
|
||||||
Vector3* newAngularVelocities = reinterpret_cast<Vector3*>(newLinearVelocities + nbComponentsToAllocate);
|
|
||||||
Vector3* newConstrainedLinearVelocities = reinterpret_cast<Vector3*>(newAngularVelocities + nbComponentsToAllocate);
|
|
||||||
Vector3* newConstrainedAngularVelocities = reinterpret_cast<Vector3*>(newConstrainedLinearVelocities + nbComponentsToAllocate);
|
Vector3* newConstrainedAngularVelocities = reinterpret_cast<Vector3*>(newConstrainedLinearVelocities + nbComponentsToAllocate);
|
||||||
Vector3* newSplitLinearVelocities = reinterpret_cast<Vector3*>(newConstrainedAngularVelocities + nbComponentsToAllocate);
|
Vector3* newSplitLinearVelocities = reinterpret_cast<Vector3*>(newConstrainedAngularVelocities + nbComponentsToAllocate);
|
||||||
Vector3* newSplitAngularVelocities = reinterpret_cast<Vector3*>(newSplitLinearVelocities + nbComponentsToAllocate);
|
Vector3* newSplitAngularVelocities = reinterpret_cast<Vector3*>(newSplitLinearVelocities + nbComponentsToAllocate);
|
||||||
@ -85,8 +82,6 @@ void DynamicsComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
|
|
||||||
// Copy component data from the previous buffer to the new one
|
// Copy component data from the previous buffer to the new one
|
||||||
memcpy(newBodies, mBodies, mNbComponents * sizeof(Entity));
|
memcpy(newBodies, mBodies, mNbComponents * sizeof(Entity));
|
||||||
memcpy(newLinearVelocities, mLinearVelocities, mNbComponents * sizeof(Vector3));
|
|
||||||
memcpy(newAngularVelocities, mAngularVelocities, mNbComponents * sizeof(Vector3));
|
|
||||||
memcpy(newConstrainedLinearVelocities, mConstrainedLinearVelocities, mNbComponents * sizeof(Vector3));
|
memcpy(newConstrainedLinearVelocities, mConstrainedLinearVelocities, mNbComponents * sizeof(Vector3));
|
||||||
memcpy(newConstrainedAngularVelocities, mConstrainedAngularVelocities, mNbComponents * sizeof(Vector3));
|
memcpy(newConstrainedAngularVelocities, mConstrainedAngularVelocities, mNbComponents * sizeof(Vector3));
|
||||||
memcpy(newSplitLinearVelocities, mSplitLinearVelocities, mNbComponents * sizeof(Vector3));
|
memcpy(newSplitLinearVelocities, mSplitLinearVelocities, mNbComponents * sizeof(Vector3));
|
||||||
@ -112,8 +107,6 @@ void DynamicsComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
|
|
||||||
mBuffer = newBuffer;
|
mBuffer = newBuffer;
|
||||||
mBodies = newBodies;
|
mBodies = newBodies;
|
||||||
mLinearVelocities = newLinearVelocities;
|
|
||||||
mAngularVelocities = newAngularVelocities;
|
|
||||||
mConstrainedLinearVelocities = newConstrainedLinearVelocities;
|
mConstrainedLinearVelocities = newConstrainedLinearVelocities;
|
||||||
mConstrainedAngularVelocities = newConstrainedAngularVelocities;
|
mConstrainedAngularVelocities = newConstrainedAngularVelocities;
|
||||||
mSplitLinearVelocities = newSplitLinearVelocities;
|
mSplitLinearVelocities = newSplitLinearVelocities;
|
||||||
@ -144,8 +137,6 @@ void DynamicsComponents::addComponent(Entity bodyEntity, bool isSleeping, const
|
|||||||
|
|
||||||
// Insert the new component data
|
// Insert the new component data
|
||||||
new (mBodies + index) Entity(bodyEntity);
|
new (mBodies + index) Entity(bodyEntity);
|
||||||
new (mLinearVelocities + index) Vector3(0, 0, 0);
|
|
||||||
new (mAngularVelocities + index) Vector3(0, 0, 0);
|
|
||||||
new (mConstrainedLinearVelocities + index) Vector3(0, 0, 0);
|
new (mConstrainedLinearVelocities + index) Vector3(0, 0, 0);
|
||||||
new (mConstrainedAngularVelocities + index) Vector3(0, 0, 0);
|
new (mConstrainedAngularVelocities + index) Vector3(0, 0, 0);
|
||||||
new (mSplitLinearVelocities + index) Vector3(0, 0, 0);
|
new (mSplitLinearVelocities + index) Vector3(0, 0, 0);
|
||||||
@ -182,8 +173,6 @@ void DynamicsComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex)
|
|||||||
|
|
||||||
// Copy the data of the source component to the destination location
|
// Copy the data of the source component to the destination location
|
||||||
new (mBodies + destIndex) Entity(mBodies[srcIndex]);
|
new (mBodies + destIndex) Entity(mBodies[srcIndex]);
|
||||||
new (mLinearVelocities + destIndex) Vector3(mLinearVelocities[srcIndex]);
|
|
||||||
new (mAngularVelocities + destIndex) Vector3(mAngularVelocities[srcIndex]);
|
|
||||||
new (mConstrainedLinearVelocities + destIndex) Vector3(mConstrainedLinearVelocities[srcIndex]);
|
new (mConstrainedLinearVelocities + destIndex) Vector3(mConstrainedLinearVelocities[srcIndex]);
|
||||||
new (mConstrainedAngularVelocities + destIndex) Vector3(mConstrainedAngularVelocities[srcIndex]);
|
new (mConstrainedAngularVelocities + destIndex) Vector3(mConstrainedAngularVelocities[srcIndex]);
|
||||||
new (mSplitLinearVelocities + destIndex) Vector3(mSplitLinearVelocities[srcIndex]);
|
new (mSplitLinearVelocities + destIndex) Vector3(mSplitLinearVelocities[srcIndex]);
|
||||||
@ -222,8 +211,6 @@ void DynamicsComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||||||
|
|
||||||
// Copy component 1 data
|
// Copy component 1 data
|
||||||
Entity entity1(mBodies[index1]);
|
Entity entity1(mBodies[index1]);
|
||||||
Vector3 linearVelocity1(mLinearVelocities[index1]);
|
|
||||||
Vector3 angularVelocity1(mAngularVelocities[index1]);
|
|
||||||
Vector3 constrainedLinearVelocity1(mConstrainedLinearVelocities[index1]);
|
Vector3 constrainedLinearVelocity1(mConstrainedLinearVelocities[index1]);
|
||||||
Vector3 constrainedAngularVelocity1(mConstrainedAngularVelocities[index1]);
|
Vector3 constrainedAngularVelocity1(mConstrainedAngularVelocities[index1]);
|
||||||
Vector3 splitLinearVelocity1(mSplitLinearVelocities[index1]);
|
Vector3 splitLinearVelocity1(mSplitLinearVelocities[index1]);
|
||||||
@ -250,8 +237,6 @@ void DynamicsComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||||||
|
|
||||||
// Reconstruct component 1 at component 2 location
|
// Reconstruct component 1 at component 2 location
|
||||||
new (mBodies + index2) Entity(entity1);
|
new (mBodies + index2) Entity(entity1);
|
||||||
new (mLinearVelocities + index2) Vector3(linearVelocity1);
|
|
||||||
new (mAngularVelocities + index2) Vector3(angularVelocity1);
|
|
||||||
new (mConstrainedLinearVelocities + index2) Vector3(constrainedLinearVelocity1);
|
new (mConstrainedLinearVelocities + index2) Vector3(constrainedLinearVelocity1);
|
||||||
new (mConstrainedAngularVelocities + index2) Vector3(constrainedAngularVelocity1);
|
new (mConstrainedAngularVelocities + index2) Vector3(constrainedAngularVelocity1);
|
||||||
new (mSplitLinearVelocities + index2) Vector3(splitLinearVelocity1);
|
new (mSplitLinearVelocities + index2) Vector3(splitLinearVelocity1);
|
||||||
@ -289,8 +274,6 @@ void DynamicsComponents::destroyComponent(uint32 index) {
|
|||||||
mMapEntityToComponentIndex.remove(mBodies[index]);
|
mMapEntityToComponentIndex.remove(mBodies[index]);
|
||||||
|
|
||||||
mBodies[index].~Entity();
|
mBodies[index].~Entity();
|
||||||
mLinearVelocities[index].~Vector3();
|
|
||||||
mAngularVelocities[index].~Vector3();
|
|
||||||
mConstrainedLinearVelocities[index].~Vector3();
|
mConstrainedLinearVelocities[index].~Vector3();
|
||||||
mConstrainedAngularVelocities[index].~Vector3();
|
mConstrainedAngularVelocities[index].~Vector3();
|
||||||
mSplitLinearVelocities[index].~Vector3();
|
mSplitLinearVelocities[index].~Vector3();
|
||||||
|
|||||||
@ -40,17 +40,6 @@ namespace reactphysics3d {
|
|||||||
class MemoryAllocator;
|
class MemoryAllocator;
|
||||||
class EntityManager;
|
class EntityManager;
|
||||||
|
|
||||||
/// Enumeration for the type of a body
|
|
||||||
/// STATIC : A static body has infinite mass, zero velocity but the position can be
|
|
||||||
/// changed manually. A static body does not collide with other static or kinematic bodies.
|
|
||||||
/// KINEMATIC : A kinematic body has infinite mass, the velocity can be changed manually and its
|
|
||||||
/// position is computed by the physics engine. A kinematic body does not collide with
|
|
||||||
/// other static or kinematic bodies.
|
|
||||||
/// DYNAMIC : A dynamic body has non-zero mass, non-zero velocity determined by forces and its
|
|
||||||
/// position is determined by the physics engine. A dynamic body can collide with other
|
|
||||||
/// dynamic, static or kinematic bodies.
|
|
||||||
enum class BodyType {STATIC, KINEMATIC, DYNAMIC};
|
|
||||||
|
|
||||||
// Class DynamicsComponents
|
// Class DynamicsComponents
|
||||||
/**
|
/**
|
||||||
* This class represent the component of the ECS that contains the variables concerning dynamics
|
* This class represent the component of the ECS that contains the variables concerning dynamics
|
||||||
@ -66,12 +55,6 @@ class DynamicsComponents : public Components {
|
|||||||
/// Array of body entities of each component
|
/// Array of body entities of each component
|
||||||
Entity* mBodies;
|
Entity* mBodies;
|
||||||
|
|
||||||
/// Array with the linear velocity of each component
|
|
||||||
Vector3* mLinearVelocities;
|
|
||||||
|
|
||||||
/// Array with the angular velocity of each component
|
|
||||||
Vector3* mAngularVelocities;
|
|
||||||
|
|
||||||
/// Array with the constrained linear velocity of each component
|
/// Array with the constrained linear velocity of each component
|
||||||
Vector3* mConstrainedLinearVelocities;
|
Vector3* mConstrainedLinearVelocities;
|
||||||
|
|
||||||
@ -165,12 +148,6 @@ class DynamicsComponents : public Components {
|
|||||||
/// Add a component
|
/// Add a component
|
||||||
void addComponent(Entity bodyEntity, bool isSleeping, const DynamicsComponent& component);
|
void addComponent(Entity bodyEntity, bool isSleeping, const DynamicsComponent& component);
|
||||||
|
|
||||||
/// Return the linear velocity of an entity
|
|
||||||
const Vector3& getLinearVelocity(Entity bodyEntity) const;
|
|
||||||
|
|
||||||
/// Return the angular velocity of an entity
|
|
||||||
const Vector3& getAngularVelocity(Entity bodyEntity) const;
|
|
||||||
|
|
||||||
/// Return the constrained linear velocity of an entity
|
/// Return the constrained linear velocity of an entity
|
||||||
const Vector3& getConstrainedLinearVelocity(Entity bodyEntity) const;
|
const Vector3& getConstrainedLinearVelocity(Entity bodyEntity) const;
|
||||||
|
|
||||||
@ -225,12 +202,6 @@ class DynamicsComponents : public Components {
|
|||||||
/// Return true if the entity is already in an island
|
/// Return true if the entity is already in an island
|
||||||
bool getIsAlreadyInIsland(Entity bodyEntity) const;
|
bool getIsAlreadyInIsland(Entity bodyEntity) const;
|
||||||
|
|
||||||
/// Set the linear velocity of an entity
|
|
||||||
void setLinearVelocity(Entity bodyEntity, const Vector3& linearVelocity);
|
|
||||||
|
|
||||||
/// Set the angular velocity of an entity
|
|
||||||
void setAngularVelocity(Entity bodyEntity, const Vector3& angularVelocity);
|
|
||||||
|
|
||||||
/// Set the constrained linear velocity of an entity
|
/// Set the constrained linear velocity of an entity
|
||||||
void setConstrainedLinearVelocity(Entity bodyEntity, const Vector3& constrainedLinearVelocity);
|
void setConstrainedLinearVelocity(Entity bodyEntity, const Vector3& constrainedLinearVelocity);
|
||||||
|
|
||||||
@ -296,38 +267,6 @@ class DynamicsComponents : public Components {
|
|||||||
friend class SliderJoint;
|
friend class SliderJoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the linear velocity of an entity
|
|
||||||
inline const Vector3& DynamicsComponents::getLinearVelocity(Entity bodyEntity) const {
|
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
|
||||||
|
|
||||||
return mLinearVelocities[mMapEntityToComponentIndex[bodyEntity]];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the angular velocity of an entity
|
|
||||||
inline const Vector3 &DynamicsComponents::getAngularVelocity(Entity bodyEntity) const {
|
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
|
||||||
|
|
||||||
return mAngularVelocities[mMapEntityToComponentIndex[bodyEntity]];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the linear velocity of an entity
|
|
||||||
inline void DynamicsComponents::setLinearVelocity(Entity bodyEntity, const Vector3& linearVelocity) {
|
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
|
||||||
|
|
||||||
mLinearVelocities[mMapEntityToComponentIndex[bodyEntity]] = linearVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the angular velocity of an entity
|
|
||||||
inline void DynamicsComponents::setAngularVelocity(Entity bodyEntity, const Vector3& angularVelocity) {
|
|
||||||
|
|
||||||
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
|
||||||
|
|
||||||
mAngularVelocities[mMapEntityToComponentIndex[bodyEntity]] = angularVelocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the constrained linear velocity of an entity
|
// Return the constrained linear velocity of an entity
|
||||||
inline const Vector3& DynamicsComponents::getConstrainedLinearVelocity(Entity bodyEntity) const {
|
inline const Vector3& DynamicsComponents::getConstrainedLinearVelocity(Entity bodyEntity) const {
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,8 @@ using namespace reactphysics3d;
|
|||||||
// Constructor
|
// Constructor
|
||||||
RigidBodyComponents::RigidBodyComponents(MemoryAllocator& allocator)
|
RigidBodyComponents::RigidBodyComponents(MemoryAllocator& allocator)
|
||||||
:Components(allocator, sizeof(Entity) + sizeof(RigidBody*) +
|
:Components(allocator, sizeof(Entity) + sizeof(RigidBody*) +
|
||||||
sizeof(bool) + sizeof(bool) + sizeof(decimal) + sizeof(BodyType)) {
|
sizeof(bool) + sizeof(bool) + sizeof(decimal) + sizeof(BodyType) +
|
||||||
|
sizeof(Vector3) + sizeof(Vector3)) {
|
||||||
|
|
||||||
// Allocate memory for the components data
|
// Allocate memory for the components data
|
||||||
allocate(INIT_NB_ALLOCATED_COMPONENTS);
|
allocate(INIT_NB_ALLOCATED_COMPONENTS);
|
||||||
@ -61,6 +62,8 @@ void RigidBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
bool* newIsSleeping = reinterpret_cast<bool*>(newIsAllowedToSleep + nbComponentsToAllocate);
|
bool* newIsSleeping = reinterpret_cast<bool*>(newIsAllowedToSleep + nbComponentsToAllocate);
|
||||||
decimal* newSleepTimes = reinterpret_cast<decimal*>(newIsSleeping + nbComponentsToAllocate);
|
decimal* newSleepTimes = reinterpret_cast<decimal*>(newIsSleeping + nbComponentsToAllocate);
|
||||||
BodyType* newBodyTypes = reinterpret_cast<BodyType*>(newSleepTimes + nbComponentsToAllocate);
|
BodyType* newBodyTypes = reinterpret_cast<BodyType*>(newSleepTimes + nbComponentsToAllocate);
|
||||||
|
Vector3* newLinearVelocities = reinterpret_cast<Vector3*>(newBodyTypes + nbComponentsToAllocate);
|
||||||
|
Vector3* newAngularVelocities = reinterpret_cast<Vector3*>(newLinearVelocities + nbComponentsToAllocate);
|
||||||
|
|
||||||
// If there was already components before
|
// If there was already components before
|
||||||
if (mNbComponents > 0) {
|
if (mNbComponents > 0) {
|
||||||
@ -72,6 +75,8 @@ void RigidBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
memcpy(newIsSleeping, mIsSleeping, mNbComponents * sizeof(bool));
|
memcpy(newIsSleeping, mIsSleeping, mNbComponents * sizeof(bool));
|
||||||
memcpy(newSleepTimes, mSleepTimes, mNbComponents * sizeof(bool));
|
memcpy(newSleepTimes, mSleepTimes, mNbComponents * sizeof(bool));
|
||||||
memcpy(newBodyTypes, mBodyTypes, mNbComponents * sizeof(BodyType));
|
memcpy(newBodyTypes, mBodyTypes, mNbComponents * sizeof(BodyType));
|
||||||
|
memcpy(newLinearVelocities, mLinearVelocities, mNbComponents * sizeof(Vector3));
|
||||||
|
memcpy(newAngularVelocities, mAngularVelocities, mNbComponents * sizeof(Vector3));
|
||||||
|
|
||||||
// Deallocate previous memory
|
// Deallocate previous memory
|
||||||
mMemoryAllocator.release(mBuffer, mNbAllocatedComponents * mComponentDataSize);
|
mMemoryAllocator.release(mBuffer, mNbAllocatedComponents * mComponentDataSize);
|
||||||
@ -85,6 +90,8 @@ void RigidBodyComponents::allocate(uint32 nbComponentsToAllocate) {
|
|||||||
mSleepTimes = newSleepTimes;
|
mSleepTimes = newSleepTimes;
|
||||||
mNbAllocatedComponents = nbComponentsToAllocate;
|
mNbAllocatedComponents = nbComponentsToAllocate;
|
||||||
mBodyTypes = newBodyTypes;
|
mBodyTypes = newBodyTypes;
|
||||||
|
mLinearVelocities = newLinearVelocities;
|
||||||
|
mAngularVelocities = newAngularVelocities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a component
|
// Add a component
|
||||||
@ -100,6 +107,8 @@ void RigidBodyComponents::addComponent(Entity bodyEntity, bool isSleeping, const
|
|||||||
mIsSleeping[index] = false;
|
mIsSleeping[index] = false;
|
||||||
mSleepTimes[index] = decimal(0);
|
mSleepTimes[index] = decimal(0);
|
||||||
mBodyTypes[index] = component.bodyType;
|
mBodyTypes[index] = component.bodyType;
|
||||||
|
new (mLinearVelocities + index) Vector3(0, 0, 0);
|
||||||
|
new (mAngularVelocities + index) Vector3(0, 0, 0);
|
||||||
|
|
||||||
// Map the entity with the new component lookup index
|
// Map the entity with the new component lookup index
|
||||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(bodyEntity, index));
|
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(bodyEntity, index));
|
||||||
@ -123,6 +132,8 @@ void RigidBodyComponents::moveComponentToIndex(uint32 srcIndex, uint32 destIndex
|
|||||||
mIsSleeping[destIndex] = mIsSleeping[srcIndex];
|
mIsSleeping[destIndex] = mIsSleeping[srcIndex];
|
||||||
mSleepTimes[destIndex] = mSleepTimes[srcIndex];
|
mSleepTimes[destIndex] = mSleepTimes[srcIndex];
|
||||||
mBodyTypes[destIndex] = mBodyTypes[srcIndex];
|
mBodyTypes[destIndex] = mBodyTypes[srcIndex];
|
||||||
|
new (mLinearVelocities + destIndex) Vector3(mLinearVelocities[srcIndex]);
|
||||||
|
new (mAngularVelocities + destIndex) Vector3(mAngularVelocities[srcIndex]);
|
||||||
|
|
||||||
// Destroy the source component
|
// Destroy the source component
|
||||||
destroyComponent(srcIndex);
|
destroyComponent(srcIndex);
|
||||||
@ -145,6 +156,8 @@ void RigidBodyComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||||||
bool isSleeping1 = mIsSleeping[index1];
|
bool isSleeping1 = mIsSleeping[index1];
|
||||||
decimal sleepTime1 = mSleepTimes[index1];
|
decimal sleepTime1 = mSleepTimes[index1];
|
||||||
BodyType bodyType1 = mBodyTypes[index1];
|
BodyType bodyType1 = mBodyTypes[index1];
|
||||||
|
Vector3 linearVelocity1(mLinearVelocities[index1]);
|
||||||
|
Vector3 angularVelocity1(mAngularVelocities[index1]);
|
||||||
|
|
||||||
// Destroy component 1
|
// Destroy component 1
|
||||||
destroyComponent(index1);
|
destroyComponent(index1);
|
||||||
@ -158,6 +171,8 @@ void RigidBodyComponents::swapComponents(uint32 index1, uint32 index2) {
|
|||||||
mIsSleeping[index2] = isSleeping1;
|
mIsSleeping[index2] = isSleeping1;
|
||||||
mSleepTimes[index2] = sleepTime1;
|
mSleepTimes[index2] = sleepTime1;
|
||||||
mBodyTypes[index2] = bodyType1;
|
mBodyTypes[index2] = bodyType1;
|
||||||
|
new (mLinearVelocities + index2) Vector3(linearVelocity1);
|
||||||
|
new (mAngularVelocities + index2) Vector3(angularVelocity1);
|
||||||
|
|
||||||
// Update the entity to component index mapping
|
// Update the entity to component index mapping
|
||||||
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity1, index2));
|
mMapEntityToComponentIndex.add(Pair<Entity, uint32>(entity1, index2));
|
||||||
@ -178,4 +193,6 @@ void RigidBodyComponents::destroyComponent(uint32 index) {
|
|||||||
|
|
||||||
mBodiesEntities[index].~Entity();
|
mBodiesEntities[index].~Entity();
|
||||||
mRigidBodies[index] = nullptr;
|
mRigidBodies[index] = nullptr;
|
||||||
|
mLinearVelocities[index].~Vector3();
|
||||||
|
mAngularVelocities[index].~Vector3();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,17 @@ class EntityManager;
|
|||||||
class RigidBody;
|
class RigidBody;
|
||||||
enum class BodyType;
|
enum class BodyType;
|
||||||
|
|
||||||
|
/// Enumeration for the type of a body
|
||||||
|
/// STATIC : A static body has infinite mass, zero velocity but the position can be
|
||||||
|
/// changed manually. A static body does not collide with other static or kinematic bodies.
|
||||||
|
/// KINEMATIC : A kinematic body has infinite mass, the velocity can be changed manually and its
|
||||||
|
/// position is computed by the physics engine. A kinematic body does not collide with
|
||||||
|
/// other static or kinematic bodies.
|
||||||
|
/// DYNAMIC : A dynamic body has non-zero mass, non-zero velocity determined by forces and its
|
||||||
|
/// position is determined by the physics engine. A dynamic body can collide with other
|
||||||
|
/// dynamic, static or kinematic bodies.
|
||||||
|
enum class BodyType {STATIC, KINEMATIC, DYNAMIC};
|
||||||
|
|
||||||
// Class RigidBodyComponents
|
// Class RigidBodyComponents
|
||||||
/**
|
/**
|
||||||
* This class represent the component of the ECS that contains data about a rigid body.
|
* This class represent the component of the ECS that contains data about a rigid body.
|
||||||
@ -70,6 +81,12 @@ class RigidBodyComponents : public Components {
|
|||||||
/// Array with the type of bodies (static, kinematic or dynamic)
|
/// Array with the type of bodies (static, kinematic or dynamic)
|
||||||
BodyType* mBodyTypes;
|
BodyType* mBodyTypes;
|
||||||
|
|
||||||
|
/// Array with the linear velocity of each component
|
||||||
|
Vector3* mLinearVelocities;
|
||||||
|
|
||||||
|
/// Array with the angular velocity of each component
|
||||||
|
Vector3* mAngularVelocities;
|
||||||
|
|
||||||
// -------------------- Methods -------------------- //
|
// -------------------- Methods -------------------- //
|
||||||
|
|
||||||
/// Allocate memory for a given number of components
|
/// Allocate memory for a given number of components
|
||||||
@ -136,6 +153,17 @@ class RigidBodyComponents : public Components {
|
|||||||
/// Set the body type of a body
|
/// Set the body type of a body
|
||||||
void setBodyType(Entity bodyEntity, BodyType bodyType);
|
void setBodyType(Entity bodyEntity, BodyType bodyType);
|
||||||
|
|
||||||
|
/// Return the linear velocity of an entity
|
||||||
|
const Vector3& getLinearVelocity(Entity bodyEntity) const;
|
||||||
|
|
||||||
|
/// Set the linear velocity of an entity
|
||||||
|
void setLinearVelocity(Entity bodyEntity, const Vector3& linearVelocity);
|
||||||
|
|
||||||
|
/// Return the angular velocity of an entity
|
||||||
|
const Vector3& getAngularVelocity(Entity bodyEntity) const;
|
||||||
|
|
||||||
|
/// Set the angular velocity of an entity
|
||||||
|
void setAngularVelocity(Entity bodyEntity, const Vector3& angularVelocity);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return a pointer to a body rigid
|
// Return a pointer to a body rigid
|
||||||
@ -210,6 +238,38 @@ inline void RigidBodyComponents::setBodyType(Entity bodyEntity, BodyType bodyTyp
|
|||||||
mBodyTypes[mMapEntityToComponentIndex[bodyEntity]] = bodyType;
|
mBodyTypes[mMapEntityToComponentIndex[bodyEntity]] = bodyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the linear velocity of an entity
|
||||||
|
inline const Vector3& RigidBodyComponents::getLinearVelocity(Entity bodyEntity) const {
|
||||||
|
|
||||||
|
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||||
|
|
||||||
|
return mLinearVelocities[mMapEntityToComponentIndex[bodyEntity]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the angular velocity of an entity
|
||||||
|
inline const Vector3& RigidBodyComponents::getAngularVelocity(Entity bodyEntity) const {
|
||||||
|
|
||||||
|
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||||
|
|
||||||
|
return mAngularVelocities[mMapEntityToComponentIndex[bodyEntity]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the linear velocity of an entity
|
||||||
|
inline void RigidBodyComponents::setLinearVelocity(Entity bodyEntity, const Vector3& linearVelocity) {
|
||||||
|
|
||||||
|
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||||
|
|
||||||
|
mLinearVelocities[mMapEntityToComponentIndex[bodyEntity]] = linearVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the angular velocity of an entity
|
||||||
|
inline void RigidBodyComponents::setAngularVelocity(Entity bodyEntity, const Vector3& angularVelocity) {
|
||||||
|
|
||||||
|
assert(mMapEntityToComponentIndex.containsKey(bodyEntity));
|
||||||
|
|
||||||
|
mAngularVelocities[mMapEntityToComponentIndex[bodyEntity]] = angularVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "BallAndSocketJoint.h"
|
#include "BallAndSocketJoint.h"
|
||||||
#include "engine/ConstraintSolver.h"
|
#include "engine/ConstraintSolver.h"
|
||||||
#include "components/DynamicsComponents.h"
|
#include "components/DynamicsComponents.h"
|
||||||
|
#include "components/RigidBodyComponents.h"
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "FixedJoint.h"
|
#include "FixedJoint.h"
|
||||||
#include "engine/ConstraintSolver.h"
|
#include "engine/ConstraintSolver.h"
|
||||||
#include "components/DynamicsComponents.h"
|
#include "components/DynamicsComponents.h"
|
||||||
|
#include "components/RigidBodyComponents.h"
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "HingeJoint.h"
|
#include "HingeJoint.h"
|
||||||
#include "engine/ConstraintSolver.h"
|
#include "engine/ConstraintSolver.h"
|
||||||
#include "components/DynamicsComponents.h"
|
#include "components/DynamicsComponents.h"
|
||||||
|
#include "components/RigidBodyComponents.h"
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "SliderJoint.h"
|
#include "SliderJoint.h"
|
||||||
#include "engine/ConstraintSolver.h"
|
#include "engine/ConstraintSolver.h"
|
||||||
#include "components/DynamicsComponents.h"
|
#include "components/DynamicsComponents.h"
|
||||||
|
#include "components/RigidBodyComponents.h"
|
||||||
|
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ CollisionWorld::CollisionWorld(const WorldSettings& worldSettings, Logger* logge
|
|||||||
mCollisionBodyComponents(mMemoryManager.getBaseAllocator()), mRigidBodyComponents(mMemoryManager.getBaseAllocator()),
|
mCollisionBodyComponents(mMemoryManager.getBaseAllocator()), mRigidBodyComponents(mMemoryManager.getBaseAllocator()),
|
||||||
mTransformComponents(mMemoryManager.getBaseAllocator()), mProxyShapesComponents(mMemoryManager.getBaseAllocator()),
|
mTransformComponents(mMemoryManager.getBaseAllocator()), mProxyShapesComponents(mMemoryManager.getBaseAllocator()),
|
||||||
mDynamicsComponents(mMemoryManager.getBaseAllocator()),
|
mDynamicsComponents(mMemoryManager.getBaseAllocator()),
|
||||||
mCollisionDetection(this, mProxyShapesComponents, mTransformComponents, mDynamicsComponents, mMemoryManager),
|
mCollisionDetection(this, mProxyShapesComponents, mTransformComponents, mRigidBodyComponents, mMemoryManager),
|
||||||
mBodies(mMemoryManager.getPoolAllocator()), mEventListener(nullptr),
|
mBodies(mMemoryManager.getPoolAllocator()), mEventListener(nullptr),
|
||||||
mName(worldSettings.worldName), mIsProfilerCreatedByUser(profiler != nullptr),
|
mName(worldSettings.worldName), mIsProfilerCreatedByUser(profiler != nullptr),
|
||||||
mIsLoggerCreatedByUser(logger != nullptr) {
|
mIsLoggerCreatedByUser(logger != nullptr) {
|
||||||
|
|||||||
@ -44,12 +44,13 @@ const decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2);
|
|||||||
const decimal ContactSolver::SLOP = decimal(0.01);
|
const decimal ContactSolver::SLOP = decimal(0.01);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ContactSolver::ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents, DynamicsComponents& dynamicsComponents,
|
ContactSolver::ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents,
|
||||||
|
RigidBodyComponents& rigidBodyComponents, DynamicsComponents& dynamicsComponents,
|
||||||
ProxyShapeComponents& proxyShapeComponents, const WorldSettings& worldSettings)
|
ProxyShapeComponents& proxyShapeComponents, const WorldSettings& worldSettings)
|
||||||
:mMemoryManager(memoryManager), mContactConstraints(nullptr), mContactPoints(nullptr),
|
:mMemoryManager(memoryManager), mContactConstraints(nullptr), mContactPoints(nullptr),
|
||||||
mIslands(islands), mAllContactManifolds(nullptr), mAllContactPoints(nullptr), mBodyComponents(bodyComponents),
|
mIslands(islands), mAllContactManifolds(nullptr), mAllContactPoints(nullptr), mBodyComponents(bodyComponents),
|
||||||
mDynamicsComponents(dynamicsComponents), mProxyShapeComponents(proxyShapeComponents), mIsSplitImpulseActive(true),
|
mRigidBodyComponents(rigidBodyComponents), mDynamicsComponents(dynamicsComponents),
|
||||||
mWorldSettings(worldSettings) {
|
mProxyShapeComponents(proxyShapeComponents), mIsSplitImpulseActive(true), mWorldSettings(worldSettings) {
|
||||||
|
|
||||||
#ifdef IS_PROFILING_ACTIVE
|
#ifdef IS_PROFILING_ACTIVE
|
||||||
mProfiler = nullptr;
|
mProfiler = nullptr;
|
||||||
@ -152,10 +153,10 @@ void ContactSolver::initializeForIsland(uint islandIndex) {
|
|||||||
mContactConstraints[mNbContactManifolds].frictionPointBody2.setToZero();
|
mContactConstraints[mNbContactManifolds].frictionPointBody2.setToZero();
|
||||||
|
|
||||||
// Get the velocities of the bodies
|
// Get the velocities of the bodies
|
||||||
const Vector3& v1 = mDynamicsComponents.getLinearVelocity(externalManifold.bodyEntity1);
|
const Vector3& v1 = mRigidBodyComponents.getLinearVelocity(externalManifold.bodyEntity1);
|
||||||
const Vector3& w1 = mDynamicsComponents.getAngularVelocity(externalManifold.bodyEntity1);
|
const Vector3& w1 = mRigidBodyComponents.getAngularVelocity(externalManifold.bodyEntity1);
|
||||||
const Vector3& v2 = mDynamicsComponents.getLinearVelocity(externalManifold.bodyEntity2);
|
const Vector3& v2 = mRigidBodyComponents.getLinearVelocity(externalManifold.bodyEntity2);
|
||||||
const Vector3& w2 = mDynamicsComponents.getAngularVelocity(externalManifold.bodyEntity2);
|
const Vector3& w2 = mRigidBodyComponents.getAngularVelocity(externalManifold.bodyEntity2);
|
||||||
|
|
||||||
// For each contact point of the contact manifold
|
// For each contact point of the contact manifold
|
||||||
assert(externalManifold.getNbContactPoints() > 0);
|
assert(externalManifold.getNbContactPoints() > 0);
|
||||||
|
|||||||
@ -45,6 +45,7 @@ class Island;
|
|||||||
class RigidBody;
|
class RigidBody;
|
||||||
class CollisionBodyComponents;
|
class CollisionBodyComponents;
|
||||||
class DynamicsComponents;
|
class DynamicsComponents;
|
||||||
|
class RigidBodyComponents;
|
||||||
class ProxyShapeComponents;
|
class ProxyShapeComponents;
|
||||||
|
|
||||||
// Class Contact Solver
|
// Class Contact Solver
|
||||||
@ -312,6 +313,9 @@ class ContactSolver {
|
|||||||
/// Reference to the body components
|
/// Reference to the body components
|
||||||
CollisionBodyComponents& mBodyComponents;
|
CollisionBodyComponents& mBodyComponents;
|
||||||
|
|
||||||
|
/// Reference to the dynamics components
|
||||||
|
RigidBodyComponents& mRigidBodyComponents;
|
||||||
|
|
||||||
/// Reference to the dynamics components
|
/// Reference to the dynamics components
|
||||||
DynamicsComponents& mDynamicsComponents;
|
DynamicsComponents& mDynamicsComponents;
|
||||||
|
|
||||||
@ -360,8 +364,8 @@ class ContactSolver {
|
|||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents,
|
ContactSolver(MemoryManager& memoryManager, Islands& islands, CollisionBodyComponents& bodyComponents,
|
||||||
DynamicsComponents& dynamicsComponents, ProxyShapeComponents& proxyShapeComponents,
|
RigidBodyComponents& rigidBodyComponents, DynamicsComponents &dynamicsComponents,
|
||||||
const WorldSettings& worldSettings);
|
ProxyShapeComponents& proxyShapeComponents, const WorldSettings& worldSettings);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~ContactSolver() = default;
|
~ContactSolver() = default;
|
||||||
|
|||||||
@ -50,7 +50,8 @@ using namespace std;
|
|||||||
DynamicsWorld::DynamicsWorld(const Vector3& gravity, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler)
|
DynamicsWorld::DynamicsWorld(const Vector3& gravity, const WorldSettings& worldSettings, Logger* logger, Profiler* profiler)
|
||||||
: CollisionWorld(worldSettings, logger, profiler),
|
: CollisionWorld(worldSettings, logger, profiler),
|
||||||
mIslands(mMemoryManager.getSingleFrameAllocator()),
|
mIslands(mMemoryManager.getSingleFrameAllocator()),
|
||||||
mContactSolver(mMemoryManager, mIslands, mCollisionBodyComponents, mDynamicsComponents, mProxyShapesComponents, mConfig),
|
mContactSolver(mMemoryManager, mIslands, mCollisionBodyComponents, mRigidBodyComponents, mDynamicsComponents,
|
||||||
|
mProxyShapesComponents, mConfig),
|
||||||
mConstraintSolver(mIslands, mDynamicsComponents),
|
mConstraintSolver(mIslands, mDynamicsComponents),
|
||||||
mNbVelocitySolverIterations(mConfig.defaultVelocitySolverNbIterations),
|
mNbVelocitySolverIterations(mConfig.defaultVelocitySolverNbIterations),
|
||||||
mNbPositionSolverIterations(mConfig.defaultPositionSolverNbIterations),
|
mNbPositionSolverIterations(mConfig.defaultPositionSolverNbIterations),
|
||||||
@ -200,8 +201,8 @@ void DynamicsWorld::updateBodiesState() {
|
|||||||
for (uint32 i=0; i < mDynamicsComponents.getNbEnabledComponents(); i++) {
|
for (uint32 i=0; i < mDynamicsComponents.getNbEnabledComponents(); i++) {
|
||||||
|
|
||||||
// Update the linear and angular velocity of the body
|
// Update the linear and angular velocity of the body
|
||||||
mDynamicsComponents.mLinearVelocities[i] = mDynamicsComponents.mConstrainedLinearVelocities[i];
|
mRigidBodyComponents.setLinearVelocity(mDynamicsComponents.mBodies[i], mDynamicsComponents.mConstrainedLinearVelocities[i]);
|
||||||
mDynamicsComponents.mAngularVelocities[i] = mDynamicsComponents.mConstrainedAngularVelocities[i];
|
mRigidBodyComponents.setAngularVelocity(mDynamicsComponents.mBodies[i], mDynamicsComponents.mConstrainedAngularVelocities[i]);
|
||||||
|
|
||||||
// Update the position of the center of mass of the body
|
// Update the position of the center of mass of the body
|
||||||
mDynamicsComponents.mCentersOfMassWorld[i] = mDynamicsComponents.mConstrainedPositions[i];
|
mDynamicsComponents.mCentersOfMassWorld[i] = mDynamicsComponents.mConstrainedPositions[i];
|
||||||
@ -259,11 +260,14 @@ void DynamicsWorld::integrateRigidBodiesVelocities() {
|
|||||||
assert(mDynamicsComponents.mSplitLinearVelocities[i] == Vector3(0, 0, 0));
|
assert(mDynamicsComponents.mSplitLinearVelocities[i] == Vector3(0, 0, 0));
|
||||||
assert(mDynamicsComponents.mSplitAngularVelocities[i] == Vector3(0, 0, 0));
|
assert(mDynamicsComponents.mSplitAngularVelocities[i] == Vector3(0, 0, 0));
|
||||||
|
|
||||||
|
const Vector3& linearVelocity = mRigidBodyComponents.getLinearVelocity(mDynamicsComponents.mBodies[i]);
|
||||||
|
const Vector3& angularVelocity = mRigidBodyComponents.getAngularVelocity(mDynamicsComponents.mBodies[i]);
|
||||||
|
|
||||||
// Integrate the external force to get the new velocity of the body
|
// Integrate the external force to get the new velocity of the body
|
||||||
mDynamicsComponents.mConstrainedLinearVelocities[i] = mDynamicsComponents.mLinearVelocities[i] + mTimeStep *
|
mDynamicsComponents.mConstrainedLinearVelocities[i] = linearVelocity + mTimeStep *
|
||||||
mDynamicsComponents.mInverseMasses[i] * mDynamicsComponents.mExternalForces[i];
|
mDynamicsComponents.mInverseMasses[i] * mDynamicsComponents.mExternalForces[i];
|
||||||
mDynamicsComponents.mConstrainedAngularVelocities[i] = mDynamicsComponents.mAngularVelocities[i] +
|
mDynamicsComponents.mConstrainedAngularVelocities[i] = angularVelocity + mTimeStep *
|
||||||
mTimeStep * mDynamicsComponents.mInverseInertiaTensorsWorld[i] * mDynamicsComponents.mExternalTorques[i];
|
mDynamicsComponents.mInverseInertiaTensorsWorld[i] * mDynamicsComponents.mExternalTorques[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply gravity force
|
// Apply gravity force
|
||||||
@ -805,26 +809,24 @@ void DynamicsWorld::updateSleepingBodies() {
|
|||||||
|
|
||||||
const Entity bodyEntity = mIslands.bodyEntities[i][b];
|
const Entity bodyEntity = mIslands.bodyEntities[i][b];
|
||||||
|
|
||||||
RigidBody* body = mRigidBodyComponents.getRigidBody(bodyEntity);
|
|
||||||
|
|
||||||
// Skip static bodies
|
// Skip static bodies
|
||||||
if (mRigidBodyComponents.getBodyType(bodyEntity) == BodyType::STATIC) continue;
|
if (mRigidBodyComponents.getBodyType(bodyEntity) == BodyType::STATIC) continue;
|
||||||
|
|
||||||
// If the body is velocity is large enough to stay awake
|
// If the body is velocity is large enough to stay awake
|
||||||
if (mDynamicsComponents.getLinearVelocity(bodyEntity).lengthSquare() > sleepLinearVelocitySquare ||
|
if (mRigidBodyComponents.getLinearVelocity(bodyEntity).lengthSquare() > sleepLinearVelocitySquare ||
|
||||||
mDynamicsComponents.getAngularVelocity(bodyEntity).lengthSquare() > sleepAngularVelocitySquare ||
|
mRigidBodyComponents.getAngularVelocity(bodyEntity).lengthSquare() > sleepAngularVelocitySquare ||
|
||||||
!mRigidBodyComponents.getIsAllowedToSleep(body->getEntity())) {
|
!mRigidBodyComponents.getIsAllowedToSleep(bodyEntity)) {
|
||||||
|
|
||||||
// Reset the sleep time of the body
|
// Reset the sleep time of the body
|
||||||
mRigidBodyComponents.setSleepTime(body->getEntity(), decimal(0.0));
|
mRigidBodyComponents.setSleepTime(bodyEntity, decimal(0.0));
|
||||||
minSleepTime = decimal(0.0);
|
minSleepTime = decimal(0.0);
|
||||||
}
|
}
|
||||||
else { // If the body velocity is below the sleeping velocity threshold
|
else { // If the body velocity is below the sleeping velocity threshold
|
||||||
|
|
||||||
// Increase the sleep time
|
// Increase the sleep time
|
||||||
decimal sleepTime = mRigidBodyComponents.getSleepTime(body->getEntity());
|
decimal sleepTime = mRigidBodyComponents.getSleepTime(bodyEntity);
|
||||||
mRigidBodyComponents.setSleepTime(body->getEntity(), sleepTime + mTimeStep);
|
mRigidBodyComponents.setSleepTime(bodyEntity, sleepTime + mTimeStep);
|
||||||
sleepTime = mRigidBodyComponents.getSleepTime(body->getEntity());
|
sleepTime = mRigidBodyComponents.getSleepTime(bodyEntity);
|
||||||
if (sleepTime < minSleepTime) {
|
if (sleepTime < minSleepTime) {
|
||||||
minSleepTime = sleepTime;
|
minSleepTime = sleepTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,11 +36,10 @@ using namespace reactphysics3d;
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BroadPhaseSystem::BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
BroadPhaseSystem::BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
||||||
TransformComponents& transformComponents, DynamicsComponents& dynamicsComponents)
|
TransformComponents& transformComponents, RigidBodyComponents &rigidBodyComponents)
|
||||||
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
:mDynamicAABBTree(collisionDetection.getMemoryManager().getPoolAllocator(), DYNAMIC_TREE_AABB_GAP),
|
||||||
mProxyShapesComponents(proxyShapesComponents), mTransformsComponents(transformComponents),
|
mProxyShapesComponents(proxyShapesComponents), mTransformsComponents(transformComponents),
|
||||||
mDynamicsComponents(dynamicsComponents),
|
mRigidBodyComponents(rigidBodyComponents), mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
||||||
mMovedShapes(collisionDetection.getMemoryManager().getPoolAllocator()),
|
|
||||||
mCollisionDetection(collisionDetection) {
|
mCollisionDetection(collisionDetection) {
|
||||||
|
|
||||||
#ifdef IS_PROFILING_ACTIVE
|
#ifdef IS_PROFILING_ACTIVE
|
||||||
@ -175,10 +174,10 @@ void BroadPhaseSystem::updateProxyShapesComponents(uint32 startIndex, uint32 end
|
|||||||
|
|
||||||
// If there is a dynamics component for the current entity
|
// If there is a dynamics component for the current entity
|
||||||
Vector3 displacement(0, 0, 0);
|
Vector3 displacement(0, 0, 0);
|
||||||
if (mDynamicsComponents.hasComponent(bodyEntity)) {
|
if (mRigidBodyComponents.hasComponent(bodyEntity)) {
|
||||||
|
|
||||||
// Get the linear velocity from the dynamics component
|
// Get the linear velocity from the dynamics component
|
||||||
const Vector3& linearVelocity = mDynamicsComponents.getLinearVelocity(bodyEntity);
|
const Vector3& linearVelocity = mRigidBodyComponents.getLinearVelocity(bodyEntity);
|
||||||
|
|
||||||
// TODO : Use body linear velocity and compute displacement
|
// TODO : Use body linear velocity and compute displacement
|
||||||
displacement = timeStep * linearVelocity;
|
displacement = timeStep * linearVelocity;
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
#include "containers/Set.h"
|
#include "containers/Set.h"
|
||||||
#include "components/ProxyShapeComponents.h"
|
#include "components/ProxyShapeComponents.h"
|
||||||
#include "components/TransformComponents.h"
|
#include "components/TransformComponents.h"
|
||||||
#include "components/DynamicsComponents.h"
|
#include "components/RigidBodyComponents.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
/// Namespace ReactPhysics3D
|
/// Namespace ReactPhysics3D
|
||||||
@ -120,8 +120,8 @@ class BroadPhaseSystem {
|
|||||||
/// Reference to the transform components
|
/// Reference to the transform components
|
||||||
TransformComponents& mTransformsComponents;
|
TransformComponents& mTransformsComponents;
|
||||||
|
|
||||||
/// Reference to the dynamics components
|
/// Reference to the rigid body components
|
||||||
DynamicsComponents& mDynamicsComponents;
|
RigidBodyComponents& mRigidBodyComponents;
|
||||||
|
|
||||||
/// Set with the broad-phase IDs of all collision shapes that have moved (or have been
|
/// Set with the broad-phase IDs of all collision shapes that have moved (or have been
|
||||||
/// created) during the last simulation step. Those are the shapes that need to be tested
|
/// created) during the last simulation step. Those are the shapes that need to be tested
|
||||||
@ -151,7 +151,7 @@ class BroadPhaseSystem {
|
|||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
BroadPhaseSystem(CollisionDetection& collisionDetection, ProxyShapeComponents& proxyShapesComponents,
|
||||||
TransformComponents& transformComponents, DynamicsComponents& dynamicsComponents);
|
TransformComponents& transformComponents, RigidBodyComponents& rigidBodyComponents);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~BroadPhaseSystem() = default;
|
~BroadPhaseSystem() = default;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user