Attaching camera to a meshSceneNode

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
Mobeen
Posts: 37
Joined: Sat Mar 25, 2006 9:31 am
Location: Karachi, PAKISTAN

Attaching camera to a meshSceneNode

Post by Mobeen »

I am doing a simplistic game with a spaceship and some asteroids. I want to attach the camera to the spaceship so that when i move the spaceship the camera should move with it. I create the camera scenenode using

Code: Select all

ICameraSceneNode cam* = smgr->addCameraSceneNode();
then I set its position so that it is just above and behind the spaceship. Consider spaceShip to be the scene node of the spaceship,
now when I parent the camera to the spaceship using this
cam->setParent(spaceShip) and i change the position of the spaceship, the camera position remains the same. I have seen the camera's absolute position which is always (0,0,0) whereas the relative position remains the same as was given by cam->setPosition. What am i doing wrong here?
I found a workaround which is to adjust the camera position whenever the spaceship position changes so that it is always having the same offset from its parent i.e the spaceship but then why should i do this when it should have been handled automatically?
Proud to be a PAKISTANI
Watcher
Posts: 40
Joined: Sat Jul 01, 2006 9:44 am
Location: Czech republic

Post by Watcher »

I´m not sure I understand you but if you set a parent for the camera you can imagine than it´s position changes from for example (100, 200, 300) to (ship.X + 100, ship.Y + 200, ship.Z + 300). So if you set cameras position to (0,0,0) you will be in the middle of your ship.
Mobeen
Posts: 37
Joined: Sat Mar 25, 2006 9:31 am
Location: Karachi, PAKISTAN

Post by Mobeen »

Watcher wrote:I´m not sure I understand you but if you set a parent for the camera you can imagine than it´s position changes from for example (100, 200, 300) to (ship.X + 100, ship.Y + 200, ship.Z + 300). So if you set cameras position to (0,0,0) you will be in the middle of your ship.
Yeah thats what should happen but it aint happening
If i am correct isn't cam->setPosition setting cameras' relative position?
I place the ship at (0,0,0). My cam is at position (0, 10,100) for example. I then attach camera to ship. Now when i move the ship to say 0, 100,0 the camera should have its absoluteposition = (0,110,100) right? but when i use cam->getAbsolutePosition it gives me (0,0,0) which is incorrect but getPosition returns (0,10,100) which is ok. Am i doing anything wrong or am missing very basic thing?
Proud to be a PAKISTANI
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Try it the other way around. ;) There is a method called "AddChild()". You'll find it inside your ship node.

Code: Select all

ship->addChild(cam)
And don't forget to set your camera's position to (0,0,0).
Post Reply