Put nodes in a broadphase to reduce tree updates

This commit is contained in:
Irlan 2019-06-15 11:33:24 -03:00
parent a3a9495d88
commit 11724ef5e3
4 changed files with 16 additions and 8 deletions

View File

@ -22,7 +22,7 @@
#include <bounce/common/math/transform.h>
#include <bounce/common/memory/stack_allocator.h>
#include <bounce/collision/trees/dynamic_tree.h>
#include <bounce/collision/broad_phase.h>
class b3World;
@ -189,8 +189,11 @@ private:
// Soft body triangles
b3SoftBodyTriangle* m_triangles;
// Node tree
b3DynamicTree m_nodeTree;
// Broadphase
b3BroadPhase m_broadPhase;
// Time-step
float32 m_dt;
// Attached world
b3World* m_world;

View File

@ -163,8 +163,8 @@ private:
// Node and body contact
b3NodeBodyContact m_bodyContact;
// Tree identifier
u32 m_treeId;
// Broadphase proxy
u32 m_broadPhaseId;
// Soft body
b3SoftBody* m_body;

View File

@ -463,6 +463,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
m_c_max = def.c_max;
m_gravity.SetZero();
m_world = nullptr;
m_dt = 0.0f;
const b3SoftBodyMesh* m = m_mesh;
@ -489,7 +490,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
b3AABB3 aabb;
aabb.Set(n->m_position, 0.0f);
n->m_treeId = m_nodeTree.InsertNode(aabb, n);
n->m_broadPhaseId = m_broadPhase.CreateProxy(aabb, n);
}
// Compute mass
@ -778,7 +779,7 @@ void b3SoftBody::UpdateContacts()
continue;
}
b3AABB3 aabb = m_nodeTree.GetAABB(n->m_treeId);
b3AABB3 aabb = m_broadPhase.GetAABB(n->m_broadPhaseId);
b3SoftBodyUpdateContactsQueryListener listener;
listener.sphere.vertex = n->m_position;
@ -839,6 +840,8 @@ void b3SoftBody::Step(float32 dt, u32 velocityIterations, u32 positionIterations
{
B3_PROFILE("Soft Body Step");
m_dt = dt;
// Update contacts
UpdateContacts();

View File

@ -39,5 +39,7 @@ void b3SoftBodyNode::Synchronize()
b3AABB3 aabb;
aabb.Set(m_position, m_radius);
m_body->m_nodeTree.UpdateNode(m_treeId, aabb);
b3Vec3 displacement = m_body->m_dt * m_velocity;
m_body->m_broadPhase.MoveProxy(m_broadPhaseId, aabb, displacement);
}