what is the easiest to do a 3th person camera ?

Started by
6 comments, last by Bezben 18 years, 4 months ago
Yes, like a tomb raider ?! can i do it with translate3f()-function
"I'm a programmer honey, but you can't beat me" Loaning from the Hurriganes - Roadrunner
Advertisement
you must use quaternions for such a 3'rd person camera. there are a lot of tutorials about this here on gamedev and gamasutra. just search!
meeshoo:

damn, i love it!

"you must use quaternions."

wow, i've never used quaternions, but i've written a bunch of games with 3rd-person cameras.

if you think about it hard enough, you can do it all with nothing more than simple high school math.

although yes, there's a fairly nice article in the reference section.. **with code**

-chris
die or be died...i think
You could use a quaternion camera, but it's not necessary unless you want to be able to yaw, pitch, and roll. Unless you're writing a flight simulator (or something similar) you should only need to yaw and pitch, so euler angles will work fine.
Atari 2600 Homebrew Author - Someone who is smart enough to learn 6502 assembly language but dumb enough to actually want to use it.
And even then they aren't needed. They might be nice to save memory or interpolate rotations, but computer graphics, games and flight simulators have been around long before everybody and his dog was caught by the quaternion craze. I wonder if someday people will say "you must use pluecker coordinates" when somebody asks for an intersection test, just because they are so neat for it.
f@dzhttp://festini.device-zero.de
first: sorry i've been so lazy writing more.
second: euler = gimbal lock
third: quaternions with their spherical interpolation tehniques give you smooth rotations with simpler code. Of course you can make the camera with classic techniques, but the topic creator asked for a tomb raider camera style, and the one from tomb raider was created using quaternions.
One have to locate the camera a distance behind a reference point, e.g. located a little bit above the head of the avatar. Also the camera in general has to look into the direction the avatar looks.

To reach this there are two ways (and some variations):

(1) In the model local co-ordinate frame of the avatar's head the camera is aligned in the standard viewing direction (e.g. along the principal -z axis), and located a distance against the standard viewing direction (e.g. at [0,0,-10]^T). Then the camera is transformed as the local co-ordinate frame prescribes to yield the camera in global co-ordinates.

(2) The orientation (say rotation matrix) of the model local co-ordinate frame w.r.t. the global frame of the avatar's head is copied (probably with some adaptions) to the camera, so that the camera's line of view is the same as those of the avatar. Then the camera is translated to the aforementioned reference point above the avatar's head, and at least translated by e.g. -10 length units along the z column vector of the orientation matrix (which in the example denotes the viewing direction).

So in principle glTanslate and glRotate are to be used (or else direct matrix math), since both orientation as well as position are to be adapted.

But one has to be aware of a variable distance. As the mentioned example of Lara shows, the environmental geometry may prohibit a fixed distance to go behind the avatar.

Whether or not to use quaternions does not play a direct role. Looking at the principles above one could see that the camera's orientation could be more or less directly derived from the avatar's head orientation. IMHO quaternions have an overall advantage in comparison to euler angles (I personally use quaternions). However, gimbal lock need not play a role in the given application. E.g. if the head could not be rolled and could not be pitched more than, say, +/- 70 degree.

EDIT: You need to have a properly controlled avatar, of course.


Here an article "A Simple Quaternion-based Camera" could be found:
http://www.gamedev.net/reference/articles/article1997.asp

Also Gamasutra.com provides an article about that stuff:
http://www.gamasutra.com/features/19980703/quaternions_01.htm

@meeshoo: Right you are; Tomb Raider was made w/ quaternion cam (see e.g. Gamasutra article).
You can use

gluLookAt( Pos->x, Pos->y, Pos->z,
LookAt->x, LookAt->y, LookAt->z,
Up->x, Up->y, Up->z );

To make a matrix defined by a position (for the camera), a look at point (for the player) and up. Then you just need to decide how to move the camera relative to the player. Easiest option is to have it just behind and just move the camera point when you move the player.

This topic is closed to new replies.

Advertisement