I'm doing a tech demo at the moment and I've done a scrolling camera for an isometric view, I am posting the code so other people can see it, hopefully someone may know the answer to my problem. When you scroll around with the camera the whole world rotates slightly, then rotates back when you aren't moving. Oh yeah, and it doesn't scroll 'properly' yet, it's going diagonally but that is an easy fix, I just quickly hacked it yesterday. Here's the code.
Code: Select all
void createCamera()
{
// Create isometric camera as where you would normally
camera = smgr->addCameraSceneNode(0,core::vector3df(7,11.0f,7), core::vector3df(8,0,8));
}
void updateCamera()
{
// Call function inside while(device->run()) loop
irr::core::vector3df camPos;
irr::core::vector3df camTargetPos;
irr::core::position2d<f32> curPos = device->getCursorControl()->getRelativePosition();
camPos = camera->getPosition();
camTargetPos = camera->getTarget();
// Move camera up
if(curPos.X < 0.05f)
{
camera->setTarget(irr::core::vector3df(camTargetPos.X, 0, camTargetPos.Z+0.2f));
camera->setPosition(irr::core::vector3df(camPos.X, 11, camPos.Z+0.2f));
}
// Move camera down
if(curPos.X > 0.95f)
{
camera->setTarget(irr::core::vector3df(camTargetPos.X, 0, camTargetPos.Z-0.2f));
camera->setPosition(irr::core::vector3df(camPos.X, 11, camPos.Z-0.2f));
}
// Move camera left
if(curPos.Y < 0.05f)
{
camera->setTarget(irr::core::vector3df(camTargetPos.X+0.2f, 0, camTargetPos.Z));
camera->setPosition(irr::core::vector3df(camPos.X+0.2f, 11, camPos.Z));
}
// Move camera right
if(curPos.Y > 0.95f)
{
camera->setTarget(irr::core::vector3df(camTargetPos.X-0.2f, 0, camTargetPos.Z));
camera->setPosition(irr::core::vector3df(camPos.X-0.2f, 11, camPos.Z));
}
// Move camera up and left
if (curPos.X < 0.05f && curPos.Y < 0.05f)
{
}
// Move camera up and right
if (curPos.X < 0.05f && curPos.Y > 0.95f)
{
}
// Move camera down and left
if (curPos.X > 0.95f && curPos.Y < 0.05f)
{
}
// Move camera down and right
if (curPos.X > 0.95f && curPos.Y < 0.95f)
{
}
}