Camera following airplane

Recommended Posts

Currently, I am drawing a plane model to the screen and then using lookAt to position the camera behind the plane at a constant distance and angle.

This works fine, but I don't like this constant following behavior when the plane pitches, yaws, or rotates because it just seems unnatural.

I'd rather have the camera act more like the cameras I've seen in other flight games such as Wings of Prey. When the plane pitches in this game, the camera doesn't pitch quite as much, so you see the plane from a different angle. It's obvious to the user that the plane is changing orientation.

Is there a name for such a camera implementation? I've scoured the internet to no avail. If someone can send me in the right direction, that would be great. thanks.

Share on other sites
DefCom    270
Hi,
I have just done this today.
I have used quaternions to perform the rotation and the Lerp (linear interpolation) to move the camera.

My code is a bit messy at the mo'

it takes the quat of the camera and plane along with a float that delays it a bit.

I used reimmers xna flight sim tutorial and googles quaternion lerp c++

This is my mixture of the above
Quaternion NLerp(Quaternion tQ1, Quaternion tQ2, float w2){	float w1 = 1.0f - w2;	Quaternion tQ3;	tQ1.w*=w1;	tQ1.x*=w1;	tQ1.y*=w1;	tQ1.z*=w1;	tQ2.w*=w2;	tQ2.x*=w2;	tQ2.y*=w2;	tQ2.z*=w2;	tQ3.w=tQ1.w + tQ2.w;	tQ3.x=tQ1.x + tQ2.x;	tQ3.y=tQ1.y + tQ2.y;	tQ3.z=tQ1.z + tQ2.z;	//normalise	float TOLERANCE = 0.00001f;	// Don't normalize if we don't have to	float mag2 = tQ3.w * tQ3.w + tQ3.x * tQ3.x + tQ3.y * tQ3.y + tQ3.z * tQ3.z;	if (  mag2!=0.f && (fabs(mag2 - 1.0f) > TOLERANCE)) {		float mag = sqrt(mag2);		tQ3.w /= mag;		tQ3.x /= mag;		tQ3.y /= mag;		tQ3.z /= mag;	}	return tQ3;}

Share on other sites
so, to clarify. The two parameters are the plane and camera rotations stored as a quaternion, and then w is some sort of factor to interpolate by?

I'll definitely read into lerp-ing quaternions. Currently my camera(and subclass plane) uses quaternions to rotate, but the entire rotation isn't stored as a quaternion, but rather a heading, up, and pos vector. I use quaternion rotations to rotate these around, so I'll probably end up just storing the overall rotation in a quaternion to make this lerp-ing easier.

Share on other sites
DefCom    270
yeah, this isnt really my strong point, but i have spent the past 3 weeks over this aspect of my game.

I have yaw, pitch and roll, which are converted to the plane rotation quaternion.
I then have a camera quaternion which is generated by the above function.

The return is the new camera quat'

It took me such a long time to do and get working i plan to try and write it up for others to use.

I am currently trying to get a propellor to spin on it's axis and rotate around the plane... it's proving tricky.

Share on other sites
skytiger    294
I limit the camera to the hemisphere above the aircraft (because people need a ground reference otherwise they feel sick)

the camera is positioned in an averaged location behind the aircraft
but looks at a point on the aircrafts velocity vector

this means sideslipping is well communicated to the user - for instance when landing you can see the reference point and the side of the aircraft

the faster it goes - the further forward the camera looks

by clamping the position using an exponential you get a nice organic feeling
plus you can still feel strong forces - there is a slight movement

the camera up vector is: normalize(aircraft.up * float3(1, 4, 1))
so the camera will roll to follow the aircraft, but not as much

if the aircraft goes into a dive the camera tilts downwards and follows it - giving a great sensation of loss of height

if the aircraft climbs the camera stays roughly behind it - hopefully giving you a sense of climbing through ground reference and watching clouds moving downwards

and things like loop the loop are pretty stunning - as the aircraft raises its nose you end up looking down the aircraft Y axis and can see the pilot

as the velocity vector changes direction the camera smoothly sweeps round
and then plunges down to follow the aircraft out of the loop

I also noticed that no flight sims seem to correctly model the way a pilot's head moves in relation to the aircraft (for first person views) so I've been working on that also ...

the first person view in apache air assault (old version) was pretty good though

Share on other sites
Thanks for the suggestions here. A lot of valuable information.

I went ahead and implemented the camera trailing with quaternions and SLERP.
I used SLERP because it was already supported by the math library i'm using. (http://mgarland.org/files/dist/libgfx-1.1.0-doc/index.html).

This mostly works besides one little buggy issue I don't quite understand.
When the camera yaws, rotates, or pitches there is a specific angle for each of these rotations where the camera acts very strangely and it appears that it is basically flipping around the plane until it returns to a normal position. Every time the plane rotates through these angles, that happens. Any ideas as to why this could be happening? Is this a side effect of SLERP?

Share on other sites
Quote:
 Original post by MantisTobaganMDThanks for the suggestions here. A lot of valuable information.I went ahead and implemented the camera trailing with quaternions and SLERP. I used SLERP because it was already supported by the math library i'm using. (http://mgarland.org/files/dist/libgfx-1.1.0-doc/index.html).This mostly works besides one little buggy issue I don't quite understand. When the camera yaws, rotates, or pitches there is a specific angle for each of these rotations where the camera acts very strangely and it appears that it is basically flipping around the plane until it returns to a normal position. Every time the plane rotates through these angles, that happens. Any ideas as to why this could be happening? Is this a side effect of SLERP?

http://www.gamedev.net/community/forums/topic.asp?topic_id=587434