Page 1 of 1

camera direction

Posted: Tue Sep 28, 2010 12:31 pm
by JBGame
Hi,

Is there a way to get which direction the camera is facing?

Posted: Tue Sep 28, 2010 12:35 pm
by Luben
I think this should work

Code: Select all

ICameraSceneNode *pCamera = pSceneManager->getActiveCamera();
vector3df pos = pCamera->getAbsolutePosition();
vector3df target = pCamera->getTarget();
vector3df dir = target - pos;

Posted: Tue Sep 28, 2010 12:50 pm
by JBGame
Hi,

i'm trying to create a cube that's always in the middle of the screen and away from the camera.

I tried your method:

Code: Select all

	 pCamera = smgr->getActiveCamera();
	 pos = pCamera->getAbsolutePosition();
	 target = pCamera->getTarget();
	 dir = target - pos;

	 node->setPosition(dir);
i think i'm doing it wrong because it's not working as expected.. sorry i'm still learning :S/

Posted: Tue Sep 28, 2010 1:07 pm
by serengeor
maybe

Code: Select all

node->setPosition(dir*100); 
Just a guess tough, you could also make camera orbit around It.(code snippets section to the rescue).

Posted: Tue Sep 28, 2010 1:20 pm
by Luben
If you want the node to follow the camera around on a fixed distance, do

Code: Select all

node->setPosition(pos + dir.normalize() * distance);
dir by itself is just a vector representing the direction from the camera towards where it looks. We normalize it (make its length = 1) then makes it distance long, and we add the position where the camera is.

If you just want the camera to focus on the node, do

Code: Select all

pCamera->setTarget(node->getAbsolutePosition())

Posted: Wed Sep 29, 2010 12:55 am
by JBGame
Hi,

Thanks guys, it works perfectly :D