camera question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

camera question

Post by KungFuLu »

Hi,

I wanted to play around a little bit with the camera scenenode and came across a very strange behaviour.
When you look nearly straight up (let's say 85°) and then look straight up, then the camera rolls at 90°. If you then look again nearly straight up, but with let's say 95°, then the camera rolls again at 90° and is, compared with the start situation, flipped.
The code at the end of this post should demonstrate the problem.

I don't know wether it's a bug or if I just do something wrong (although I can't see what).

Thanks in advance,
-Lu

Code: Select all

#include "irrlicht.h"

using namespace irr;

int main()
{
	//setup irrlicht
	IrrlichtDevice* device = createDevice(video::EDT_OPENGL,core::dimension2du(800,600));
	scene::ISceneManager* smgr = device->getSceneManager();
	video::IVideoDriver* driver = device->getVideoDriver();

	//make a moving cube
	scene::ISceneNode* node = smgr->addCubeSceneNode(5,0,-1,core::vector3df(0,100,50));
	scene::ISceneNodeAnimator* anim = smgr->createFlyStraightAnimator(core::vector3df(0,100,50),core::vector3df(0,100,-50),5000,true,true);
	node->addAnimator( anim );
	anim->drop();
	
	//add nodes for orientation
	smgr->addCubeSceneNode(10,0,-1,core::vector3df(50,100,0));
	smgr->addBillboardTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(),L"Start",0,core::dimension2df(20,20),core::vector3df(0,100,60));
	smgr->addBillboardTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(),L"Goal",0,core::dimension2df(20,20),core::vector3df(0,100,-60));

	//add camera
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();

	while( device->run() )
	{
		//let camera follow the cube
		camera->setTarget( node->getPosition() );

		//draw scene
		driver->beginScene(true,true,video::SColor(255,255,0,0));
		smgr->drawAll();
		driver->endScene();
	}

	return 0;
}
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

This is completely normal behaviour
If you take a look at the animator used for the FPS camera provided by irrlicht, you'll see that a maximum view angle is set to prevent this from happening, the default camera however has no such thing
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Post by KungFuLu »

Thanks for your answer Radikalizm.

But is it possible to prevent the camera from behaving like this?
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

Yes it is not only possible, but easy. I had a LOT of trouble with camera transformations when I started out, but I made a class to handle them.
It can be found here:

http://irrlicht.sourceforge.net/phpBB2/ ... 5&start=15

Good luck!
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
KungFuLu
Posts: 27
Joined: Sat May 15, 2010 9:41 pm

Post by KungFuLu »

Thank you very much lazerblade for this camera class.
It helped me a lot understanding how to rotate a camera locally.
lazerblade
Posts: 194
Joined: Thu Mar 18, 2010 3:31 am
Contact:

Post by lazerblade »

That, and if you use the 'Camera::setRotation()' method your fliping problems will go away. ;)
LazerBlade

When your mind is racing, make sure it's not racing in a circle.

3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
Post Reply