README for CS248 Assignment #3-4 Video Game Shanchi Zhan szhan@leland.stanford.edu Haobo Xu haoboxu@leland.stanford.edu How to run ./wild How to play This is a third-person view shoot game. Control your charactor to destroy the enemy force in a maze-like enemy base. keyboard: For your charactor 'j': turn left 'l': turn right 'i': move forward 'k': move backward 'u': step left 'o': step right 'z': fire For the camera 'q': up 'a': down 'w': closer to charactor 's': farer to charactor 'e': look farer 'd': look closer 'r': look up 'f': look down When you die: press enter to continue. Mouse: Click right button to pop up a menu to toggle different effects. Extra Functions: 1.On-screen minimap: A neat minimap showing where you and your enemy are on the bottom right corner of the screen. It's implemented by orthogonal projection and disable depth test. 2 View frustum culling: Enemy is considered as a cylinder.Compute two tangent lines from the view point to the cylinder. If both lines are out of the view frustum,enemy is culled. Wall is a little bit different. Besides checking whether the two lines from the viewpoint to the end points of a wall are both out of view frustum, a collision detection between the wall and view frustum is also implemented. For a wall could be large enough so that its endpoints are both outside of view frustum, but large part of it is still within the view frustum. 3 Occlusion culling: Occulision culling is implemented somehow like ray-tracing(Honestly, I didn't know ray-tracing till I reviewed CS248 last night.:) ) And I got the idea from AI of the enemy(covered later). Because enemies and charactor are much smaller than walls, walls are considered as efficient occluders. Similar to view frustum culling,enemy is consider as cylinder. If the two tangent lines from the viewpoint to the cylinder are both intersected with any of the walls, the enemy is culled. Wall is culled in the similar way. 4 Collision detection Collision detection is used intensively in this program to facilitate view frunstum culling; occlusion culling; camera movement; AI of enemies; bullet to walls,bullet to enemies and your charactor(spirit), spirit to walls collision.... For the boundary of spirit is a cylinder. The basic functions include face to line, face to cylinder, line to cylinder ... collision detections. It's a brain sucking but also constructive work. 5 Multipass rendering effects Reflection is implemented with a reflective matrix(can be as simple as a scale traslation) and a stencil buffer. The reflective surface is drawn first into the stencil buffer with depth test disabled to confine the reflection area. Then easily blend the reclective surface with the reflected scene. You can choose which object is to be reflected. In practice, it looks no good reflecting all the walls. So only the spirits, the bullets, the explosions are reflected. You can change this by adding more drawing functions to function DrawReflectableScene 6 Advanced image-based techniques Explosion is implemented by blending a growing textured poligon with the billboarding technique. the poligon is rotated to always face the line of view. 7 Sound Simple sound effect when you fire,when bullets hit the walls and the enemies, when enemies die. (Code modified from samples under the class directory). 8 AI The enemy's AI is pretty high.:) They know how to walk among the walls. (Obviously with the help of collision detection) They have their own view frustum! They will catch sight of your charactor if a. your charactor is in their view frustum b. your charactor is not occluded by any of the walls. Notice here, a&b are exactly viewfrustum culling and occlucion culling! In fact, I did these first, then I got the idea how to do culling. :) There are three type of the enemy: patroler,wanderer and seeker. There are also three mode of the enemy: patrol,wander and seek. 1. Patroler is normally in patrol mode, patroling between some area. When they catch sight of your charactor, they will change to seek mode , and then, change back to patrol mode as soon as the object is out of sight. 2. Wanderer is normally in wander mode, wandering in the base. When they catch sight of your charactor, they will change to seek mode , and then, change back to wander mode as soon as the object is out of sight. 3. Seeker has the ability to seek object. They are always in seek mode, following your charactor until you are in their gun range and firing! So there are three important properties for enemy: EyeRange: how far he can see EyeFovy: how wide he can see GunRange: how far he will fire from. Different values give different IQs .:) Furthermore, when the enemy gets hurt by you, he will turn to the shot direction and try to find you .:) Due to time limit, only wanderer is fully implemented(wander mode and seek mode), though the rest are fairly easy on the base of wanderer. 9. Procedural and physically-based modeling. Construct backgound 3D objects using procedural modeling, In particular, the program is capable of generating fractal trees and mountains that are recusively defined with the recursion depth dynamically alterable. (Code modified from samples under class directory.) Camera Movement: It's not listed as advanced functions. But It's important in this game. For a good third-person view game, camera plays a vital role. Not like first-person view game, the camera is not linked with the charactor's eyes, which causes much trouble. Sometimes camera will go into unpleasant places like inside the walls, and you will see all the mess. This will not happen in first-person view game, for the collision detection of the charactor to walls ensure the camera will not go into Walls. Furthermore, if charactor gets occluded by other objects, the camera should follow quickly to catch the charactor. It's somewhat like a AI problem which also includes the same technique used in occlusion culling and view-frustum culling(determine when the charactor is lost and should follow). Our solution is just a simple one. Let camera follow the charactor in a specified distance. Whenever the line between the charactor and the camera is intersected by a wall(camera goes inside the wall or the charactor occluded by a wall ), the camera go quickly before that wall and ensure the charactor is visable,and no back face of the wall is seen. It's more cinematic, if camera is sometimes fixed when the charactor moves around the scene, and follows him at the appropriate time. Resouces: The simple 3D model is done by ourselves. Wall and sky extures are got from web, sounds effects too. texture.c imported to load texture, useful. glm.c imported to draw obj 3D models, but nearly not used. SIGGRAPH'99 Advanced OpenGL Programming Course Notes help us a lot. :)