3rd Person 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
twentytortures
Posts: 41
Joined: Thu Sep 28, 2006 4:34 am
Location: Eaton, Colorado, United States

3rd Person Camera

Post by twentytortures »

I've been searching the forums for a while and haven't found anything to help.

I'm using Newton with Irrlicht and I made a car. I want to know, how can i mount a camera on top of the car?

I can use this code to move the camera with the car:

Code: Select all

carnode->addChild(camera);
But the camera always wants to look at the origin. How can I make it look at the front of the car?
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

camrea->setTarget();
camrea->setPosition();

I assume. I would do something like the following:

Image

First set your camera as a child, then use camera->setPosition(); to set it some value behind, and above the car. This will put the camera behind the car, although it will still be looking at the origin of the car, so then setTarget() to look at a point the same height as the camera above the car, maybe a little lower.

So for example, if your camera is at (-100,100,0) relative to your car, the target will be (0,100,0), again relative to the car.

Hope you understood, good luck.
twentytortures
Posts: 41
Joined: Thu Sep 28, 2006 4:34 am
Location: Eaton, Colorado, United States

Post by twentytortures »

I've tried that but it still does silly things. I think it's because the camera doesnt rotate when the car turns.

Yeah, the camera travels with the car perfeclty, but it always looks at the origin.
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Post by FreakNigh »

he means that no matter where the parent node goes, if he setTarget(vector3df(0,0,0)) then the camera will move with its parent node correctly, but the cameras target will lookat 0,0,0 of the camera's grandparents node, or the scene node your could say.

... so if the car starts at 0,0,0 but moves to 500,0,0, and the camera was initialy set at 0,100,0 with lookat 0,0,0 and parent of -car-, then at this point the camera will be at 500,100,0 looking at 0,0,0 still.
Archive
Posts: 6
Joined: Tue Nov 14, 2006 8:08 am

Post by Archive »

Ah this can be easily done. Here is the code:

scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(CarNode,core::vector3df(100,100,0), HeliNode->getPosition() );

And in your update loop:
if (device->isWindowActive())
{
.....
camera->setTarget(HeliNode->getPosition());
....
}

Its good to note that a rotation of the car will result in your base co-ordinate system being rotated, so if your car is rotated about the Z axis, your cameras position will be rotated as well. So, if your camera is initially facing the back of your car, it will always appear to be facing the back of your car, even when your car undergoes Z-axis rotation.

This method of course is not useful for space simulators, where your space vehicle will be rotated arbirtrarly along all axises. For space simulators you'll want to use quaternion which do not suffer from gimbal lock.

Of course this is kinda a ghetto fix, and i suspect the camera always referencing the origin is a bug, and will be fixed eventually.
Last edited by Archive on Tue Nov 14, 2006 8:47 am, edited 1 time in total.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The camera looking at a fixed position is not a bug. It is expected behavior. The camera is initialized with a target position, and you can update the target position as you see fit.
Archive
Posts: 6
Joined: Tue Nov 14, 2006 8:08 am

Post by Archive »

You would expect the camera to have its root target position at the root of the parent node, rather than the global root.

If i were to setPosition( vector3df (0,0,0) ), the camera would move to the position of the parent node.

but if i setTarget( vector3df (0,0,0) ), the camera looks at the <0,0,0> position of the global co-ordinate system. It won't look at the parent node position as the setPosition behavior would imply.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I think that's a reasonable complaint. It becomes clearer if you consider a camera inside an area (defined by a parent node), in which case you might expect the behaviour of setTarget() to be the same as setPosition().

However, that behaviour is firmly entrenched, so perhaps we could add a new method, setTargetRelative() or similar. It'd be inconsistent, but at least it'd be available. Perhaps add setTargetRelative() and setTargetAbsolute(), with setTarget() being synonymous with setTargetAbsolute() (and commented as such), to make it clearer that there's two distinct methods.
Archive
Posts: 6
Joined: Tue Nov 14, 2006 8:08 am

Post by Archive »

Perhaps a new camera class should be developed such that its position always reflected the coordinate system of its parent.

So when the parent node changes its position or rotation, the camera's position, rotation, and target are automatically recalculated in the parent nodes co-ordinate system.

I've noticed under rotation of an node, the camera will only follow the pitch and yaw of the parent node. It will always stay parallel to the horizon, indicating its Roll never changes. This is good for FPS, but bad for flight simulators.

Perhaps call the new camera node type something like:

class ICameraNodeRelative

This would also get around the problem of gimbal lock.

http://en.wikipedia.org/wiki/Gimbal_lock
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

You have to setTaget in absolute world.

As you know the absolute transformation of the parent node, you just have to transform your relative target position into the absolute target position. It's just a few lines of code !

No need to develop anything. Irrlicht already provides every class you need.

Xter.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Post Reply