How can I make the camera return to the beginning of the terrain when it reaches the end?
- by wbaccari
How can I make the camera return to the beginning of the terrain when it reaches the end?
I tried using the ICameraSceneNode*-setPosition().
if (camera->getPosition().X>1200.f)
camera->setPosition(vector3df(1.f,1550.f,camera->getPosition().Z));
if (camera->getPosition().X<0.f)
camera->setPosition(vector3df(1199.f,1550.f,camera->getPosition().Z));
if (camera->getPosition().Z>1200.f)
camera->setPosition(vector3df(camera->getPosition().X,1550.f,1.f));
if (camera->getPosition().Z<0.f)
camera->setPosition(vector3df(camera->getPosition().X,1550.f,1199.f));
It seems to work fine with a flat terrain (one shade of grey in heightmap) but it starts to produce a strange behavior as soon as i try to add some hills.
Edit: The setPosition() call seems to perform a translation of the camera toward the new position, therefore the camera stops at the first obstacle it encounters on its way.