Game Programming in C Start To Finish 1st Edition Erik Yuzwa
Game Programming in C Start To Finish 1st Edition Erik Yuzwa
com
https://ebookname.com/product/game-programming-in-c-start-
to-finish-1st-edition-erik-yuzwa/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookname.com/product/successful-capital-campaigns-from-
start-to-finish-third-edition-scott-c-stevenson/
https://ebookname.com/product/wedding-videography-start-to-
finish-1st-edition-joanna-silber/
https://ebookname.com/product/windows-forms-programming-
with-c-1st-edition-erik-brown/
https://ebookname.com/product/infertility-around-the-globe-
professor-marcia-inhorn/
Tax Planning and Compliance for Tax Exempt
Organizations Rules Checklists Procedures Wiley
Nonprofit Law Finance and Management Series 4th Edition
Jody Blazek
https://ebookname.com/product/tax-planning-and-compliance-for-
tax-exempt-organizations-rules-checklists-procedures-wiley-
nonprofit-law-finance-and-management-series-4th-edition-jody-
blazek/
https://ebookname.com/product/the-maudsley-handbook-of-practical-
psychiatry-6th-edition-gareth-owen/
https://ebookname.com/product/the-fiction-of-relationship-arnold-
weinstein/
https://ebookname.com/product/scripps-whittier-diabetes-
institute-guide-to-patient-management-and-prevention-1st-edition-
athena-philis-tsimikas/
https://ebookname.com/product/artificial-psychology-the-quest-
for-what-it-means-to-be-human-1st-edition-jay-friedenberg/
Advances in Accounting Volume 20 20th Annv Edition
Philip M J Reckers
https://ebookname.com/product/advances-in-accounting-
volume-20-20th-annv-edition-philip-m-j-reckers/
GAME PROGRAMMING
IN C++:
START TO FINISH
Erik YuzwA
This book is
printed on acid-free paper.
Erik Yuzwa. Game Programming in C++:
ISBN: 1-58450-432-3
Start to Finish
All brand names and product names mentioned
in
this book are trademarks
respective companies. Any omission or misuse (of any kind) of service marks or service marks of their
or trademarks should not
be regarded as intent
toinfringe on the property of others. The publisher recognizes and
marks used by companies, manufacturers, and developers as means respects all
a to
distinguish their products.
Library of Congress Cataloging-in-Publication Data
Yuzwa, Erik.
Game programming in C++ start to finish / Erik Yuzwa.
p. cm.
Includes index.
ISBN 1-58450-432-3 (pbk. with cd : alk. paper)
1. Computer games—Programming. 2. C++ (Computer program language) I.
Title.
QA76.76.C672Y98 2005
005.13’3—dc22
2005032754
Printed in the United States of America
06765432
CHARLES RIVER MEDIA titles
are available for site license or bulk purchase by institutions, user
groups, corporations, etc. For additional information, please contact the Special Sales
Department
at 800-347-7707.
Requests for replacement of a
defective CD-ROM must be accompanied by the
mailing address, telephone number, date of purchase and purchase price. Please
original disc, your
state the nature of
the problem, and send the information to CHARLES RIVER MEDIA, 25
Thomson Place, Boston,
Massachusetts 02210. CRM’s sole obligation to the purchaser
materials or faulty workmanship, but not on the operation
is
to replace the disc, based on defective
or functionality of the product.
Contents
XixX
Acknowledgments
Preface
1 Game Technologies -
©
Using CVS
Creating the SuperAsteroidArena Project
OO
14
Introduction to Doxygen
16
Introduction to InnoSetup
23
The Standard Template Library
23
std::string
24
std::vector
25
std::map
27
Chapter Exercises
27
Summary
29
2 Design Fundamentals
29
What Is a Game Design?
30
Classic Waterfall Software Design
31
Iterative Software Design
32
Principles of Agile Design
:
33
When to Use Agile
33
Introduction to the Unified Modeling Language
Basic Class Notation 34
vi Contents
Visibility Notation 35
Comment/Note Notation 35
Modeling Class Relationships 36
Generalization Relationship 37
Software Reusability
38
Code Reuse
38
Design Reuse 38
Anatomy of a Game 44
Initialization Phase
44
Process Phase 45
Destruction Phase 46
The SuperAsteroidArena Design Document
46
Drafting a Project Overview 46
What Type or Genre of Game Is It? 47
Who Is Your Audience?
48
Why Make the Game? 49
What Do You Want To See? 49
What Does It Offer? 49
Draft an Initial List of Timeboxes
50
Who Is Involved? 51
Budget Concerns 51
Demo versus Registered Features
52
Chapter Exercises 53
Summary 53
Cleaning Up SDL
Big Endian versus Little Endian
Adding the FileLogger
Using Windows Initialization
Files
77
4 Introduction to the Peon Engine
77
Basic Engine Structure
79
Introduction to Peon
80
Introduction to Some Peon Components
82
Building Upon the Foundation
82
Managing State Information
83
Working on the First Timebox
85
Creating the New Instances of IApplicationState
86
Timebox Evaluation
86
Chapter Exercises
87
Summary
89
5 Graphics Programming Mathematics
89
The Cartesian Coordinate System
90
Fixed Function Geometry Pipeline
92
Introduction to Vectors
93
Common Vector Operations
95
Introduction to Matrices
95
The OpenGL Matrix Stacks
96
Identity Matrix
97
Matrix Addition and Subtraction
Contents
Matrix Multiplication 98
Coordinate Transformations 99
Scaling Transform 99
Translation Transform 99
Rotation Transform 100
Matrix Concatenation 102
Basic Camera/View Orientation 103
Projection Transformations 104
Create a Basic Camera 105
Gimbal Lock 106
:
Quaternions 107
Basic Quaternion Algorithm 108
Chapter Exercises 109
Summary 109
187
Rendering Text to the Player
187
Creating the Graphical User Interface
188
The ActiveState
188
Timebox Evaluation
189
Chapter Exercises
189
Summary
191
10 Working with Input Devices
191
Introduction to Input Using SDL
192
Using the Keyboard
193
Using the Mouse
195
Using the Joystick
195
Joystick Enumeration
196
Opening a Joystick
196
Processing Joystick Events
198
Cleaning up the Joystick
198
Adding Input Support to Peon
200
Chapter Exercises
200
Summary
201
Working With Sound
201
Sound Mechanics
202
Digitized Sound
202
Sound Layers
203
Introduction to SDL_Mixer
203
Working with Audio Music Data
206
Cleaning Up
206
Working with Audio Sound Effects Data
207
Sound Effect Playback
208
Cleaning Up
xii Contents
Plane Collisions
232
Collision of Plane versus AABB
232
Ray Collisions
233
Collision of Plane versus Ray
234
Implementing Physics
235
Using the neSimulator
237
Working with Geometry
238
Running the Simulation with Tokamak
238
Rendering the Geometry
239
Cleaning Up
240
Chapter Exercises
240
Summary
276
Rendering the Model 277
Cleaning Up 279
Model Animation
279
The MD3 File Format
280
The AnimatedMeshFactory
284
Introduction to Collada 284
Chapter Exercises 285
Summary 285
288
Extracting the Vectors
291
Skyboxes (Environment Mapping)
294
Object Picking/Selection
298
Particle Systems
300
Updating the Emitter
301
Rendering the Emitter
302
Particle System II: Point Sprites
305
Billboard Animation
306
Loading New Frames
307
Updating Frames
308
Creating a Shockwave
309
Initializing the Shockwave
310
Updating the Shockwave
311
Rendering the Shockwave
312
Taking a Screen Shot
314
Chapter Exercises
315
Summary
The barking came nearer, and Happy, Waddles, and Jack dashed
past Tommy and up the lane; at the same time he saw a riderless
horse in the outer field, and something seemed to move near the
barbed wire fence that ran between.
“It’s one of those poor hounds, and that wicked wire has caught
him,” cried Tommy, running toward the spot with his eyes flashing
and his little fists doubled up, for, like Anne, he could not bear to
have animals suffer pain.
But when he got near he saw that it was not a hound that was
caught by the wire, but Mr. Hugh! For an instant Tommy was
frightened, but as soon as he saw that his friend was not hurt, but
merely held fast by the clothes in a dozen places, the fun of the
situation struck him, and he capered about shouting, and making
comments, and asking questions, all in one breath.
“Ah, Mr. Hugh, you do look so funny! If only Anne were here with
her camera to take a picture! If you’ll wait long enough, I’ll go fetch
her, for you’re hooked up just like when Pinkie Scott reached after
lilies and fell in the pond, and they pulled her out from behind with
the hay-fork. Did the horse tumble you in like that?”
The truth was that Mr. Hugh had dismounted to let down some bars
for the people who had gone astray, and his horse, feeling fresh,
galloped off. In trying to head him off by a short cut, Mr. Hugh had
met the barbed wire fence, seen a gap between the strands, dashed
at it, only to be caught by a couple of slack wires when halfway
through, in such a position that if he let go the only hold he had
upon a half rotten post, he must fall upon a rusty coil that guarded
the tumble-down stone fence below. Barbed wire at best is cruel
stuff, and when it is old and rusty every scratch it gives means
danger.
“Stop bawling so, for pity’s sake, and see if you can help me out of
this mess before the others come; try to pry the wire with a stick,”
said Mr. Hugh, in so hoarse a whisper that Tommy instantly obeyed,
or rather tried to, but the sticks at hand were either too small or
rotten, and at every twist the poor man made the hooked wire
seemed to take new hold.
At this moment the snapping of twigs and the padding sound of
hoofs on grass made Mr. Hugh give a painful writhe to look over his
shoulder; his discomfiture was complete, for there was Miss Letty.
She slipped quickly to the ground, and tethering Brown Kate to a
branch, came forward, looking, as Tommy told Anne that night in the
privacy of his little bed, “the colour you feel when you’ve waited too
long for your breakfast.”
Seeing that Mr. Hugh had not been thrown, but was merely snared,
she pulled herself together and hesitated for a moment; while he,
putting on an air of bravado which was very funny under the
cramped circumstances, said: “Yes, here I am, and having parted
with my common sense I’m taking the consequences, and you have
your revenge. When all the party have had a good look at me, I
suppose some one will help me out.”
Miss Letty did not answer though she was afraid he would hear her
heart beat it was thumping so loudly, but looking about with a swift
glance spied Tommy’s gun that had fallen unnoticed in the grass.
Seizing it, she slipped it between the two furthest apart wires,
managing to catch a barb in the muzzle, and pried, while with the
handle of her riding crop she pulled back the two loose strands with
all her strength. There was a sound of tearing cloth, a pocket burst
open, throwing its contents in among the leaves, and Mr. Hugh
crawled out on his hands and knees, literally at Miss Letty’s feet. Just
as she stretched out her hand to help him, lest he slip backward,
one of the papers that Tommy was cramming back into the letter-
case caught her eye; it was the picture of herself that Anne had
taken, and which had disappeared as if by magic. Mr. Hugh, if it was
possible, turned redder than he was before he was released; but
Letty, with quiet tact, quickly unfastened Brown Kate and,
scrambling into the saddle by the aid of a stone at the fence corner,
cantered off in the opposite direction to where Mr. Hugh’s horse was
now quietly grazing.
For a minute the big man and the little one stood eying each other
curiously. Then Tommy broke the pause: “Now isn’t Miss Letty
common sensible and useful enough to be your sweetheart, Mr.
Hugh, even if she is pretty? And wouldn’t that red and black girl
have shouted if she’d seen you in the fence?”
“Yes, Tommy,” said Mr. Hugh, quietly; “you are a better judge than I
was; but Miss Letty does not wish to be the sweetheart of an old
bear like me.”
“No,” said Tommy, candidly, “I guess not, for I’ve heard her say you
were a bear, and so has Anne.” And though Tommy handed back the
letter book containing the picture without further comment, he had
seen, and when one has seen a thing, one can hardly unsee it again.
Mr. Hugh secured his horse and regained the road, Tommy riding in
front of him, before he overtook the others; and the beseeching look
that the big man gave the little one as he swung him to the ground
kept him quiet concerning the barbed wire episode, at least for some
hours.
The wedding was in May, exactly a year from the day of the poison
ivy luncheon. All Dogtown was invited, and filled the gray stone
church on the hillside to overflowing, even though the dogs attended
by proxy, except in a few rare cases. Laddie was one of these, for
Mrs. Carr never went without him, and he sat quietly beside her like
a little old man, with bent head and silvery locks.
Mrs. Carr herself was resplendent in a new black cloak, and a close
silk bonnet of the bride’s making took the place of the old pointed
hood. Her gift was her precious old Lowestoft teaset. “I’ve had my
pride o’ it,” she said, when Miss Jule had remonstrated with her, “and
when I gie a gift I like it o’ gude stuff.”
Anne was maid of honour, and Tommy wept bitterly because he
could not be best man. However, he managed to be quite prominent
as it was.
The day was perfect, and both the church and the quaint, low-
studded rooms at the Hilltop Farm were turned into gardens by the
great sprays and wreaths of white lilacs and dogwood with which
Miss Jule and the Happy Hall people had covered even the walls.
The dogs of all three families had been brushed, and their collars
decorated with immense bows of white ribbon; but they were
carefully locked up during the ceremony, to be ready to appear at
the breakfast, for if Waddles had gone near enough to the church to
have heard the organ play, his baying would have certainly brought
the wedding march to an untimely end.
As it was, all promised well, and as Miss Letty crossed the vine-
draped church porch, the people who watched thought that never
had there been a sweeter girl bride. On the side nearest to Anne a
dimple that would come and go, and threatened to end in a smile,
broke the seriousness of her face, and the cause of it was at first
hidden by the folds of her veil and train. It was Tip, the devoted
spaniel, who, climbing out of the window of the room where he was
prisoned, had dropped first to the porch and then the ground, and
caught up with the procession just in time to slip into the church
unnoticed, except by her he was following.
However, he
behaved like a
gentleman, and sat
sedately on the top
step during the
ceremony. This,
together with the
white bow he
wore, caused some
of the village
gossips, who were
not invited, to say
that the whole
thing was planned,
and was a disgrace
to the town; but
wise people know
that such remarks
are as much a part
of a wedding as
the ring and veil.
Tommy, who with his mother and father
occupied one of the front pews, crept out and drew gradually nearer
to where stood the family lawyer and friend, on whose arm the bride
had entered. In another moment he had climbed into a chancel chair
that was partly concealed by a column; from this place he had an
unimpeded view. It was the first time that the child had ever been to
a wedding, and the doings had all the fascination of entire novelty.
So when the clergyman, looking up, asked distinctly, “Who giveth
this woman to be married to this man?” Tommy shouted “Me!”
without the slightest suspicion that it was not what was expected of
him, adding indignantly to an usher who made haste to lift him
down, amid the natural ripple of laughter, “I had to, of course,
’cause she’d rather, and now she isn’t my sweetheart any more.”
The wedding breakfast was very jolly, at least everybody said so,
and all sorts of jokes were mingled with the congratulations. The
minister, who was very bashful, astonished himself by saying that he
was glad that they had finished with all the barbed wires of life
before the wedding, and then suddenly kissed the bride, amid
general applause.
The wedding cake boxes were white with initials, and a dog’s head,
Miss Jule’s crest, in silver. And the gossips had a second spasm when
they learned beyond dispute that there were souvenirs, of Miss
Letty’s invention, for all who owned dogs—small-sized Bologna
sausages wrapped in silver foil, and tied with white.
After it was all over,—and the bride had gone away, and the last
shoe been thrown, while Miss Jule was removing rice from her neck,
saying to a rather mournful relative, “Of course they will be happy,
they can’t help it, for they not only like but dislike the same
things,”—Tip appeared from upstairs with a crestfallen air, and in his
mouth a white slipper, one that his idol had just discarded, which
had dropped to the floor of her room.
Coming out on the porch, after several efforts he succeeded in
sitting upright, a trick Letty had taught him in imitation of Hamlet,
supporting his unsteady spine against the post. Then, as no Miss
Letty came to applaud him, he dropped the slipper on the step as a
challenge, and mounted guard over it until night came, when he
carried it with him to bed unchidden.
“Mistress,” said Waddles, as he sat watching her that night while she
put away her trinkets, and brushed and braided her hair, “I wish that
I hadn’t eaten so much of that round black lumpy cheese that Miss
Letty cut with the great knife.”
“So do I,” said Anne, with a sigh; “but then, Waddlekins, you see Mr.
Hugh and Miss Letty will never be married to each other again, and
we must be willing to bear a little pain inside for the sake of our
friends!”
Then the Mayor of Dogtown and Diana his mistress slept the sleep
of wedding cake, which is heavy with dreams!
Citizen Bird
Scenes from Bird-life in Plain English for a Beginner
By MABEL O. WRIGHT and Dr. ELLIOTT COUES
Profusely illustrated by Louis Agassiz Fuertes
Cloth. Crown 8vo. $1.50, net
“When two writers of marked ability in both literature
and natural history write to produce a work giving
scope to their special talents, the public has reason to
expect a masterpiece of its kind. In the ‘Citizen Bird,’
by Mabel O. Wright and Dr. Elliot Coues, this
expectation is realized—seldom is the plan of a book
so admirably conceived, and in every detail so
excellently fulfilled.”—The Dial.
“There is no other book in existence so well fitted for
arousing and directing the interest that all children feel
toward the birds.”—Tribune, Chicago.
Birdcraft
A Field-Book of Two Hundred Song, Game, and Water
Birds
By MABEL OSGOOD WRIGHT
With eighty full-page plates by Louis Agassiz Fuertes
“One of the best books that amateurs in the study of
ornithology can find ... direct, forcible, plain, and
pleasing.”—Chautauquan.
“Of books on birds there are many, all more or less
valuable, but ‘Birdcraft,’ by Mabel O. Wright, has
peculiar merits that will endear it to amateur
ornithologists.... A large number of excellent
illustrations throw light on the text and help to make a
book that will arouse the delight and win the gratitude
of every lover of birds.”—Saturday Evening Gazette,
Boston.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com