camera direction

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
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

camera direction

Post by JBGame »

Hi,

Is there a way to get which direction the camera is facing?
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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;
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

Post 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/
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Post 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).
Working on game: Marrbles (Currently stopped).
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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())
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

Post by JBGame »

Hi,

Thanks guys, it works perfectly :D
Post Reply