Isometric scrolling camera

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Isometric scrolling camera

Post by Tyn »

Hey all

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)
	{

	}
}
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

It works now, if a little jerky. The twisting effect on the camera is decreased a bit now so it isn't too annoying but a solution would be nice. The only thing that is altered is the updateCamera() function so here it is:

Code: Select all

	// Move camera Left
	if(curPos.X == 0)
	{
		camera->setTarget(irr::core::vector3df(camTargetPos.X-0.2f, 0, camTargetPos.Z+0.2f));
		camera->setPosition(irr::core::vector3df(camPos.X-0.2f, 11, camPos.Z+0.2f));
		
	}
	// Move camera Right
	if(curPos.X > 0.99f)
	{
		camera->setTarget(irr::core::vector3df(camTargetPos.X+0.2f, 0, camTargetPos.Z-0.2f));
		camera->setPosition(irr::core::vector3df(camPos.X+0.2f, 11, camPos.Z-0.2f));
		
	}
	// Move camera up
	if(curPos.Y == 0)
	{
		camera->setTarget(irr::core::vector3df(camTargetPos.X+0.2f, 0, camTargetPos.Z+0.2f));
		camera->setPosition(irr::core::vector3df(camPos.X+0.2f, 11, camPos.Z+0.2f));
		
	}
	// Move camera Down
	if(curPos.Y > 0.99f)

	{
		camera->setTarget(irr::core::vector3df(camTargetPos.X-0.2f, 0, camTargetPos.Z-0.2f));
		camera->setPosition(irr::core::vector3df(camPos.X-0.2f, 11, camPos.Z-0.2f));
	}
Post Reply