3D Racing Car Game - Chalmers

Transcription

d3D Racing Car GameProject LloydBachelor’s ThesisSVEN ABELSSON RUNINGMATHIAS HÄLLMANNICOLE ANDERSSONDepartment of Computer Science and EngineeringCHALMERS UNIVERSITY OF TECHNOLOGYGothenburg, Sweden, 2009SVEN ANDERSSONFREDRIK TOFTRICKARD NILSSON

3D Racing Car Game2009-05-193D Racing Car GameProject LloydSven Abelsson RuningSven AnderssonMathias HällmanFredrik ToftNicole AnderssonRickard Nilsson Sven Abelsson Runing, Sven Andersson, Mathias Hällman, Fredrik Toft, NicoleAndersson, Rickard Nilsson, May 2009.Department of Computer Science and EngineeringCHALMERS UNIVERSITY OF TECHNOLOGYSE-412 96 GothenburgSweden2 (51)

3D Racing Car Game2009-05-19AbstractThis bachelor thesis describes a case study, where we focusing on developing a 3Dracing car game, using a process based upon agile development; an evolutionarydevelopment method.The thesis will cover implementation of real-time graphics, physics engine, networksupport, as well as sound effects and background music.In the end, our case study will show that this development process was anappropriate choice for our game development project.SammanfattningDenna slutrapport beskriver en fallstudie gjord på utvecklingen av ett 3D -bilspel.Utvecklingen använder sig av en process baserad på agile development, som är enmetod inom evolutionary development.Slutrapporten kommer att täcka implementering av realtidsrenderad grafik,fysikmotor, nätverksstöd, liksom ljudeffekter och bakgrundsmusik.I slutändan kommer fallstudien att visa att utvecklingsprocessen var ett lämpligt valför vårt spelutvecklingsprojekt.3 (51)

3D Racing Car Game2009-05-194 (51)

3D Racing Car Game2009-05-19Table of Content1. INTRODUCTION . 72. GAME DESIGN . 82.1. Game Design and Concepts . 82.1.1. Initial Concept . 82.1.2. Second Iteration . 82.1.3. Final Concept . 82.2. Development Process . 9What Is a Software Process Model? . 9The Waterfall Model . 10Component-based Software Engineering . 11Evolutionary Development . 112.2.1. Our Development Process . 11Agile Methods. 12Milestones . 132.3. Game Engine . 132.3.1. Game Framework . 13Microsoft XNA . 13CodePlex . 142.3.2. Physics Engine. 14Background . 14JigLibX . 15Limitations . 152.3.4. Game Assets . 172.3.4.1. Creation. 172.3.4.2. Result and Discussion . 182.3.4.3. Loading . 182.3.5. GUI, Menu and HUD . 19Background . 19Results . 20Discussion . 213. GRAPHICS . 223.1. Lights and Rendering . 223.1.1. Ambient Pass . 233.1.2. Light Pass . 243.2. Shadows . 255 (51)

3D Racing Car Game2009-05-193.2.1 Shadow Mapping . 253.2.2. Variance Shadow Mapping. 263.3. Bump Mapping . 273.3.1. Techniques . 273.3.2. Normal Mapping . 273.3.3. Parallax Mapping . 273.3.4. Result and Discussion . 273.4. Post-processing Effects . 283.4.1. Motion Blur . 283.4.2. Screen-Space Ambient Occlusion . 293.4.3. Bloom . 313.5. Particle Systems . 323.5.1. Sparks . 333.5.2. Sprinkles and Glow . 343.5.3. Smoke. 343.6. Result . 353.7. Discussion . 364. NETWORK . 374.1. Background . 374.2. Results . 384.3. Discussion . 425. SOUND . 425.1. Sound Effects . 425.2. Background Music . 436. RESULTS . 436.1. Requirements . 436.2. Features . 436.3. Time Estimations . 446.4. The Development Process . 447. DISCUSSION . 458. ABBREVIATIONS . 46APPENDIX A . 47APPENDIX B . 48REFERENCES . 496 (51)

3D Racing Car Game2009-05-191. Introductionreal-time rendered soft shadows,motion blur, and ambient occlusion.Developing software applications is atime-consuming process, and withtime-consuming processes come highcosts. During the last years, severalsoftware development methodologies,often known as agile softwaredevelopment, have become widely usedby software developers to address thisissue. Many different developmentmethodologies can be more or lessgood, depending of the task andapplication type.Working with these requirements, wedecided to use Microsoft XNA as ourplatform to develop our 3D game with.This decision was made with regard tothat the platform had many in-builttools and provided a good frameworkfor us to get started with thedevelopment as fast as possible. Thefact that Microsoft XNA also used C#as development language was also inconsideration, since we wanted to learnthis newly developed C-based objectoriented language.One of the software developmentmethodologies is the evolutionarysoftware method, which, as the namehints, takes on an evolutionaryapproach to the problem, and allowsthe project to evolve through differentstages of the project. Our case studywill show how well this evolutionaryapproach worked on our project wherewe choose to develop a 3D graphiccomputer game. Some requirementsfor the computer game were given fromthe beginning, such as:The requirement for the game tocontain 3D graphics introduced aninteresting challenge for the projectgroup, since all had none or littleexperience in 3D modelling. Spendingtime learning how to model proper 3Dmodels for our game was thereforenecessary. During the research to findout what 3D modelling program to use,we found that we could use differentstudios to create models that we couldlater import to our game project. Thecomplete game contains models madein both Blender and 3D Studio MAX.3D graphics – The game mustcontain 3D models, and render these inthe game. 3D environments were nevera requirement, and platform gameswith 2D environment could still openup for 3D objects.With these choices made, we soon hadour development environment set touse Microsoft Visual Studio 2008 withMicrosoft XNA Game Studio 3.0supporting the framework, andBlender and 3D Studio MAX formodelling the graphical components.For some of the sound effects we alsomade use of Adobe Audition 2.0.Impressive result – The game resultmust impress whoever plays the game.It should last long, and make theplayers come back and play it over andover again.Graphical effects – To achieve animpressive result, we would need toadd modern graphical effects, such as7 (51)

3D Racing Car Game2009-05-192. Game Designlevelling, something that many playersappreciate. It was also decided that theracing track should be a garage or astore-house, filled with containers,boxes, and miscellaneous objectssuitable for that environment. Sincedriving a real car around a garage isvirtually impossible, it was decidedthat we should make remote controlledcars instead.2.1. Game Design and ConceptsIn this project, we were left free todecide what type of game we wanted todevelop. The suggestion was that aracing game would be suitable, sincesuch a game usually do not depend onadvanced assets, e.g. animated models.After some brainstorming, it wasdecided that a racing game should bedeveloped. However, there were twodifferent racing game ideas, which willbe described below.2.1.3. Final ConceptWe kept most of the ideas from thesecond iteration with one exception forthe death rally concept. It appearedthat our first instinct, to give this idea alow priority, was right and in this lastiteration, the idea was dropped.However, a racing game where playersonly may collect coins and nothingmore, sounded a bit boring. Influencedby games like Super Mario Kart, it wasdecided that power-ups should beadded. There are a number of differentpower-ups, and they could be dividedinto two groups; those that affect thecar that hit the power-up, and thosethat affect the opponents’ cars. A moreprofound description of the differentpower-ups follows.In compliance with our developmentprocess, the game concept evolved, asmore and more features were added.To further explain how the gameconcept evolved, the development hasbeen divided into three parts.2.1.1. Initial ConceptOur first concept had a game playsimilar to Remedy’s game in 1996,called Death Rally1, where each playerhad a car equipped with a weapon, andthe goal was to hunt down theopponent’s cars. The other idea was tocreate a simple race track whereplayers could collect coins in order towin. Since the first idea involved muchgreater work than the latter one, it wasdecided that the first idea were to begiven a low priority, whereas thesecond were to be given a high priority.In addition to the other improvements,one change was made to the pointssystem. It should be possible to collectthree types of coins, worth 50, 100 and200 points.2.1.2. Second IterationWe decided that a joint solution wouldbe best, where players are able tocollect coins and then use the money tomake upgrades. Example of upgradeswas better weapons, faster engine, andheavier car body. These upgradeswould be similar to the concept of8 (51)

3D Racing Car ness, availability, maintainability, dependability and usability. Tomeet such varying demands, it isimportant to base the work on a wellprepared strategy. In software engineering, the term for such a strategy iscommonly known as software process,which is built on one or severalsoftware process models.DescriptionNitroThe player’scar movesfaster.PunchA punch from arandomdirection hitsthe opponents’cars.DoublepointsThe player’spoints aredoubled.SlowSlows downthe opponents.ReverseTheopponents’steeringcontrols arereversed.LowFrictionCauses the carto lose frictionto the ground.What Is a Software Process Model?A software process model is atheoretical philosophy that describesthe best way of developing software.Based on one or several models, asoftware process is formed providingguidance on how to operate. A softwareprocess model may also be described asan abstract representation of a software process. The concept of theprocess model is similar to an abstractjava class, which can not be instantiated, but it can be implemented byanother class, thus providing basicguidelines for that other class.A model may for example demandcustomer involvement, but it does notstate exactly how. A process implementing that model should involve thecustomer in the process’ activities, butis free to choose how2.There is not only one type of processmodel, but two. The first one is themost common, and described above.The second type of process model iscalled a process paradigm, which is amodel even more general than anordinary process model. Such a modeldoes not hold any details on how theactivities that lead to the completion ofa project should be performed, butwhat it does hold is basic guidelines ofhow to develop software, and assump-Figure 1: Punch object.2.2. Development ProcessIn a software development project, theresulting product is required to fulfilmany different qualities. Examples ofsuchqualityrequirementsare:9 (51)

3D Racing Car Game2009-05-19tions about what sort of project couldbenefit from implementing a particularmodel. With this in regard, one canconclude that a process paradigmprovides a framework that may beadapted to form a process which suits aparticular project.There are three major process paradigms that are commonly used today insoftware engineering practice; thewaterfall model, component-basedsoftware engineering and evolutionarydevelopment2.The Waterfall ModelThe waterfall model is recommendedfor large and complex systems thathave a long life-time 2. Some systemswhich carry these attributes are alsocritical systems. This means that if afault would occur, it may result in:Threat to human life (death orinjury)Economic lossEnvironmental damage2It is believed that the waterfall modelwould be an appropriate choice whendeveloping a critical system, since themodel emphasises on thoroughness3.The basic concept is to take all theactivities and treat them separately.One activity is always followed byanother, in the same way water travelsdown some falls. This descriptionbecomes even more obvious whenlooking at a visualization of the model(Figure 2).RequirementsdefinitionSystem andsoftware designImplementationand unit testingIntegration andsystem testingOperation andmaintenanceFigure 2: The waterfall model2.1. Requirements definition Allrequirements on the system arefound by talking to system users.Example of requirements can beservices, constraints and goals,such as “We want a webpage thatcolour-blind people can enjoy”.2. System and software design Inthis activity, the overallarchitecture of the system isestablished.3. Implementation and unit testingThe software is implemented inunits which also are tested.4. Integration and system testingThe units are merged togetherinto a complete system. Furthertesting is required.5. Operation and maintenance Thesystem is delivered to thecustomer and put into operation.“Bugs” are almost always found,and therefore the systemrequired bug-fixing andmaintenance.In each of the activities describedabove, one or several documents areproduced. The idea is not to start on anew activity until the documentsbelonging to the previous activity issigned off, but in practice, this is nothow it is done. Instead most of theactivitiesoverlapandallthedocuments feed information to thedifferent activities. Although thesedocuments provide a good overlook,10 (51)

3D Racing Car Game2009-05-19they are very costly to produce. Due tothe cost of constantly producing, signing and reworking documents, thewaterfall model should not be appliedto a project where one is uncertainabout the requirements 2.Evolutionary DevelopmentThis model is recommended for smalland medium-sized systems that shallbe developed rapidly2. The idea is thatspecification, implementation andvalidation should work as concurrentthreads, all supplying input to theother activities. Customer input isconsidered to be very important, if noteven necessary for the developmentand outcome of the project.Component-based SoftwareEngineeringAs the name suggest, this model is usedwhen there are several already existingcomponents which can be reused andput together to form a system.Normally, reuse is an important part ofany software process, but in this case itis the fundamental activity. The firstand the last activities, requirementsspecification and system validation, arethe same as in any process model, butthe intermediate activities differ fromother models.At the beginning of a project, an initialimplementation of the software isproduced and released to the customer.This way, the customer can makeimprovements and further describedetails, which might not have beenclear to the developers. Gradually thesystem will improve, and when thefinal release comes, the customershould be fully satisfied with thesystem.During the component analysis, onesearchesforcomponentsthatcorrespond to the requirements. Whenthe right components are found, theymight differ a bit from the originalrequirement specification, thus leadingto a modification of the requirements.Before the system is developed and thecomponents are integrated, thearchitecture of the system must beestablished.Thisisdoneinconsideration to the found components. When all of the componentsare fully integrated, it is time nalysisRequirementsmodificationDevelopmentand utionary development is dividedinto two major types:1. Exploratory development Thedevelopment start with therequirements that are bestunderstood. To further evolve thesystem, new features areproposed by the customer. Thisidea relies on the customer’swillingness to spend much timecontributing to the project.2. Throwaway prototyping Thedevelopment starts with therequirements that are poorlyunderstood, because there is noneed to prototype requirementsthat you already understand.System designwith reuseSystemvalidationsoftware11 (51)2.2.1. Our Development ProcessIn this project, evolutionary development was chosen as a keystone for our

3D Racing Car Game2009-05-19development process. The decision wasmainly based on the size and theduration of the project. We had alimited amount of time, namely 4.5months, and during this time ngineering was easily dismissed sincethere were very few, or none,components to work with. Thewaterfall model was dismissed, since itfocuses a lot on writing documents,which is a very time-consumingactivity.these two models are connected toevolutionary development, and whichlevel of detail they hold, is representedby Figure 4.When it came to deciding whether togo with throwaway prototyping orexploratory development, the latterwas chosen. This decision was based onthe following facts. The greatestproblem was not to understand thebasic requirements, but how muchtime it would take implementing themany possible features. Given thecircumstances, the best strategy wasfirsttoimplementthegamefoundation, and subsequently implement one feature after another, henceusing exploratory development.For example, agile methods agree withevolutionary development on somepoints, but other ideas and conceptsmay be added, hence the agile circle isnot totally encased by the evolutionarycircle. The heights of the circlesindicate what level of detail the modelshold. XP is more detailed than agile,whichismoredetailedthanevolutionary.Figure 4: Visual description of how differentprocess models are related to each other.Since we, in this project, wanted to testsomething other than XP, it wasdecided that agile methods would besuitable.As indicated earlier, a process isseldom based on one single model, andmodels are not considered to bemutually exclusive.Agile MethodsAgile is a common name for a numberof different software process models.Although the different models sharethe same idea, that the best way ofdeveloping software is throughoutincremental development and delivery,they propose different ways to attainthis. However, they have one morething in common, namely a set ofprinciples, which are described below2:Since evolutionary development is aprocess paradigm that provides littledetail on how to work, it would be wiseto choose a little more specific model.This model would have to agree withtheideasthatevolutionarydevelopment represents. There are twomajor process models which would besuitable; XP (eXtreme Programming)and agile development methods2. HowCustomer involvement12 (51)

3D Racing Car Game2009-05-19The customer should be closelyinvolved in the developmentprocess and contribute byproviding new system requirements and evaluate each of theiterations. In this project thedevelopers along with thesupervisor acted as customers.Incremental deliveryThe customer specifies whatrequirements are to be includedin what increment.People, not processIt is important that themembers of the developmentteam are free to develop theirown way of working, instead ofblindly following what theprocess specifies.milestone would last approximatelytwo weeks. In order to get a goodoverview and make reasonable timeestimations we, acting as developers,had two meetings per week. On thesemeetings, we checked the project’sstatus and saw to it that the milestoneswould be delivered on time. In thebeginning of each milestone, we actedas customers, thus providing newfeatures to be added. What features toadd, was based on an evaluation of themost recent milestone. For moreinformation about what tasks that wereassigned to what milestones, seeappendix A.In addition to the milestones, a roughtime estimation of the major parts ofthe game was made, this is found inappendix B.2.3. Game EngineEmbrace change2.3.1. Game FrameworkThe system should be designedin such a way, that it is easy toimplement changes or newfeatures.To save time in our developmentprocess, we choose to use MicrosoftXNA framework, when developing ourgame.Maintain simplicityMicrosoft XNAMicrosoft XNA framework providesdifferent tools to help game developersget started more quickly 4. Such tools,as the XNA Framework ContentPipeline, help developers by reducingthe time you need to add 2D and 3Dcontent to your game5. In our game, weused Microsoft XNA Game Studio 3.0,which contains a complete class libraryfor handling game content and events 6.We took advantage of many of theseclasses; Audio to implement soundeffects and background music to thegame, Graphics to implement 3Dgraphics to the game, Input toBoth development process andsoftware should be kept simple 2.MilestonesAs indicated earlier, incrementaldelivery is a keystone in agiledevelopment, which also makes it animportant part in this project. Eachincrement is here called a milestone, asa way of indicating how far on the roadto a complete program we have come.Sinceevolutionarydevelopmentstresses the importance of having shortincrements, it was decided that each13 (51)

3D Racing Car Game2009-05-19communicate with the player, and Netto implement network support to thegame.CodePlexCodePlex7 is a community to host opensource projects; most of them made in.NET, and especially C#. The website ishosted by Microsoft, and was started toencourage open source development.CodePlex provides different tools tosupport the user in his or herdevelopment; such as wiki pages,discussion forum, RSS support andstatistics(overdownloadsandvisitors). It also provides the projectwith a version control system, whichhas support for different software,including TortoiseSVN 8, and VisualStudio Team Explorer, which we usedin our project. A version control systemwas absolutely necessary for ourproject group to manage differentversions of the project files, especiallywhen many developers work with theproject concurrently.2.3.2. Physics EngineBackgroundThe part that handles the physicalbehaviour of the game world is called aphysics engine and it is made up ofthree main parts; collision detection, adynamics simulation and updating thesystem 9. The dynamic simulation partsolves the forces affecting thesimulated object.It is desirable that the game objectsbehave in a realistic way. The objectsshould be able to detect when theycollide with other objects. When theyhit another object, they should resolvethe collision in a realistic way. Theirspeed should be affected by gravity.14 (51)Each game object is represented in thephysics engine by a simplified mesh,called a collision skin. The collisionskins are often rough estimations ofthe geometry of the game object inorder to make the simulation faster.The chassis of our car objects are forexample represented by two boxes(Figure 5), one large for the bottom ofthe model and a smaller for the top.Figure 5: The car is represented by two boxesin the physics engine.Rigid body

3D Racing Car Game 2009-05-19 3 (51) Abstract This bachelor thesis describes a case study, where we focusing on developing a 3D racing car game, using a process based upon agile development; an evolutionary development method. The thesis will cover impl