3D Game Programming All In One (2004)
.pdfxx Contents
Building Bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .505
Building a House . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .508
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .512
Chapter 18 Making the Game World Environment . . . . . . . . . . . . . . . |
513 |
Skyboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
513 |
Creating the Skybox Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
516 |
Adjusting for Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
518 |
The Sky Mission Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
519 |
Cloud Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
521 |
Cloud Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
521 |
Cloud Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
522 |
Fog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
523 |
Storms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
524 |
Setting Up Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
524 |
Storm Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
528 |
Lightning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
529 |
Rain 531 |
|
A Perfect Storm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
532 |
Water Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
533 |
Terraforming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
534 |
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
538 |
Chapter 19 Creating and Programming Sound . . . . . . . . . . . . . . . . . . |
539 |
Audacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .540
Installing Audacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .540
Using Audacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .540
Audacity Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .542
OpenAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .550
Audio Profiles and Data Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . .550
Audio Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .551
Trying It Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .553
Koob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .555
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .558
Chapter 20 Game Sound and Music . . . . . . . . . . . . . . . . . . . . . . . . . . .559
Player Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .559
Footsteps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .560
Utterances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .563
Team LRN
Contents xxi
Weapon Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .565
Vehicle Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .572
Environmental Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .578
Interface Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .579
Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .580
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .582
Chapter 21 Creating the Game Mission . . . . . . . . . . . . . . . . . . . . . . . . |
583 |
Game Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
583 |
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
584 |
Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
585 |
Koob 586 |
|
Torque Mission Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
587 |
World Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
589 |
Terrain Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
590 |
Terrain Terraform Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
592 |
Terrain Texture Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
592 |
Mission Area Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
593 |
Building the World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
594 |
Particles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
594 |
The Terrain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
605 |
Items and Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
606 |
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
608 |
Chapter 22 The Game Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
609 |
The Player-Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
609 |
Player Spawning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
609 |
Vehicle Mounting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
611 |
The Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
611 |
Server Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
612 |
Vehicle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
617 |
Model 617 |
|
Datablock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
617 |
Triggering Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
620 |
Creating Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
620 |
Scoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
622 |
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
630 |
Team LRN
xxii Contents
Chapter 23 The Game Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .631
Client Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
.632 |
MenuScreen Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
632 |
SoloPlay Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
634 |
Host Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
635 |
FindServer Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
635 |
ChatBox Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
636 |
MessageBox Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
640 |
Client Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
642 |
MenuScreen Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
642 |
SoloPlay Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
643 |
Host Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
647 |
FindServer Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
648 |
ChatBox Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
650 |
MessageBox Interface Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
652 |
Game Cycling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
655 |
Final Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
657 |
Moving Right Along . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
657 |
Chapter 24 The End Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
659 |
Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
660 |
Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
660 |
Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
660 |
Play Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
661 |
Test Harnesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
661 |
Hosted Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
661 |
Dedicated Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
662 |
FPS Game Ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
662 |
Other Genres . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
663 |
Modifying and Extending Torque . . . . . . . . . . . . . . . . . . . . . . . . . . |
664 |
Go For It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
665 |
Appendix A The Torque Game Engine Reference . . . . . . . . . . . . . . . . . |
667 |
Torque Console Script Command Reference . . . . . . . . . . . . . . . . . . |
667 |
Torque Reference Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
727 |
Team LRN
Contents xxiii
Appendix B Game Development Resources on the Internet . . . . . . . . .741
Torque-Related Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
.741 |
Game Development Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
743 |
Appendix C Game Development Tool Reference . . . . . . . . . . . . . . . . . |
749 |
Shareware and Freeware Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
750 |
Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
750 |
Image Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
751 |
Programming Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
751 |
Audio Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
752 |
Retail Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
752 |
GNU General Public License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
754 |
Appendix D QuArK Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
755 |
The Map Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
755 |
Configuration Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
764 |
General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
764 |
Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
766 |
map2dif Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
767 |
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .773
Team LRN
Letter from the Series Editor
In the past few years, game development has become a huge subject, covering so many areas of technology and expertise that learning all the various aspects of game development would be a huge undertaking that would easily take 5-10 years to master. One of my goals with the Premier Game Development series was to cover each and every area of game development in depth, in a highly technical manner. However, sometimes you just want to know “how” to do something; you’re not really interested in every single detail. Along these lines, I experimented with a totally beginner book titled Game Programming All in One, in which the reader is assumed to know nothing about game development, not even how to program! The book you’re holding is really a follow-up to that book, albeit on a slightly different path. Instead of teaching general game programming from the ground up, 3D Game Programming All in One teaches you how to make 3D games—period.
This book isn’t so much about developing 3D engines, complex 3D math, or even physics, but how to create 3D games and what the high level major components of them are. As the author Kenneth Finney and I discussed and developed the book, we decided that the goal shouldn’t be to exhaustively teach 3D game development—that would take 5,000 pages. Instead, the book should have the single goal—given a reader is familiar with C/C++, teach him how to make a 3D game as quickly as possible, leverage as much technology as possible, but still give the reader enough background information on the low-level aspects of 3D game development that if he did want to write everything from the rendered to the physics engine, he would have at least an idea of what they do.
3D Game Programming All in One is probably the only book you will find that will really live up to the hype of being able to teach you to create a 3D game. Let’s face it, there are only a handful of people in the world that have the technical expertise (or the time) to write a commercial 3D engine, thus, this book saves you the time of that nightmare by leveraging one of the most advanced 3D engines available, the “Torque Engine”—even the name is cool. Ken uses this state-of-the-art 3D engine as a semi black box API to create 3D game examples in advancing levels of complexity. The book begins with basic 3D concepts, moves on to objects, models, large-scale worlds, and how all the elements of a 3D game fit together. Then Ken builds game demos that use these concepts, one added to another in a real-world example of developing an actual 3D game. By the end of the book, you will be able to create a number of 3D game types, from first-person shooters to exterior-based games with vehicles.
Team LRN
In conclusion, I highly recommend 3D Game Programming All in One to anyone who wants to learn how to build 3D games, but doesn’t necessarily want to spend 5-10 years learning how to build a 3D game engine from the ground up! In no time you will be creating amazing games based on a state-of-the-art engine. Then, if you so desire, you can always delve deeper into 3D engine design with further studies.
Sincerely,
André LaMothe
Series Editor, Course Technology PTR Game Development series
Team LRN
Introduction
Beginnings
“Hi, I’m using your software and I was wondering—can you tell me how I can make a computer game? I don’t have much money, but I have this terrific idea for a shooter-like XYZ game, except I’ll make it do…”
During the past several years while working on the Tubettiland “Online Campaign” software and more recently while working on the Tubettiworld game, I figure I’ve received more than a hundred queries from people of all ages about how to get started making games. There were queries from 40-year-olds and 13-year-olds and every age in between. Most e-mails were from guys I would estimate to be in their late teens or early 20s.
After about the 30th response or so, I gave up trying to help these people out in detail and started to just point them to Web sites where they could gather the information they needed. Finally I stopped responding completely. But this bugged me to no end (I still get several of these e-mails in a month), so every now and then I will respond with the Web links or some pointers. However, whenever I do answer, I often get drawn into long e-mail exchanges for which I just don’t have the time. Eventually I have to beg out of the exchange, usually by being nonresponsive at some point. Then I feel bad again.
I see this book as a sort of e-mail to everyone I haven’t responded to. It’s been rattling around in my head for about two years now, and I have to get it out!
About This Book
If you want to, you will be able to take this book and a computer, go into a room without Internet access, and emerge with a completed, ready-to-play first-person shooter game
xxvi
Team LRN
Introduction xxvii
within weeks. You will then be able to spend as much time as you want to dream up your game play concepts, and you will have the ability to add them to your game.
You might think this is a bold claim, but you can see for yourself. Go ahead and turn to the Table of Contents, or take a quick flip-through skim of the chapters. It’s all there. If you follow through and do the exercises and work, you will arrive at the other end of the journey with experience, not just book learnin’.
Believe in Yourself
Computer games are a $9 billion per year industry. A growing part of this industry is people like you—part of a growing segment of the gamer population that doesn’t just want to play the games but believes that you can make them better than the game companies can. Your problem may be that you lack the right combination of training, experience, and tools needed to turn your dreams into reality. This book is for you.
Every year more and more colleges offer game development programs, and every few months a new online indie game developer site launches on the Web. There is no lack of training available for those with the money to pay, and there is no lack of books for those of you who want to create your own engines or other specialized parts of a game.
The key element missing is a resource that takes the inspired and aspiring game developer by the hand and walks him through all the steps and tools required to make a fully featured game. This book is that resource. With the exception of game music composition (which itself could be a complete book series), you, the Gentle Reader, will learn how to create every part of the game yourself by using a well-defined toolkit of programs, knowledge, skills, and ideas. Sound, music, art, and code libraries are included on the companion CD for you to use if you lack a certain artistic or creative flair.
What You Bring to the Party
I assume that you have more than a passing familiarity with computer games, especially the first-person shooter genre. Throw in some computer savvy, add a reasonably capable computer system, sprinkle with desire, and you should be good to go!
Skills
You are probably fully able to deal with all aspects of Microsoft Windows–based computing. You don’t need to be a programmer, but you do need to be aware that some programming will be required in creating a computer game. The first few chapters will introduce you to all the programming concepts that you will encounter in the course of using the book. You will not be expected to learn advanced 3D math in detail, but you will learn enough 3D math to accomplish your goals.
Team LRN
xxviiiIntroduction
I’m going to show you how to create your own artwork, but you don’t need to be an artist. The companion CD features a large collection of art you can use in your game.
System
All of the development tools, including the engine, are also included on the companion CD. All of these tools are priced such that even though the shareware version may be included on the CD, the actual registered versions are less than $100.
You will need a Windows-based computer to use this book. (The table below outlines the minimum system requirements.) It is possible for Macintosh and Linux users to use this book to create a game, because the game engine used—Torque—is also available for those platforms. However, not all of the required development tools are available on Mac and Linux, so the book’s focus will be on Windows on Intel.
System Requirements
Processor |
Pentium II/500MHz minimum |
Operating System |
Windows 98/ME/2000/XP |
Video Card |
3D graphics accelerated video card, NVidia GeForce 2–32MB |
|
equivalent or better |
Display |
17-inch recommended |
Input Devices |
keyboard and mouse |
Memory |
128MB minimum with 256MB recommended |
Hard Disk |
4GB minimum |
What the Book Offers
In this book we are going to look at all aspects of game development, a journey from first principles to the completed game.
Concepts
We are going to take a look at various aspects of the game industry to give you the opportunity to see where you might fit in and what sort of opportunities there are. We’ll also examine the elements of a 3D game, game design issues, and game genres.
Programming
Next, you’ll be introduced to the programming concepts that you will need to understand in the course of using the book. You will see how to structure program code, create loops, call functions, and use globally and locally scoped variables. We’ll use a subset of an object-oriented programming language called Torque Script, which is built into the
Team LRN
Introduction xxix
Torque Engine. Hands-on sample programs that you can try are available on the companion CD. We’ll move on to examining the 3D concepts that you will need to understand some of the more sophisticated activities later in the book. This will provide a foundation for both the programming and the modeling tasks that you will take on later.
Torque
Once you’ve been powered up with sufficient knowledge and understanding of the main concepts in 3D game development, we’ll get into using the Torque Engine in detail. You will learn how to handle client/server programming, how to control the player-character, how to send messages between players, how to create and control AI bots, and much more. Concepts will be presented with exercises and sample programs, which are available on the CD. Although we will cover some of the more intricate low-level workings of the Torque Engine in order to understand it better, it’s important to realize that as an independent game developer you’ll benefit more from mastering the higher-level functions that utilize the engine for us, so you can worry about other stuff—like game play. Without game play, you won’t have a game.
Textures
Next, the book will show you everything you need to know about game textures: how to create them, how to modify and manipulate them, and how to use them in the game. The coverage is comprehensive; all of the texture types and their uses are discussed: skins, tiles, terrain, skyboxes, height maps, GUI widgets, and more. You will be guided through exercises in creating each of the texture types. A library of textures is available on the companion CD to fill in any gaps in your texture needs.
Models
Then we get to the meat of a 3D game—the models. In these chapters we will be delving into the world of low-poly modeling. We’ll talk about the general principles involved in ways that can be applied to other tools, such as the expensive 3D MAX or Maya. But the practical focus will be geared toward using MilkShape, UVMapper, and other low-cost tools that are included on the companion CD.
I will show you the various model types, such as polygon-rendered or CSG models. You will create models for all aspects of the game in the exercises: player-characters, vehicles, weapons, powerups, decorations or clutter, buildings, and structures. You will walk through each step in the creation of the different model types so that you can create your own unique game look, if you want. All of the models in these chapters, plus many more, are available on the companion CD to round out your model library.
Team LRN