Page 1 of 1

[SOLVED] Oh My Camera...

Posted: Mon Mar 02, 2009 9:57 am
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.

Posted: Mon Mar 02, 2009 9:59 am
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...

Posted: Mon Mar 02, 2009 10:53 am
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 ?

Posted: Mon Mar 02, 2009 11:31 am
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.

Posted: Mon Mar 02, 2009 3:45 pm
by Linaxys
Thanks a lot, it was that indeed :D