← Black Art of Macintosh Game Programming 1996

Black Art of Macintosh Game Programming 1996

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

Image 1

Black Art of MACINTOSH GAME PROGRAMMING

THE WAITE GROUP® Black Art of MACINTOSH GAME PROGRAMMING PROGRAMMING 3D GAMES IN MACINTOSH C INCLUDES CD-ROM The groundbreaking guide to writing professional 3D games for the Macintosh, featuring unprecedented demonstrations of freeform texture-mapping. WAITE GROUP PRESS™ KEVIN TIESKOETTER

A dark red textured book cover with gold and blue-gray ornamental metal corners, a shield-shaped CD-ROM badge on the left, a gem-and-scroll decorative motif in the center, and yellow and teal title typography.

Reading notes: Title lettering and small logo text on the cover are stylized; reading order follows visual layout from top to bottom.

Languages
English
PDF page 1

Black Art of MACINTOSH GAME PROGRAMMING

THE WAITE GROUP® Black Art of MACINTOSH GAME PROGRAMMING PROGRAMMING 3D GAMES IN MACINTOSH C INCLUDES CD-ROM The groundbreaking guide to writing professional 3D games for the Macintosh, featuring unprecedented demonstrations of freeform texture-mapping. WAITE GROUP PRESS™ KEVIN TIESKOETTER

A book cover with a dark red textured background, large gold serif title lettering, a shield-shaped CD-ROM badge on the left, a central gem ornament with blue stones, and ornate metal corner and key decorations.

Reading notes: Title line 'MACINTOSH' is set very large and the headline is split across several lines; line breaks are approximate to the layout. The 'KEVIN TIESKOETTER' author line is in teal over a red background and is legible but low contrast.

Printed product names
Black Art of Macintosh Game Programming
Languages
English
PDF page 2

The image is a entirely blank white portrait page with no visible artwork, layout elements, or text.

PDF page 3

PUBLISHER Mitchell Waite EDITOR-IN-CHIEF Charles Drucker ACQUISITIONS EDITOR Jill Pisoni EDITORIAL DIRECTOR John Crudo MANAGING EDITOR Kurt Stephan CONTENT EDITOR Lyn Cordell COPY EDITOR Deirdre McDonald Greene TECHNICAL REVIEWER Eduard Schwan PRODUCTION DIRECTOR Julianne Ososke PRODUCTION MANAGER Cecile Kaufman DESIGN Sestina Quarequio, Christi Fryday PRODUCTION Christi Fryday, Karen Johnston ILLUSTRATIONS Larry Wilson COVER ILLUSTRATION James Dowlen © 1996 by The Waite Group, Inc.• Published by Waite Group Press™. 200 Tamai Plaza. Corte Madera, CA 94925 Waite Group Press™ is a division of Sams Publishing. Waite Group Press™ is distributed to bookstores and book wholesalers by Publishers Group West. Box 8843, Emeryville, CA 94662, 1-800-788-3123 (in California 1-510-658-3453). All rights reserved. No part of this manual shall be reproduced, stored in a retrieval system. or transmitted by any means. electronic, mechanical, photocopying, desktop publishing, recording, or otherwise, without writ- ten permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. All terms mentioned in this book that are known to be trademarks, registered trademarks. or service marks are listed below. In addition. terms suspected of being trademarks. registered trademarks, or service marks have been appropriately capitalized. Waite Group Press cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark. registered trademark, or service mark. The Waite Group is a registered trademark of The Waite Group, Inc. Waite Group Press and The Waite Group logo are trademarks of The Waite Group, Inc. America Online is a registered service mark of America Online. Inc. Apple, Apple II, Macintosh. Quadra. and Power Macintosh are registered trademarks of Apple Computer. Irie. QuickDraw. Quicklime. ResEdit. and SimpleText are trademarks of Apple computer. Inc. CodeWarrior is a trademark of Metroworks. Inc. lnfini-D is a trademark of Specular International. Pentium is a trademark of Intel, Inc. Think C is a trademark of Symantec Corporation. All other product names are trademarks. registered trademarks, or service marks of their respective owners. Printed in the United States of America 96 97 98 99 • 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data Tieskoetter, Kevin. Black art of Macintosh game programming I Kevin Tieskoetter. p. cm. Includes index. ISBN 1-57169-059-X 1. Computer games--Programming. 2. Macintosh <Computerl--Programming. QA76.76.C642T54 1995 794.8' 1526--dc20 95-44225 CIP

Reading notes: Trademark and copyright notice lines contain spaced-out and irregular OCR-like text such as 'Irie' and 'Quicklime' that may be misreadings of Apple trademarks.

Printed dates
1996 · 1995 · 96 · 97 · 98 · 99 · 10 · 9 · 8 · 7 · 6 · 5 · 4 · 3 · 2 · 1
Languages
English
PDF page 4

The image is a plain, entirely white page with no visible artwork, layout, or markings.

PDF page 5

WELCOME TO OUR NERVOUS SYSTEM

Message from the Publisher WELCOME TO OUR NERVOUS SYSTEM Some people say that the World Wide Web is a graphi cal extension of the information superhighway, just a network of humans and mac hines sending each other long lists of the equivalent of digital junk mail. I think it is much more than that. To me the Web is nothing less than the nervous system of the entire planet-not just a collection of computer brains connected togeth- er, but more like a billion silicon neurons entangled and reci rculati ng electro-chemical signals of information and data , eac h contributing LO th e birth of another CPU and another Web site. Think of each person 's hard disk connected at once to every other hard disk on earth , driven by human navigators searching like Columbus for the New World. Seen this way the Web is more of a super entity, a growin g, living thing, controlled by the uni ve rsal human will to ex pand, to be more. Yet unlike a purposeful business plan with rigid rules, the Web expands in a nonlinear, unpredictable, creative way that echoes natural evolution. We created our Web site not just to extend the reach of our computer book products but to be part of this synaptic neural network, to experience, like a nerve in the body, the flow of ideas and then to pass those ideas up the food chain of the mind . Your mind. Even more, we wanted to pump some of our own creative juices into this rich wine of technology. TASTE OUR DIGITAL WINE And so we ask you to taste our wine by visiting the body of our business. Begin by understanding the metaphor we have created for our Web site-a unive rsal learning center, situated in outer space in the form of a space stati on. A place where you can journey to study any topic from the convenience of your own screen. Right now we are focusing on computer topics, but the stars are the limit on the Web. If you are interested in discussing this Web site, or finding out more about the Waite Group, please send me email with your comments and l wi ll be happy to respond. Being a prograrmmer myself, I love to talk about technology and find out what our readers are looking for. Sincerely, Mitchell Waite, C.E.O. and Publisher

Reading notes: Line-break hyphenation and spacing irregularities in the body text, such as 'graphi cal', 'mac hines', and 'reci rculati ng', may reflect OCR artifacts.

Printed product names
Waite Group
Languages
English
PDF page 6

Come Visit Waite Group Press World Wide Weli Site n.-o~----~~---wo•~• ~~:i::r1cc'*..~~=r~·-jl!ill., .. ~ ~~€e=:~e:~~==~= ~~Adftloib,bQ~ ... ,.,._~tlilrll ... -lllJ.-, =~:e~i·5":l£i!:£5~: ---.lil' ... ,,,.,. __ loeli)Cl"' ........ ,_, •• ..__,...AM.11. -=- ... --~Ol--ol-)\OP_,....,_..,.~,, Now find all the latest information on Waite Group books at .our new ~"'.:l"-4::!'~,,:,;.;-~:g;.,..-·-.,. ,.....,,.,.,...,..MhJM..ctlb~ Web site , http://www.waite.com/waite. You'll find an online catalog ~---·~---""~""'---·--·~·-- _. where you can examine and order any title, review upcoming books, and send email to our authors and editors. Our ftp site has all you need to update your book: the latest program listings, errata sheets, most recent versions of Fractint, POV Ray, Polyray, DMorph, and all the programs featured in our books. So down- load , talk to us, ask questions, on http://www.waite.com/waite.li .. - ' The Backlist Room has all our books listed alphabetically. The People Room is where you'll interact with Waite Group employees Links to Cyberspace get you in touch with other computer book publishers and other interesting Web sites. I L- The FTP site contains all program listings, erroto sheets, etc. The Order Room is where you can order any of our books online. The Subject Room contains typical book pages which show description, Index, Tobie of Contents, and links to authors.

Reading notes: OCR garbling in the upper header and sidebar text Reading order of room descriptions is uncertain

Printed product names
Fractint · POV Ray · Polyray · DMorph
Languages
English
PDF page 7

\ , r Kevin Tieskoetter spent a short time at Drake University in Des Moines, Iowa, and worked in Des Moines at MicroFrontier, Inc ., on Color ltl , an image processing application for the Macintosh. He is now a software engineer at Specular International, working on products such as InfiniD, a 3D modeling and animation package, and Collage, an image composition tool for graphics professionals. He spends his free time researching methods of procrastinating getting real work done . Regrettably, he does not own a cat, nor is he owned by one.

Reading notes: Possible OCR spacing artifacts in 'Color ltl' and 'Inc .' and 'done .'

Printed product names
Color ltl · InfiniD · Collage
Languages
English
PDF page 8

Introduction ......... . . . . . . ... . . .. .... ..... ..... .. .. . . . ........... xxi About the CD-ROM ... ..... . . . . ... . . . ... . .. ... . ...... . . ............ xxiii Chapter 1 Games and the Macintosh . . . ... ... .. .. . . . . . ................. 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Opening the Toolbox: Macintosh Programming Basics .... ........ 11 More about the Toolbox . . . ...... . . . . . ..... . .... .... .. ... . . . 45 Mathematics of Art . ... .... .. . . ... . . ..... . . ....... . . ...... 77 Sprite Animation ........ . ... .. . . .... .................... 119 Talking to the Computer . ... ... .. ... . ..... .. . ....... . ... . . 155 Listening to the Computer . ........ ...... .................. 181 Chapter 8 Invaders! .. . . . . . . . ..... ..... . . ....... ....... ... . . ... ... 227 Chapter 9 Wireframe Graphics .... .. ... ..... ... . ..... . . . ... . . ... . . . 269 Chapter 10 Three-Dimensional Graphics . ... .. .............. .. .... ... . . 305 Chapter 11 Polygon-Fill Graphics .... . ..... . .............. . .. ...... . . 339 Chapter 12 Optimization . . ........ ....... . ... .............. . ... . . .. 387 Chapter 13 Accelerating and Bypassing QuickDraw . ........ .... . . .. ..... 433 Chapter 14 Optimizing Power Macintosh . .............................. 463 Chapter 15 Hidden Surface Removal . .. ..... . . ....... . .. ... .. . . ... .. . . 491 Chapter 16 Po·lygon Clipping ........ . . . . ... ... . ... . . . . ....... . ..... . 525 A Chapter 1'7 Viewing the World . . ... . . . . ....... . . ..... . ... . . . . . ..... .. 569 ' Chapter 18 Three-Dimensional Mazes . .. . . . ..... . . . . . . . .. . . . ..... . . .. . 601 Chapter 19 Texture Mapping ... ..... . . . . .. . . .. ... . . ..... . . . . . ... . .. . 629 1 Cha~t~r 20 Graphics in Flight . . ..... . ... . ....................... . ... 689 Chapter 21 Game Marketing and Distribution . .......................... 751 Chapter 22 The Future of 3D Games . . .. . ..... . . . . . . . ............. . . . . 765 Appendix A Recommended Reading .. .... .. ... ... . . . ..... . . .. ....... . . 777 Index . . . ... . . . . ............... . ....... .......... ......... . . . .... 779 vi.i

Reading notes: OCR fragments in chapter list, e.g. 'Po·lygon' and '1 Cha~t~r' may be misread

Languages
English
PDF page 9

Introduction .. . ... . ....... ... ......... .... . .... . . . ... . .. .......... xxi About the CD-ROM ... ....................................... . . . ... xxiii Chapter 1: Games and the Macintosh . . . . .. .. . ..... . ..... .. ....... . . . .... 1 Graphics and Games .......... . . .. ... ...... . ... .. . . .. . . . ... . . ... . .. 5 The Macintosh: Made for Graphics . ... . ... . ........ . . . ... . . . .. . .. . 5 Mapping Color Images ........ . . .. ... . .. . ..... .. . . .... .. . . . . .. . . 6 The Color Palette .. .. . ............ .. ... . .. . . ... ... . . .. .... . . .. . 6 Creating the Screen Image .. ... ... . . . . ... .. . ... . ... ... . . . . . .. . .... . . 8 Video Memory ... .. ........ . . . . ... . . . . . .... . . . .... . ....... . ... 8 QuickDraw: Friend and Enemy of the Game Programmer . . . ....... . ... 9 Creating the Graphics . ........ . . . . ...... . . . . . ... . . . . ....... . .. 10 Opening the Toolbox: Macintosh Programming Basics .......... . .. 11 Building a Window ...... . . .. . ... . .. .. .. .. . ......... . . ........... . 14 Chapter 2: I The Window Manager . ... . . . .. . . .. . . . .. ... . .... . ..... . ........ 14 The Event Manager ........ .. . .. .. . .. . . . ...... . .... . ....... . .. 16 Putting the Event Loop Together .. . . . . . .. . . . . ... . ..... . .. . .. . . . .. 23 The Simple Window Application .... . . . .. .... .. .. . . ..... . . ...... . . . . 24 Building a Menu .... . ... . .. ... .. . . .. ... .. . . . ..... . . . .. . . .. . . .. . . . 27 The Menu Manager . . .... . . . ..... . . .. . . .... . .. . ... . . .. .. . .. ... 27 Input from the Menus .. .... . . .... . . .. . . ...... . .. . ....... . . . . . . 28 The Disappearing Window Application .. . .. . ..... . .. . . . . .. .. . .. ... 30 Calling on QuickDraw . ........ . . .. . .... . . . . .. ... . . .......... . .. . . 34 The QuickDraw Package .. . . . . . . . . . .. . .. . ... .. . .. . . . . .. . . .. . . .. 35 Generating Random Numbers . ... . .. .... . . . .... . . . .. .. ... . .. . ... 37 The Shape-Drawing Application ... . ... . ........ . .... . .. . . . . . . ... 38 -~-

Reading notes: Table of contents text contains irregular spacing and a stray 'I' near Chapter 2 heading, so reading order may be imperfect.

Printed product names
Macintosh · QuickDraw · CD-ROM
Languages
English
PDF page 10

\/,,,~~ +++++ Bkck Art of Macmtosh 6ame Programming >~<~\¥::::,<: ·,\ , \>' \' "\,"'< ,.:<>(\ . Chapter 3: More about the Toolbox . ........................... ,>(. :;,.,;·<~ '._>4~. >< > x Getting a Handle on Memory .............................. <\ .. ,\:,'\,_\(7\.)-<'.\ · Introducing the Handle ............................... : : \. ; \: \.49: .'<· ". ). _,., \ \,··· \ )<' \ ,/\., What Goes On behind the Scenes .......................... )•( ·>·· ~1 .\>\ \< Creating and Releasing Handles .............................. · \: . \52_ ).·/\, " The Re~ource Ma.nager ........................................ _,;\'.v.)>,3,,.,\)':~'~\· Usmg ~esEdit ............................................. :·. \?1'.:: )<\ .. > Accessmg Resources ......................................... :·. 5-9·<, )/ \ . Bitmaps and PICT Files............................................ ·'5!-.,>\ ,,\,.,'. Using the Macintosh File System .................................... 59 ,\,,,\ _)( . ·1 .. \ /\ \, Opening F1 es ................................................ 61 ,,·\ \·"'\ Reading and Writing Data Forks ................................. 63 ,)( •" Reading Resource Forks ........................................ 64 ><: ,.· w 1 riting a Re 1 source ............................................ 64 />< C osing a Fi e ................................................ 65 The PICT Viewer Application ....................................... 65 Chapter 4: Mathematics of Art ........................................ 77 Cartesian Coordinates ............................................. 79 The Cartesian Plane ........................................... 80 Geometry Meets Algebra ....................................... 81 Coordinates on the Computer ...................................... 85 Coordinates to Pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 86 How Images Are Stored ........................................ 88 The PixMap Structure ......................................... 90 Using the PixMap Structure to Access the Image .................... 92 Moving the Origin ............................................ 93 Accessing Multiple Pixels ...................................... 94 Into the Third Dimension .......................................... 94 Shapes, Solids, and Coordinates ..................................... 97 Three-Dimensional Vertices ..................................... 99 Graphing Equations .......................................... 102 Solving the Equation ......................................... 103 Fractals .................................................... 104 Transformations ................................................ 105 Translating ................................................. 105 Scaling .................................................... 106 Rotating on X, Y, and Z ....................................... 106 Matrix Algebra ................................................. 112 Building Matrices ............................................ 112 Multiplying Matrices ......................................... 113 Three Kinds of Rotation Matrices ............................... 117 Floating-Point Math ............................................. 118

Reading notes: Table of contents text is heavily damaged with stray characters and misaligned page numbers Reading order of some entries is uncertain due to OCR fragmentation

Languages
English
PDF page 11

x Black Art of Macintosh G-ame Programming +++++ Chapter 5: Sprite Animation . ........................................ 119 Motion Pictures for the Computer Screen ............................ 122 Bitmaps in Motion ............................................... 124 Graphical Worlds ............................................... 125 Creating the Offscreen Image................................... 126 Showing the Off screen Bitmap .................................. 128 The Walking Sprites ............................................. 130 A Structure for Sprites ........................................ 135 Sprite Manipulation .......................................... 136 The Walking Man Routines .................................... 14 2 The main() Routine .......................................... 150 Meet the Animated Gentleman ..................................... 153 Chapter 6: Talking to the Computer ................................... 155 Where Did the Mouse Go? ........................................ 157 Keyboard Input ................................................. 159 The GetKeys() Alternative ..................................... 159 Breaking the Key Code ........................................ 161 Directly Supporting joysticks ...................................... 164 ADB Drivers ................................................ 165 The ThrustMaster Interface .................................... 165 The MouseStick Interface ...................................... 167 Improving the Walking Man Animation .............................. 169 Checking Menu Items ........................................ 170 The Walking Man 2 Code ..................................... 170 Using Walking Man 2 ............................................ 179 Chapter 7: Listening to the Computer . ................................. 181 Components of Sound ........................................... 184 The Sound of Sine ........................................... 185 Sawtooth Waves and Square Waves .............................. 185 Complex Sounds ............................................ 185 Modern Equipment and Sound ..................................... 186 A Computer's Representation of Sound .............................. 187 Synthesizers ................................................ 188 Sound Channels ............................................. 189 Synchronous Sound ............................................. 191 Asynchronous Sound ............................................ 192 Has the Sound Finished? ...................................... 193 Sending Signals ............................................. 193 Creating the Asynchronous Sound .................................. 194 Asynchronous Sound Player ................................... 196 Using the Asynchronous Player ................................. 198 Continuous Sound .............................................. 199

Reading notes: Table of contents text contains irregular spacing and hyphenation (e.g., 'G-ame', 'Off screen'), possibly from extraction.

Languages
English