time lag between collision model and graphic model

anear

11-01-2007 15:55:22

I come across a problem when moving my project from NxOgre.0.5.preview.3 to NxOgre.0.4RC2. In my project I link a kinematic body to a sensor of a motion tracking system. Now there is a big time lag between the physX model and the graphic model. When I press "F2", I can see that the physX model follows the sensor movement (in the real world) just right, but the graphic model stays in an old position for a while before jumping to the physX model.

The project worked fine in NxOgre.0.5.preview.3. I notice that there are some changes in tutorialApplication.h and tutorialApplicationDragon.h on frameStarted(). Could this a problem to cause the lag?

To simplise the problem, I change Lesson101 to the following code

#include "nxOgre.h"
#include "Ogre.h"
#include "tutorialApplication.h"
#include "MS.h" // interface to the motion tracking system

using namespace nxOgre;
using namespace Ogre;

class NxTutorial : public SimpleTutorial
{
public:
world *mWorld;
scene *mScene;
body *myBody;

MotionStar sensor;
double* positions; // MotionStar variables
Vector3 oldPos, newPos, currentPos, oldOri, newOri, rotation;
Quaternion q;

void start() {
mWorld = new world(mRoot);
mScene = mWorld->createScene("myScene", mSceneMgr);
mScene->hasGravity();
mScene->hasFloor();

myBody = mScene->createBody("myCube", "cube.1m.mesh", // Mesh to use
new cubeShape(1.0f), // Collision Model to use
10.0f, // Density of the body (In Kilograms)
Vector3(0,5,0) // Where to put it. (In Metres)
);
myBody->setKinematic(true);
}

void stop() {
delete mWorld;
}

//update the kinematic cube's position and orientation in every frame
void newFrame(float _time)
{
positions = sensor.get();
if ((oldPos.x-0.0f < 0.0001) && (oldPos.y-5.0f < 0.0001) && (oldPos.z-0.0f < 0.0001)) // first frame
oldPos = Vector3(positions[1], positions[2], positions[0]);
else
{
newPos = Vector3(positions[1], positions[2], positions[0]);
currentPos[0] += (newPos[0]-oldPos[0]);//*(mMove/10)
currentPos[1] += (oldPos[1]-newPos[1]);
currentPos[2] += (oldPos[2]-newPos[2]);

mCaption1->setCaption(Ogre::StringConverter::toString(currentPos));
myBody->setGlobalPosition(currentPos);
oldPos = newPos;

Quaternion qy(Radian(positions[3]-oldOri.x), Vector3::UNIT_Y);
Quaternion qx(Radian(positions[4]-oldOri.y), Vector3::UNIT_X);
Quaternion qz(Radian(positions[5]-oldOri.z), Vector3::UNIT_Z);
q = qy * qx * qz;
myBody->setGlobalOrientation(myBody->getGlobalOrientation() * q);
oldOri = Vector3(positions[3], positions[4], positions[5]);
}
return;
}

void getTutorialSettings() {
mTutorialName = "101";
mTutorialDescription = "Linked Cube";
mMouseMode = CAMERA_CONTROL;
}

void prestart()
{
mCaption3->setCaption("Move the sensor to control the cube.");

positions = sensor.get();
oldPos = Vector3(positions[1], positions[2], positions[0]);
oldOri = Vector3(positions[3], positions[4], positions[5]);
currentPos[0] = 0.0f;
currentPos[1] = 5.0f;
currentPos[2] = 0.0f;
}


Here's a sceenshot that shows the delay of the graphic model, where the physX model is already at the new position whereas the graphic model is still at the old position.


Betajaen says: Right Click and Show image to see the image..Google is being funny.
Any idea? Thanks a lot.

betajaen

11-01-2007 16:08:46

That is significant lag there, much more than I've experienced.

The only change that would effect that is, that the render (updating Ogre) is performed at the end of a frame instead of at the beginning. Perhaps modifying nxOgre_world.cpp, and move the contents of the frameEnded to the end of the frameStarted may help it a little.

It is a timing issue though, most likely a frameListener.

anear

11-01-2007 17:15:00

But why in the previous NxOgre, the lag is barely noticable?

There's no frameEnded() in the nxOgre_world.cpp.

It is a timing issue though, most likely a frameListener.
What shall I do to the frameListner to reduce the lag?

Does the variable speed [0,4] has something to do with the issue?

Here's another problem:

I tried to roll back to NxOgre0.5.preview.3, but found that its output doesn't display on my HMD (only shown on monitor). The simulation on NxOgre.0.4.RC2 can display on both HMD and monitor.

Probably because the new tutorials NxOgre.0.4.RC2 on are not full-screen mode? How can I change my program on NxOgre.0.5.preview.3 to make it non-full-screen mode?

betajaen

11-01-2007 17:43:26

Ah, the frameEnded is only in RC3.

Edit the config.yaml file in the tutorial directory, change "fullscreen:No" to "fullscreen:Yes".

jchmack

16-01-2007 20:21:03

Im having this same issue. I haven't changed a thing in my code from RC2.