Hakara TEA Laurent MEUNIER CS248 PROGRAMMING ASSIGNMENT 3 and 4 VIDEO GAME "ROLLING SNAILS" ----------------------------------------------------------------------------------------- The following requirements were implemented: basic requirements - 3D viewing and objects - User input - Lighting and smooth shading - Texture mapping extra requirements - Hierarchical Scene Graph - View frustum culling - Level of detail control - Procedural and physically-based modeling - Collision detection - Simulated dynamics - Parametric curved surfaces - Game level editor TECHNICAL FEATURES ****************** I. THE SCENE MANAGEMENT. The scene is structured as an hierarchical tree, whose main aim is to speed-up the non-visible objects culling. Each node is enclosed in a bounding-box that contains its own descendant bounding-boxes. Thus as soon as we know that a node is not visible, it is not necessary to test further in the subtree. This clipping is done in addition to the one provided by openGL, in order to minimize the number of triangles sent to the state machine. This was absolutely necessary given the size of the scene. It enabled the number of nodes displayed to be reduced from several thousands to less than 200. Choosing the size of the nodes required to consider both the time spent on visibility computations and the accuracy of the culling. Each node of the tree may correspond to any of the basic openGL entities : a light, a material, a transformation matrix, a motion, an object, etc... We wanted this structure to be in the same time efficient and flexible. The ground landscape is a specific subclass of this scene structure. It is organized as a quad-tree whose leaves are elementary squares on a NxN grid. This enables to define multi-level detailed models of the landscape, which are used according to the distance from the view point to the considered part of the landscape. This required to handle with problems related to the junctions between areas with different levels of details. The holes were filled in using additionnal triangles strips added on the edges of the areas. The whole environment of the game consists of a landscape, a track, and various objects placed along the track. Each elementary square of the landscape is defined as a Bezier function controlled by the heights and normals of the four edges. These controlled points are generated using a fractal function. The final height at a point (x,y) is obtained by substracting the track profile to the original landscape. For each square element of the landscape, we generated a mesh by sampling several points on the surface. The resulting mesh is an instance of CAdvancedObject, a generic container for all openGL objects that can be defined using an interleaved array. Practically, we use triangled strips for efficiency. Each parent contains an under-sampled version of its child meshes, used for multi-level detail displaying. In order to avoid having to define limits for the scene, while using a bounded landscape, we replicated that landscape over each direction, using symetries to solve the continuity problems. Objects and track segments are referenced by each leaf in order to restrict collision tests to objects located near the characters. II. Motion Management The characters motions were implemented using dynamics principles applied to a ball. This includes: rotation of the ball (snail's shell), surface-constrained movements, flying mode, rubbing effects of the ground (the snails slows down if it does not accelerate), realistic bending of the body and direction changes of the speed (sudden turns trigger opposite forces), smooth motion of the cameras and the snail (to avoid shaking behaviors), collision detection between the two snails. The collision detection between the snails and the game objects are not totally implemented. Four types of cameras were designed. FOLLOWING MODE : the camera follows the character and remains vertical. SUBJECTIVE MODE : looking through the snail's eyes HELICOPTER MODE : view from the air SHOULDER MODE : the camera follows the snail but remains perpendicular to the ground The interaction between the ground and the characters mainly call for two methods ground->getZ(x,y) and ground->getN(x,y) which return the height and normal of the surface at a given point of the scene, using the Bezier functions and the distance to the track. This made collision detection with the ground mesh unnecessary, and saved a lot of running time. GAME FEATURES ************* I. MENU BAR We provided a menu bar enabling the user to set several parameters of the rendering (fill/line/point modes, fog switching, flat/smooth mode) as well as choose the camera mode for each player, choose another level, switch from edit mode to play mode, 2-players mode, and lastly display a top view showing the surface culling and the multi-level detail management. II. CONTROLS: The game may be played by two people simultaneously, by splitting the screen into two independant parts. Player 1 (in the bottom of the screen) controls its snail with the mouse, while player 2 uses the keyboard. Mouse: left button accelerate middle button slow down right button menu The snail can turn only if one the buttons are pressed Key: arrow keys The snail does not need to accelerate to turn We used special-func and special-func-down functions provided by the GLUT library. III. EDIT MODE: The EDIT mode enables the user to define its own tracks by laying landmarks on the ground and then requiring the program to dig the track from one landmark to the next one. When the EDIT mode is on, it is possible to set the view point to any possible coordonnates in the scene: middle button: enables the user to change the viewing direction by moving the mouse in both X and Y directions. left button: move forward along the viewing directions. A vertical line shows the corresponding position on the ground. A orthogonal line shows the orientation and size of the track/objects The following keys may be used : space: place a landmark. 'x': remove the last landmark '+' and '-': change the track width left and right arrows: change the object orientation '1' to '9': place one of the objects on the ground 'd': dig the track defined by the landmarks 'r': delete all objects/track segments 's': save objects/track for this level 'l': load " IV. THE OVER-SCREEN DISPLAY: A kind of "head-up display" is available, that provides information about the current state of the game : * number of the level; * number of laps remaining; * time elapsed from the beginning of the last lap; * timing for both players on the last lap; * a map of the level, showing the track and the location of both players * a speed bar V. THE LEVELS: The program makes it possible to define as many levels as desired, which are parametrized by the landscape fractal generator (an integer), the colors of the sky and fog, a function that maps colors on the landscape and lastly a file defining the track and the position of the objects. We designed 3 levels for the demonstration, and tried to create three different athmospheres: level I: "water-colors sunny day" level II: "mars by night" level III: "lost in the foggy mountains"