apologies, I'll try and be a bit more explicit.
The jump occurs when I Alt-Tab back and forth between the window, and likewise when I minimise and then maximise. Both have the same effect as far as I'm aware.
My main rendering loop looks like...
Code: Select all
while(device->run())
{
//render only when window active
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,200,200,200));
if(robotActive)
robot->process(); //move robot around in the world
smgr->drawAll();
driver->endScene();
}
//if window inactive, but robot active, process as usual
else if(robotActive)
robot->process(); //move robot around in the world
// otherwise sleep to free up CPU cycles
else
Sleep(30);
}
the robotActive is a trigger so I can turn the robots movement routine on and off.
the function robot->process() makes calls to the scene manager, collision manager and driver to get information about the world i.e. distance from nearest wall. It then moves the robot in one of 3 ways, described by the function doAction(int a)
(by the way RobotClass is derived from the SceneNode class in the same way as descibed in the tutorial for Custom SceneNodes)
Code: Select all
void RobotClass::doAction(int a)
{
// STEP 1: rotate robot about axis
core::vector3df rot = this->getRotation();
switch(a) {
case 0: //do nothing
break;
case 1: //rotate left 15 degrees
rot.Y-=15;
this->setRotation(rot);
break;
case 2: //rotate right 15 degrees
rot.Y+=15;
this->setRotation(rot);
break;
}
//STEP 2: move robot forward by 2 points
core::vector3df pos(sqrt(2.0),0,sqrt(2.0)); //XZ vector length of 2
core::matrix4 mat;
mat.setRotationDegrees(this->getRotation());
mat.transformVect(pos); //pos now faces the direction of the robot
pos+=this->getPosition();
this->setPosition(pos); //move avatar to pos
this->updateAbsolutePosition(); //is this necessary?
}
I don't know if its relevant, but I overloaded the render() function to draw 2 lines showing the robots field of view
Code: Select all
void RobotClass::render()
{
robotModel->render(); //robotModel is a child animated scenenode, that represents the robot in the world.
//draw field of view lines
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->draw3DLine(getAbsolutePosition(),leftLine,video::SColor(0,255,0,0));
driver->draw3DLine(getAbsolutePosition(),rightLine,video::SColor(0,255,0,0));
}
Hope that makes things a bit clearer.
Basically so long as the window is active the robot moves fine. Obviously I can't tell if it's working okay when the window is minimised, but as soon as I alt-tab back to look, the robot jumps!
I think this is to do with the absoluteTransformation matrix not being updated/set correctly outside my rendering loop, but I can't pin-point the problem!
Thanks in advance - this has really got me stumped!
