I can't seem to get it.
Here is the situation.
My game loop looks like this:
UpdateLocalTransforms();UpdateGlobalTransforms();UpdatePhysX();RenderStuff();
Inside of UpdatePhysX() right now i'm just moving PhysX actors based on global positions of my graphic objects. Looks like this:
for(PhysicalBody *body = static_cast<PhysicalBody*>(bodyList.First()); body; body = body->Next()) { NxMat34 matrix(false); matrix.setColumnMajor44(body->bodyNode->GetWorldTransform().Get()); body->bodyActor->moveGlobalPose(matrix); } currentScene->simulate(TheTimeMgr->GetFloatDeltaTime() * PHYSX_TIMESTEP_SCALE); currentScene->flushStream(); currentScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
To simplify things, all actors (actually there is just one actor) are kinematic.
Inside RenderStuff() i render all objects based on their global transforms and also render debug info from PhysX.
But when launched, i clearly see my actor lagin behind by one (subjective of course) frame. Like it's taking previous transforms or render in previous transforms. After using different loggings i found that transforms i pass to my actors are exactly same as those that are calculated previously. In other words, all graphic objects are syncronized with physical objects.
Example.
I create a graphic object as a capsule and an actor with a capsule shape. Now i just move my graphic object and then pass resulted transforms to an actor (physical object). After that i render graphic object separately and actor (debug render) separately (not combining them now). Clearly seeing the lag. But all debug stuff (logging to a file, using Visual Studio debugger, etc.) show same transforms (in this case just a simple X coordinate, because i change only it).
What can be the problem?
P.S.
PhysX scene is created with 0 flags set (i.e. no multithreading) and using fixed timestep method.
Changed to using fixed time step like in docs (replaced my GetFloatDeltaTime() with a fixed number), but it didn't help.
Tried to move my actors updating after fetchResults() and before - no difference.