Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have decided that in order to improve my math skills and game programming skills I am going to work on a two-dimensional space simulator. The view of the player or camera will be from inside the cockpit of a spaceship. This presents quite a few challenges which I am looking to the gd.net community for help with. I'm not asking for any code or any specific answers, just suggestions on what subjects to research.

My first challenge is going to be related to perspective correction. Since I'm only working with two-dimensions I need to fake flight dynamics. If you imagine that you are sitting in a cockpit of a spaceship, when you move the flight stick to the right or left the ship would yaw in either direction. Simulating this in two dimensions is much more difficult than in three dimensions, as you have to apply some sort of perspective correction.

The same is true if you were to pitch the nose of the spacecraft up or down. Simply moving the camera along the x / y axes won't be enough. I need to correct the perspective of my camera so that it appears that the aircraft is actually yawing / pitching in the desired direction and not just panning upwards / to the side.

What is the basic mathematical formula for applying this kind of perspective correction? If a formula is too much to ask for, where can I read about examples of this being done / read about the basic concepts I need to understand to accomplish this?

Thanks!

share|improve this question
    
This is a 2D FPS? –  Byte56 Feb 1 '13 at 21:08
    
Yes the perspective would be from the cockpit of a spaceship. –  Zachary Carter Feb 1 '13 at 21:10
    
The basic mathematical principle is to use 3 dimensions. –  Jimmy Feb 1 '13 at 21:23
1  
The positions are calculated using 3D math, and the sprites are looked up based on relative orientation. –  Jimmy Feb 1 '13 at 21:30
1  
let us continue this discussion in chat –  Zachary Carter Feb 1 '13 at 21:41

1 Answer 1

up vote 4 down vote accepted

Almost all 3D games are fake 3D. At the end of the day, you're projecting a 2D image into the screen. The standard way to project a 3D scene onto a 2D scene is using a Projection Matrix. In every 3D game, the programmer has to think in 3D "world-space" and 2D "screen space" (and sometimes, 3D "camera space")

but sir, I know the difference between SNES Zelda and SNES Mario Kart! One was 2D and one was 2D with fake 3D!

In the past, doing the calculations required for this projection was too expensive for standard processors. This is why "fake 3D" technologies like Mode 7 and Doom-style raycasting were invented. Nowadays, with dedicated graphics hardware and 3D libraries, It's more work to implement Mode 7 than to simply draw a textured quad on the screen.

There's this common idea that when you make a 2D game, you can use 2D coordinates for everything, and then add a "fudge factor" for perspective. Commonly, a game using 2D graphics will use this fudge factor to provide parallax effects as well as shrink objects that are farther away. However, this doesn't really change the nature of what you are doing. the "fudge factor" is how you represent the Z-axis. You're really just calculating positions in 3D space anyways, so "faking" yaw and perspective in a (X,Y,fudge) system. is more difficult that calculating real yaw and perspective in a (X,Y,Z) coordinate system.


TL;DR: Games such as Wing Commander use 3D math for all game logic such as calculating the position of an asteroid or enemy, then finally use perspective equations to calculate where to draw on the screen. You can then draw sprites at the calculated position, and this is how it looks "2D"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.