Dark Mesa Flight Simulator 2000 by Bob Kunz Sergio Marti 12/5/99 CS 248 Flight Simulator ---------------- The objective of the game is to fly around the environment and practice maneuvers such as taking off, landing, and flying by hazardous terrain and, of course, avoid crashing. Though this may sound like a simple game model, it is the basis of most commercial flight simulators such as Microsoft Flight Simulator series which is currently in the top 5 bestselling games. We also add the ability for the use to custom make their own terrains to fly through. Camera Views: The first and default view is the cockpit view. This view shows the cockpit of the airplane along with the indicators including speed, thrust, altitude, artificial horizon, and gear light. The artificial horizon is an especially interesting instrument and was remarkably complicated to calculate the correct rotation maneuvers for it to work. The chase view mode places the camera directly behind the airplane at a fixed distance. The orbit view mode allows the camera to be freely moved in an orbit around the airplane at a distance which can be adjusted by zooming in and out, but always looking in the direction of the plane. The free camera view mode allows the camera to be moved anywhere in world, completely independently of the position of the airplane. The tracking mode allows the camera to be moved anywhere in the world but always looking in the direction of the airplane. Finally, the top view mode places the camera directly above the plane. The user can then zoom the camera in and out. Mouse Controls: The mouse is used in the game to control camera movement in the views which allow free movement of the camera. Holding down the left button allows the camera to be turned left or right by moving the mouse in the X direction and tilted up or down by moving it in the Y direction. Holding down the middle button the camera can be moved forward and backward in the Y direction and rolled in the X direction. Holding down the right mouse button lets the camera be trucked left and right in the X direction and up and down in the Y direction. Not all movements are allowed in all the view modes. Keyboard Controls: 1 - Cockpit view mode. 2 - Press once for chase view mode. Press again for orbit view mode. 3 - Free camera view mode. 4 - Tracking view mode. 5 - Top view mode. Arrow Keys control plane direction of flight. UP - Pitch the plane down. DOWN - Pitch the plane up. LEFT - Roll the plane left. RIGHT - Roll the plane right. + - Raise thrust by 1. - - Lower thrust by 1. ] - Raise thrust by 10. [ - Lower thrust by 10. \ - Lower thrust to 0. g - Raise/lower landing gear. p - Pause the game. R - Restart the game. Q - Quit the game. t - Toggle texture use. C - Toggle backface culling. w - Toggle wide-angle view. B - Show bounding box used for collision detection. F - Cycle through fog modes (off, exponential, exponential squared, linear). d - Increase fog density. D - Decrease fog density. T - Toggle changing day time (sun and moon movement). z - Toggle sun flare effect. L - Enable/disable Game of Life easter egg. M - Switch to/from experimental flight model (explained below). Flight Model: Two physics models were written for the flight simulator. The first implemented and integrated into the flight simulator attempts to model the behavior of the airplane without calculating the actual physical response to a real-world system. Features include drift in the direction that the plane is tilted, a constant gravitational effect which causes the plane to accelerate when going down (the more downwards the plane is pointing, the faster it accelerates) as well as tilting and falling downwards inversely proportional to the speed of the plane calculated as a simple lift factor). The speed of the plane is proportional to it's thrust though it must go through a period of acceleration and decelaration when the thrust is altered (not instantaneous). It does not implement certain realistic effects such as engine stall. However, we did develop a second engine that modeled lift, drag, thrust, and gravity. Several bugs still existed at demo time so that model wasn't used. Designed a realistic flight model involved variable lift forces based on the angle of attack and a drag force that pulled the plane in the opposite direction as the current velocity. The main bug with the realistic flight simulator model was tuning the parameters to make the flight of the plane believable. Often drag was too high to correctly model falling into the ground. However, if drag was too low, then a small thrust delivered by the engine could yield a higher velocity then intended so that the bounds of the landscape were quickly realized. Since most of the problems involved tuning, this model was not used in the final demo but is available as an option to switch between the two. However, a plane involved in flight that is switch will have undefined behavior because the meaning of "velocity" and "thrust" are slightly different. Environment and Lighting Effects: To add to the realism of the game we added both a sun and a moon which light the scene using directional lights and can be seen as objects in the sky. Both rotate around the world at different rates. At sunrise and sunset, the world background color changes appropriately to reflect the lightening and darkening of the sky at the transitions from day to night. Also, by hitting the 'F' key, a fog effect can be added to the world at a bit of a performance hit. The fog density can be varied using the 'd' and 'D' keys. Importing Models and Textures: The F14, batwing, and airfield models were 3DS meshes downloaded from www.3dcafe.com. No author information is available for the models. The 3DS models were converted to OpenGL code using the 3DWin converter by Thomas Baier located at http://www.stmuc.com/thbaier/. The files were then modified and colors manually assigned to each component so that the models could be displayed in the game. The ground texture was taken from an OpenGL sample demo. The rest of the textures (trees, cockpit, explosions, sun) were created by us. The textures are loaded into the game using code developed by Mark J. Kilgard to load Iris RGB images and modified by us to allow loading an alpha channel (if available). Collision Detection: Collision with the ground is checked using a bounding square which is always maintained below the plane (in world coordinates) since none of the landscape can ever legally be above the plane. The the height of corners of the square are then compared to the height of the terrain at that location to determine whether a collision took place. In the event of a collision with the flat ground various conditions are checked for the possibility of a landing. The landing gear must be down, the plane must be nearly horizontal, and the speed must be low enough. If the plane is landing, it's direction is straightened out. If the plane is not landing, it crashes and explodes and the user is asked if they want to play again. Explosions and Thrust: The explosion effect is done by using the Alpha Blend function on a polygon which expands as its alpha value decreases. This gives the effect of an expanding and dissipating cloud. A similar technique is used for the engine thrust effect where it cycles through a few variations of the explosion image to give the effect of jet engines. Trees: The trees in the world are made up of 4 polygons set at 45 degree angles from each other and covered with a tree texture which is made somewhat transparent using the Alpha Test function. Landscape Generation: A key element of the "Dark Mesa" flight simulator game was the generation of realistic looking terrain that would model the desert southwest areas of Arizona and Utah. Originally, the intent was to generate landscape that was more realistic and would model lakes, oceans, and snow capped mountains but the time and processing power limitations required us to scale back on the landscape generation mechanism. Initial Pass: The first terrain generation mechanism was a square grid approach where each grid point formed four triangles with the three closest neighbors. Grid points were generated using a random number generation and then smoothed using the average with the eight nearest neighbors. The terrain was created separately then written out to a file which was read by the flight simulator at start up. The smooth terrain looked realistic and extremely smooth. However, for each grid point, four triangles were generated. Thus for a 1000x1000 point grid a total of 4,000,000 triangles were drawn. Rendering this terrain took a long time as the frame rate was around 4 fps. Even by scaling down the terrain to 100x100 grid points, the frame rate didn't improve to an acceptable level for efficient game play. Grid Format: Second Pass: To further improve the performance of the landscape generator, the triangle grid format was changed so that for each grid point, only 2 triangles were drawn. The grid point numbers were then reduced to 40x40 so that only 3200 triangles were drawn for the terrain. Thus produced a small mountain which could be quickly drawn. By drawing several of these around the map, the appearance of several mountains surrounding the airfield were created that scaled linearly rather than by the square of the grid points. Using this method, we could draw roughly 8 mountains around the map and not notice any significant decline in frame rate. By waiting the center of the grids more heavily than the outskirts of the map, the landform drawn looked like volcanic rock formations in Arizona and Utah which added to the feel of the "Dark Mesa" flight simulator and added to the landscape of the desert simulator. Third Pass: Frustrum Culling To further improve the performance of the landscape generation and rendering as well as increase the complexity of the landscape we implemented frustrum culling. Often only one or two mountains were visible at one point and time. We implemented the culling by calculating the angle between the camera and each of the landscape bounding box points. If any of the points fell within 45 degrees the entire landscape was drawn. This improvement allowed us to increase the number of landscape mountains to increase to 16. By doing Frustrum Culling we were able to keep the frame rate high most of the time. There was a minor speed difference noticed when all 16 landscapes were visible such as when the plane was flying from very high straight down. Fourth Pass: Landscape Editing In order to aid in the development of landscapes for the "Dark Mesa Flight Simulator", we designed a 2D landscape editor. The editor allows the user to change the height of landscapes by clicking on the grid points and adjusting the height of points. The editor shows a square 41x41 section of points green points along a black plane. The black sections of the screen are not valid points on the landscape. Green indicates the zero height which matches with the ground color of the land in the flight simulator. Red indicates the highest allowable point, roughly 8000ft. The landscape is edited by clicking the edit window. The user then selects the appriopriate edit function by hitting the key corresponding to the desired edit function. For instance, to increase the height of grid point by 100, press "i" in the edit window and then click the grid point on the window to increase. Debug information will be printed to the debug screen. Once edited the landscape file can then be written out to the "landscape.dmf" file which will be loaded by the flight simulator and automatically used in the landscape. Currently there is no support for additional file names. Only one custom landscape can be loaded at a time and it must be called landscape.dmf. Usage: r: set click function to a random height between 0 and 8000ft. h: set click function to the set highest setting (8000ft) g: toggle between displaying grid points and not. c: set click function to set a user specified contour level (level is set by stdin) i: set click function to increase current height by 100 m: set click function to decrease current height by 100 s: set click function to smooth current height by surrounding heights. w: write out landscape to "landscape.dmf" file.