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
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.
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.