[SOLVED] Oh My Camera...

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
Linaxys
Posts: 47
Joined: Tue Feb 24, 2009 10:46 pm

[SOLVED] Oh My Camera...

Post by Linaxys »

Hello,
I would like to make a really customized camera, like a FPS one but without freelook...

I try with addCameraSceneNode, and can someone please tell me how the hell can I seriously get rid off that autorotating to the target function everytime I move forward and stuff please ???

I tried this, it doesn't change anything at all :

Code: Select all

	camera = smgr->addCameraSceneNode();
	camera->setPosition(vector3df(0,10,-30));
	camera->bindTargetAndRotation(false);
And it's looking at 0,0,0 but I want it look forward...

Thanks.
Last edited by Linaxys on Mon Mar 02, 2009 3:45 pm, edited 1 time in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

A camera will always look at its target... That's what the target is for.. If you want it to look somewhere specific you set the target to the specific position to look at...
Image Image Image
Linaxys
Posts: 47
Joined: Tue Feb 24, 2009 10:46 pm

Post by Linaxys »

Ok I got it :

Code: Select all

	// update position
	vector3df pos = cam->getPosition();

	// Update rotation
	vector3df target = (cam->getTarget() - cam->getAbsolutePosition());
	vector3df relativeRotation = target.getHorizontalAngle();

	target.set(0,0, core::max_(1.f, pos.getLength()));
	vector3df movedir = target;

	matrix4 mat;
	mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0));
	mat.transformVect(target);
	movedir = target;

	movedir.normalize();

	target += pos;
	cam->setTarget(target);
But I'd like to rotate the Y axis with the RIGHT and LEFT keys, I do it :

Code: Select all

	if (keyDown[VK_LEFT])
		cam->setRotation(vector3df(cam->getRotation().X,cam->getRotation().Y - 5,cam->getRotation().Z));
	if (keyDown[VK_RIGHT])
		cam->setRotation(vector3df(cam->getRotation().X,cam->getRotation().Y + 5,cam->getRotation().Z));
But nothing happens, maybe the target is locked to it's rotation...
Can someone give me a hint please ?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

the camera's rotation is independent from its target.... setting the rotation effectively has no effect on what the camera sees. That's because you made bindTargetToRotation false, if you make it true then setting the camera's rotation should work.
Image Image Image
Linaxys
Posts: 47
Joined: Tue Feb 24, 2009 10:46 pm

Post by Linaxys »

Thanks a lot, it was that indeed :D
Post Reply