Put nodes in a broadphase to reduce tree updates
This commit is contained in:
parent
a3a9495d88
commit
11724ef5e3
@ -22,7 +22,7 @@
|
|||||||
#include <bounce/common/math/transform.h>
|
#include <bounce/common/math/transform.h>
|
||||||
#include <bounce/common/memory/stack_allocator.h>
|
#include <bounce/common/memory/stack_allocator.h>
|
||||||
|
|
||||||
#include <bounce/collision/trees/dynamic_tree.h>
|
#include <bounce/collision/broad_phase.h>
|
||||||
|
|
||||||
class b3World;
|
class b3World;
|
||||||
|
|
||||||
@ -189,8 +189,11 @@ private:
|
|||||||
// Soft body triangles
|
// Soft body triangles
|
||||||
b3SoftBodyTriangle* m_triangles;
|
b3SoftBodyTriangle* m_triangles;
|
||||||
|
|
||||||
// Node tree
|
// Broadphase
|
||||||
b3DynamicTree m_nodeTree;
|
b3BroadPhase m_broadPhase;
|
||||||
|
|
||||||
|
// Time-step
|
||||||
|
float32 m_dt;
|
||||||
|
|
||||||
// Attached world
|
// Attached world
|
||||||
b3World* m_world;
|
b3World* m_world;
|
||||||
|
@ -163,8 +163,8 @@ private:
|
|||||||
// Node and body contact
|
// Node and body contact
|
||||||
b3NodeBodyContact m_bodyContact;
|
b3NodeBodyContact m_bodyContact;
|
||||||
|
|
||||||
// Tree identifier
|
// Broadphase proxy
|
||||||
u32 m_treeId;
|
u32 m_broadPhaseId;
|
||||||
|
|
||||||
// Soft body
|
// Soft body
|
||||||
b3SoftBody* m_body;
|
b3SoftBody* m_body;
|
||||||
|
@ -463,6 +463,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
|
|||||||
m_c_max = def.c_max;
|
m_c_max = def.c_max;
|
||||||
m_gravity.SetZero();
|
m_gravity.SetZero();
|
||||||
m_world = nullptr;
|
m_world = nullptr;
|
||||||
|
m_dt = 0.0f;
|
||||||
|
|
||||||
const b3SoftBodyMesh* m = m_mesh;
|
const b3SoftBodyMesh* m = m_mesh;
|
||||||
|
|
||||||
@ -489,7 +490,7 @@ b3SoftBody::b3SoftBody(const b3SoftBodyDef& def)
|
|||||||
b3AABB3 aabb;
|
b3AABB3 aabb;
|
||||||
aabb.Set(n->m_position, 0.0f);
|
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
|
// Compute mass
|
||||||
@ -778,7 +779,7 @@ void b3SoftBody::UpdateContacts()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
b3AABB3 aabb = m_nodeTree.GetAABB(n->m_treeId);
|
b3AABB3 aabb = m_broadPhase.GetAABB(n->m_broadPhaseId);
|
||||||
|
|
||||||
b3SoftBodyUpdateContactsQueryListener listener;
|
b3SoftBodyUpdateContactsQueryListener listener;
|
||||||
listener.sphere.vertex = n->m_position;
|
listener.sphere.vertex = n->m_position;
|
||||||
@ -839,6 +840,8 @@ void b3SoftBody::Step(float32 dt, u32 velocityIterations, u32 positionIterations
|
|||||||
{
|
{
|
||||||
B3_PROFILE("Soft Body Step");
|
B3_PROFILE("Soft Body Step");
|
||||||
|
|
||||||
|
m_dt = dt;
|
||||||
|
|
||||||
// Update contacts
|
// Update contacts
|
||||||
UpdateContacts();
|
UpdateContacts();
|
||||||
|
|
||||||
|
@ -39,5 +39,7 @@ void b3SoftBodyNode::Synchronize()
|
|||||||
b3AABB3 aabb;
|
b3AABB3 aabb;
|
||||||
aabb.Set(m_position, m_radius);
|
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);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user