0
\$\begingroup\$

In my project I have simple scene graph to render whole scene and Bullet physics SDK to provide physics simulation.

Each rendered object is represented as scene node. Camera always has target and located behind this target. Target can be any scene node.

First, I want to describe my rendering pipeline.

1)When time to render whole scene, we calculate view matrix from target's world matrix. We take offset vector in order to locate camera behind targeted scene node and transform it to scene node world's coordinate. Then add position of target with transformed offset vector. Finally, get inverse matrix of scene node. This method always is called before rendering whole scene.

HRESULT CameraNode::SetViewTransform(Scene *pScene)
{
    //If there is a target, make sure the camera is
    //rigidly attached right behind the target
    if(m_pTarget)
    {
        Mat4x4 mat = m_pTarget->VGet()->ToWorld();
        Vec4 at = m_CamOffsetVector;
        Vec4 atWorld = mat.Xform(at);
        Vec3 pos = mat.GetPosition() + Vec3(at);
        mat.SetPosition(pos); 
        VSetTransform(&mat); // Set normal matrix and calculate inverse matrix
    }
    m_View = VGet()->FromWorld(); // Get inversed matrix
    pScene->GetRenderer()->VSetViewTransform(&m_View);
    return S_OK;
}

2)Then, when time to render particular scene node, we calculate projection matrix and send it to the vertex shader.

Mat4x4 CameraNode::GetWorldViewProjection(Scene *pScene)
{ 
     Mat4x4 world = pScene->GetTopMatrix();
     Mat4x4 view = VGet()->FromWorld();
     Mat4x4 worldView = world * view;
     return m_Projection * worldView;
}

I have next problem, when I calculate view matrix from target's world matrix and locate target on coordinate ( x = 0; y = 10; z = 1) it started to fall due to physics and jerk/twitch. [1]

When I set view/camera matrix only offset position. Scene node falls without jerking/twitching. [2]

How I can fix this jerking/twitching when camera is following the scene node ?

I suppose that it is problem of matrices multiplication, when Bullet SDK sets new coordinates to scene node. But I have no idea how it can be solved.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I found that, physics system was late with matrix synchronization. In the result, scene node wasn't updated on time with the desired matrix. When I got new projection matrix for rendering, world matrix had updated matrix, but view matrix was calculated with old matrix.

I realized that GLM library good accuracy in this respect, as for this, because DirectX matrix to round this error.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .