How to use 3rd Person Camera

A forum to store posts deemed exceptionally wise and useful
Post Reply
Even

How to use 3rd Person Camera

Post by Even »

send 3rd Person Camera project for me please. Email- crazy_xmu@hotmail.com thank... :D
Pazystamo
Posts: 115
Joined: Sat Dec 03, 2005 5:56 pm
Location: Lithuania
Contact:

Post by Pazystamo »

Here you have to post code, for asking it you have to write in beginers forum...And first use search.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

http://irrlicht.sourceforge.net/phpBB2/ ... php?t=7977

Link above will get you to topic about easy & great 3rd person camera.

Yeah as Even said in future search a bit longer ;)

Good luck :D
Guest

Post by Guest »

Judging from some reactions this question seems to come up quite a lot. The first thing I did was attach the camera node to some objects node, expecting that this should be pretty much it. But instead the camera obviously ignored the parents orientation. It seemed to care about nothing but target, up vector and position which made it just completely inconsistent. If nodes can be attached, then one should expect "correct" behaviour (read: all parents transformations are considered).

So I changed the camera code, setTarget and setUpVector now actually update the nodes orientation. Target and UpVector are still there, but only so it won't break the derived Maya and FPS cameras. Also, the view matrix is now built based on the absolute transformation. Doing somenode->addChild(cameranode) will now result in what I would consider "correct" behaviour (some might disagree, somebody always does). If you need a typical 3rd person camera, create a camera that is translated back a little, attach it to some node and that's it.

While I was at it and noticed that applying typical transformations to nodes was a major pita due to Euler Angle conversion and no existing functions I could see I also added two functions to the scene node.

rotate: takes angle in degree and an axis to rotate around. Also 2 bools, specifying local or global coord system (where "global" means "parent", if one exists) and rotation around own position or parents position.

translate: takes a vector for the translation and a bool for local or "global" coords. Rather straight forward.

What's that good for? Some examples:

You have a 3rd person cam as above, but want it to orbit the object. That's exactly what the last parameter means:
camera->rotate(45, vector3df(0,1,0), false, true);

will make the camera rotate around the objects "up" axis and its position. I placed that in the scene node because it might be useful to have objects orbit each others.

How would you do a fps style camera? Almost the same. It obviously doesn't have a parent and you want to rotate around the local x, but the global y. So as reaction to mouse movement you would call:
camera->rotate(degreeFromMouseY, vector3df(1,0,0));
camera->rotate(degreeFromMouseX, vector3df(0,1,0), false);

while movement (for the cam just like for anything else) would be:
camera->translate(vector3df(0,0, +-forward_speed));
camera->translate(vector3df(+-strafe_speed,0,0));
(except for outside influences there usually isn't much use for the global version)

I decided against adding rotateX/Y/Z functions, though the matrix class now has a buildAxisRotationMatrix(f32 angleInRad, vector3df axis) function to fill the current matrix (translation will be wiped), as well as buildRotationX<Y,Z>Matrix(f32 angleInRad). The latter are somewhat redundant (and untested), as you could just as well use the function to build them from Euler Angles, but generally I would expect that to either do a lot of useless work (ie. covers a generic case) or have a good number of ifs ("how do you want to kill your instruction cache today?", though if you start building a gazillion rotation matrices per frame something must be wrong anyway).

The changed source files and Win32 binaries are here:
http://festini.device-zero.de/irrchange.zip

I'd suggest compiling the engine yourself if you want to add these functions, as I already "cleaned" up my version by removing all the D3D and software renderer stuff (just in case you wonder why the dll is only 668kb). If you don't feel like compiling the engine and want to stick with D3D it shouldn't be hard to use the new functions and add them as additional files
Post Reply