I think I have to be a new function, is what UpdateCollisionMatrix does.
- Code: Select all
void ndBodyKinematic::UpdateCollisionMatrix()
{
m_transformIsDirty = 1;
m_shapeInstance.SetGlobalMatrix(m_shapeInstance.GetLocalMatrix() * m_matrix);
m_shapeInstance.CalculateAabb(m_shapeInstance.GetGlobalMatrix(), m_minAabb, m_maxAabb);
}
as you can see it does update the collision shape global matrix and aabb, however that is no enught to guarantee collision.
in the game that function is called during the collision update from here.
- Code: Select all
void ndScene::UpdateAabb(ndInt32, ndBodyKinematic* const body)
{
ndSceneBodyNode* const bodyNode = body->GetSceneBodyNode();
body->UpdateCollisionMatrix();
dAssert(!bodyNode->GetLeft());
dAssert(!bodyNode->GetRight());
dAssert(!body->GetCollisionShape().GetShape()->GetAsShapeNull());
const ndInt32 test = dBoxInclusionTest(body->m_minAabb, body->m_maxAabb, bodyNode->m_minBox, bodyNode->m_maxBox);
if (!test)
{
bodyNode->SetAabb(body->m_minAabb, body->m_maxAabb);
if (!m_rootNode->GetAsSceneBodyNode())
....
this is so that during update collision the broad phase is only update once per call, if we do it in reverse order, meaning set the broad phase each time set matrix is call, them it will requires lot of synchronization, and also it could be expensive.
and since update collision shape does not update the bradphase, we need a new SetMatrix function
one that call SetMatrix, the calls void ndScene::UpdateAabb(ndInt32, ndBodyKinematic* const body)
so that is take case of the scene update.
I added like this
D_COLLISION_API void SetMatrixUpdateScene(const ndMatrix& matrix);
please try it out.