Jump to content
  • Advertisement
Sign in to follow this  
barret232hxc

Camera class for arcade style flight sim

This topic is 4219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right now I'm currently in the early development stages of a 4 man team project making an arcade style flight sim. The objective of the game is doing tricks and flying through rings so the camera needs to follow the plane and be able to follow while the plane is going upside down for loops and such. I have done some research and found several Quaternion-based camera classes posted on the web. I was wondering if anyone has any experience with anything similar to this and if Quaternions are indeed the way to go or if matrix's are a feasible solution. I appreciate anyone who can offer me any insight. Just to let you know, we are using directx 9 with the latest sdk and using c++. feel free to contact me via email : Janitor30@hotmail.com or via aim sn : barret232hxc Thanks for your time, Barret

Share this post


Link to post
Share on other sites
Advertisement
I personally use matrices as they are more familiar to me and I use OpenGL rather than DirectX, so I feel that matrices offer a speed benefit because I pass the matrix straight to OpenGL without having to do any conversion. (I am open to being proven wrong on that, of course).

Nearly every book I have on 3D programming mentions quaternions but never go into much detail so it seems to be one of those things you're expected to accept without too much explanation. Some people will tell you that quaternions are better, faster (less multiplications etc.) but you need to look at what the underlying architecture (DirectX) is going to do with them.

Also, think about what kind of operations you are going to be doing most and think about which mechanisms offer the best performance.

Whichever kind of camera you use there are plenty of resources for converting between the various structures and implementing "look at" functions so that your camera points in the right direction.

Share this post


Link to post
Share on other sites
The advantage of quaternions is not, in this day and age, related to their storage size and speed of use. Yes, they are smaller than matrices, and yes, the operations on them are faster; but frankly, if the frame rate of your game is limited by calculating the camera view, then either you're doing something very wrong, or you're already running at 3000fps anyway.

Quaternions are difficult to understand, or so I find them anyway. I also find, like you, that books gloss over the details. The reason is simple. Quaternions are Black Magic. I don't believe anyone really understands how they work, they just do.

Get to the point, I hear you say... OK, here's the thing. Imagine you are representing the direction your camera looks in via storing Pitch, Yaw and Roll (X, Y and Z rotations) angles. This is much, much simpler to understand than quaternions. For many games, it's going to be fully sufficient for your needs. However, your game is an arcade flight sim. Planes can do loop the loops, barrel rolls, and all kinds of exciting manouevres.

Grab yourself a model toy plane, or some substitute device (such as a mobile phone - something with an obvious orientation). Point it flying directly into the screen. This is Pitch 0, Yaw 0, Roll 0, right? Now, your pilot pulls back on the joystick - point your plane vertically straight up. This is Pitch +90. Your pilot pulls left on the stick - this makes the plane roll. Roll the plane through ninety degrees so that the left wingtip is pointing at the screen (Roll +90). So far so good.

Now your pilot kicks the left rudder - he wants to yaw. Yaw turns the plane horizontally, keeping it flat. With your plane in it's current position, already with Pitch +90 and Roll +90, that would involve tilting it so that the front of the plane points at the screen again. But! and here is the problem - if it did that, it would be changing the pitch. (Remember how we got the plane pointing vertically upward in the first place?) You now find that changing the Yaw of the plane actually has an effect on the Pitch. As if that weren't ugly enough, pretend that were actually possible - pretend that Pitch +90, Yaw +90, Roll +90 really did end up in the position we'd find ourselves in, with the plane pointing at the screen and the left wingtip pointing at the floor. Now take off the roll, leaving us with Pitch +90, Yaw +90, Roll 0... but we're back in the starting position, which was Pitch 0, Yaw 0, Roll 0! Something has clearly gone very, very wrong.

This phenomenon is known as Gimbal Lock, and manifests itself in a game as whichever object it is affecting twisting around unpredictably and uncontrollably when certain conditions are met. (Above we assumed we were talking about the plane, but your camera will be attached to the plane so the same principles apply). Storing your camera orientation as PYR (Euler angles) will, in the game you are describing, leave you suffering with Gimbal Lock. And it will make your game unplayable. Not all games are affected by this - generally speaking, if you don't use Roll at all (say you're making a third-person adventure, or a first-person shooter) you can get away with using Euler angles. For a flight sim, you can't.

The really important thing you need to know about Quaternions is this... they are never affected by Gimbal Lock. Black Magic remember? And that should tell you everything you need to know about what kind of camera you need for your game.

Share this post


Link to post
Share on other sites
Quaternions are really nice for animations (and camera stuff). Try interpolating matrices for example.

You will be better off implementing the three (Euler, Matrix, Quaternion), and write conversion routines between them. They are always handy. Note that the conversions are not straight forward, and that you will have to make assumptions.

this is a great site for that kind of stuff.

Martin Baker's Math Emporium

Share this post


Link to post
Share on other sites
Quaternions are really nice for animations (and camera stuff). Try interpolating matrices for example.

You will be better off implementing the three (Euler, Matrix, Quaternion), and write conversion routines between them. They are always handy. Note that the conversions are not straight forward, and that you will have to make assumptions.

this is a great site for that kind of stuff.

Martin Baker's Math Emporium

a small example of mine (WSAD key, mouse),
basic plane controls

Share this post


Link to post
Share on other sites
I wanna thank everyone for their input and advice. I think that the issues have been clearly shown and it seems that the quaternions are the way to go

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!