page bitmap offscreen

dllgdx2000 2011-03-11 11:26:58
描述:
在一个page上生成一个1024*1024的bitmap,
手机的屏幕只显示bitmap的一部分,
A 当手机的屏幕在1024*1024的bitmap内部拖动时,
不通知C++重绘bitmap,
B 当手机的屏幕托出1024*1024的bitmap时,
通知C++重绘一个新的1024*1024的bitmap
bitmap的中心显示在手机屏幕上

问题:
重绘的bitmap坐标怎么确定?
bitmap的中心显示在手机屏幕上的坐标怎么确定?
m_doc.drawPageSlice(m_cache_canvas, m_current_page, m_offset.x, m_offset.y, this.docWidth, this.docHeight);
m_offset.x, m_offset.y 就是起始坐标
page、新bitmap、屏幕的各个坐标换算怎么计算
纯新手 望各位高手指教!!
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
念茜 2011-03-13
  • 打赏
  • 举报
回复
我只能帮顶 不会
About this manual 13 Using this manual..14 Accessing ActionScript documentation15 ActionScript learning resources.. 17 Chapter 1: Introduction to ActionScript 3.0.. 19 About ActionScript..19 Advantages of ActionScript 3.0.20 What’s new in ActionScript 3.0.. 21 Core language features...21 Flash Player API features...23 Compatibility with previous versions24 Chapter 2: Getting started with ActionScript..27 Programming fundamentals27 What computer programs do..27 Variables and constants...28 Data types...29 Working with objects.. 31 Properties...31 Methods32 Events33 Basic event handling...34 Examining the event-handling process... 35 Event-handling examples.. 39 Creating object instances...40 Common program elements..42 Example: Animation portfolio piece44 Building applications with ActionScript.47 Options for organizing your code48 Choosing the right tool...50 The ActionScript development process 51 Creating your own classes...53 Strategies for designing a class. 53 Writing the code for a class..54 4 Suggestions for organizing your classes...56 Example: Creating a basic application 56 Running subsequent examples.. 63 Chapter 3: ActionScript language and syntax.67 Language overview..68 Objects and classes.69 Packages and namespaces... 70 Packages...70 Namespaces..75 Variables83 Data types87 Type checking..88 Dynamic classes..93 Data type descriptions94 Type conversions.97 Syntax 103 Operators 109 Conditionals...117 Looping119 Functions 122 Basic function concepts... 122 Function parameters 128 Functions as objects 134 Function scope.135 Chapter 4: Object-oriented programming in ActionScript.137 Basics of object-oriented programming 138 Classes140 Class definitions..141 Class property attributes... 144 Variables...147 Methods...148 Enumerations with classes..156 Embedded asset classes...158 Interfaces 158 Inheritance162 Advanced topics..171 Example: GeometricShapes..180 5 Chapter 5: Working with dates and times... 191 Basics of dates and times191 Managing calendar dates and times193 Controlling time intervals196 Example: Simple analog clock...199 Chapter 6: Working with strings203 Basics of strings.. 204 Creating strings... 205 The length property. 207 Working with characters in strings208 Comparing strings.208 Obtaining string representations of other objects.209 Concatenating strings209 Finding substrings and patterns in strings210 Converting strings between uppercase and lowercase215 Example: ASCII art..216 Chapter 7: Working with arrays223 Basics of arrays... 223 Indexed arrays...225 Associative arrays.234 Multidimensional arrays...239 Cloning arrays...241 Advanced topics..241 Example: PlayList..247 Chapter 8: Handling errors. 253 Basics of error handling...254 Types of errors..257 Error handling in ActionScript 3.0259 ActionScript 3.0 error-handling elements..260 Error-handling strategies...261 Working with the debugger version of Flash Player.261 Handling synchronous errors in an application.. 262 Creating custom error classes.. 267 Responding to error events and status268 6 Comparing the Error classes...272 ECMAScript core Error classes..272 ActionScript core Error classes.275 flash.error package Error classes276 Example: CustomErrors application278 Chapter 9: Using regular expressions...285 Basics of regular expressions..286 Regular expression syntax288 Creating an instance of a regular expression..289 Characters, metacharacters, and metasequences 290 Character classes.293 Quantifiers..295 Alternation...297 Groups297 Flags and properties. 301 Methods for using regular expressions with strings.305 Example: A Wiki parser...306 Chapter 10: Handling events313 Basics of handling events...314 How ActionScript 3.0 event handling differs from earlier versions317 The event flow..320 Event objects...322 Event listeners...327 Example: Alarm Clock335 Chapter 11: Working with XML343 Basics of XML..344 The E4X approach to XML processing348 XML objects... 350 XMLList objects...353 Initializing XML variables354 Assembling and transforming XML objects356 Traversing XML structures...358 Using XML namespaces363 XML type conversion.364 Reading external XML documents.366 Example: Loading RSS data from the Internet..367 7 Chapter 12: Display programming371 Basics of display programming.372 Core display classes377 Advantages of the display list approach 379 Working with display objects..382 Properties and methods of the DisplayObject class...382 Adding display objects to the display list... 383 Working with display object containers...383 Traversing the display list..387 Setting Stage properties..389 Handling events for display objects392 Choosing a DisplayObject subclass393 Manipulating display objects..395 Changing position395 Panning and scrolling display objects 400 Manipulating size and scaling objects402 Controlling distortion when scaling 403 Caching display objects... 405 When to enable caching.. 406 Enabling bitmap caching.. 408 Setting an opaque background color...409 Applying blending modes...409 Adjusting DisplayObject colors..410 Setting color values with code411 Altering color and brightness effects with code.412 Rotating objects..413 Fading objects..413 Masking display objects...414 Animating objects...416 Loading display content dynamically418 Loading display objects...419 Monitoring loading progress.420 Specifying loading context..421 Example: SpriteArranger...423 Chapter 13: Working with geometry431 Basics of geometry.431 Using Point objects. 434 Using Rectangle objects436 Using Matrix objects440 Example: Applying a matrix transformation to a display object.442 8 Chapter 14: Using the drawing API...447 Basics of using the drawing API..448 Understanding the Graphics class450 Drawing lines and curves...450 Drawing shapes using built-in methods453 Creating gradient lines and fills..454 Using the Math class with drawing methods..460 Animating with the drawing API.461 Example: Algorithmic Visual Generator462 Chapter 15: Filtering display objects...465 Basics of filtering display objects..465 Creating and applying filters...467 Creating a new filter467 Applying a filter..467 How filters work..470 Potential issues for working with filters470 Available display filters472 Bevel filter473 Blur filter474 Drop shadow filter..474 Glow filter...475 Gradient bevel filter.476 Gradient glow filter477 Example: Combining basic filters478 Color matrix filter. 480 Convolution filter.481 Displacement map filter484 Example: Filter Workbench...490 Chapter 16: Working with movie clips 491 Basics of movie clips491 Working with MovieClip objects.. 494 Controlling movie clip playback.494 Working with scenes497 Creating MovieClip objects with ActionScript.. 498 Exporting library symbols for ActionScript..498 Loading an external SWF file..501 Example: RuntimeAssetsExplorer503 9 Chapter 17: Working with text 509 Basics of working with text510 Displaying text513 Types of text...513 Modifying the text field contents.514 Displaying HTML text514 Using images in text fields...515 Scrolling text in a text field...516 Selecting and manipulating text..517 Capturing text input.518 Restricting text input520 Formatting text..520 Assigning text formats521 Applying cascading style sheets..521 Loading an external CSS file..523 Formatting ranges of text within a text field... 524 Advanced text rendering525 Working with static text528 Example: Newspaper-style text formatting... 529 Reading the external CSS file.530 Arranging story elements on the page...532 Altering font size to fit the field size533 Splitting text across multiple columns535 Chapter 18: Working with bitmaps539 Basics of working with bitmaps..540 The Bitmap and BitmapData classes543 Manipulating pixels.. 545 Manipulating individual pixels.545 Pixel-level collision detection.547 Copying bitmap data549 Making textures with noise functions550 Scrolling bitmaps.552 Example: Animating sprites using an offscreen bitmap...553 Chapter 19: Working with video555 Basics of video..556 Understanding the Flash Video (FLV) format..559 Understanding the Video class.560 Loading video files..561 Controlling video playback... 562 Detecting the end of a video stream563 10 Streaming video files.564 Understanding cue points...565 Writing callback methods for onCuePoint and onMetaData..566 Set the NetStream object’s client property to an Object...567 Create a custom class and define methods to handle the callback methods.568 Extend the NetStream class and add methods to handle the callback methods569 Extend the NetStream class and make it dynamic570 Set the NetStream object’s client property to this.572 Using cue points..572 Using video metadata.573 Capturing camera input 577 Understanding the Camera class577 Displaying camera content on-screen578 Designing your camera application.578 Connecting to a user’s camera..578 Verifying that cameras are installed.579 Detecting permissions for camera access..580 Maximizing video quality...582 Monitoring playback conditions..583 Sending video to a server...584 Advanced topics..585 Flash Player compatibility with encoded FLV files585 About configuring FLV files for hosting on a server585 About targeting local FLV files on the Macintosh.586 Example: Video Jukebox587 Chapter 20: Working with sound 595 Basics of working with sound.. 596 Understanding the sound architecture599 Loading external sound files..600 Working with embedded sounds. 603 Working with streaming sound files 604 Playing sounds..605 Pausing and resuming a sound606 Monitoring playback.607 Stopping streaming sounds.609 Security considerations when loading and playing sounds..609 Controlling sound volume and panning.611 Working with sound metadata.. 613 Accessing raw sound data 614 Capturing sound input617 11 Accessing a microphone... 617 Routing microphone audio to local speakers...619 Altering microphone audio...619 Detecting microphone activity. 620 Sending audio to and from a media server621 Example: Podcast Player...622 Reading RSS data for a podcast channel..623 Simplifying sound loading and playback using the SoundFacade class.623 Displaying playback progress.627 Pausing and resuming playback.628 Extending the Podcast Player example...629 Chapter 21: Capturing user input.631 Basics of user input.631 Capturing keyboard input...633 Capturing mouse input 636 Example: WordSearch641 Chapter 22: Networking and communication645 Basics of networking and communication...646 Working with external data...649 Connecting to other Flash Player instances...656 Socket connections. 662 Storing local data.668 Working with file upload and download671 Example: Building a Telnet client. 682 Example: Uploading and downloading files... 685 Chapter 23: Client system environment..695 Basics of the client system environment695 Using the System class 698 Using the Capabilities class..699 Using the ApplicationDomain class700 Using the IME class. 704 Example: Detecting system capabilities 709 12 Chapter 24: Printing... 715 Basics of printing..716 Printing a page..718 Flash Player tasks and system printing719 Setting size, scale, and orientation.722 Example: Multiple-page printing.725 Example: Scaling, cropping, and responding..727 Chapter 25: Using the external API...731 Basics of using the external API..732 External API requirements and advantages...735 Using the ExternalInterface class..736 Getting information about the external container737 Calling external code from ActionScript...737 Calling ActionScript code from the container...739 The external API’s XML format.740 Example: Using the external API with a web page container..742 Example: Using the external API with an ActiveX container..749 Chapter 26: Flash Player security757 Flash Player security overview..758 Overview of permission controls.760 Security sandboxes.. 770 Restricting networking APIs..773 Full-screen mode security...775 Loading content... 776 Cross-scripting...779 Accessing loaded media as data.783 Loading data786 Loading embedded content from SWF files imported into a security domain..788 Working with legacy content..789 Setting LocalConnection permissions.790 Controlling access to scripts in a host web page..790 Shared objects...792 Camera, microphone, clipboard, mouse, and keyboard access.794
Tricks of the Windows video Game Programming

PART I Windows Programming Foundations 7
1 Journey into the Abyss 9
A Little History........................................................................................9
Designing Games ..................................................................................13
Types of Games ....................................................................................13
Brainstorming........................................................................................14
The Design Document and Storyboards................................................15
Making the Game Fun ..........................................................................16
The Components of a Game..................................................................16
Section 1: Initialization....................................................................17
Section 2: Enter Game Loop............................................................17
Section 3: Retrieve Player Input ......................................................17
Section 4: Perform AI and Game Logic ..........................................17
Section 5: Render Next Frame ........................................................18
Section 6: Synchronize Display ......................................................18
Section 7: Loop................................................................................18
Section 8: Shutdown ........................................................................18
General Game Programming Guidelines ..............................................21
Using Tools............................................................................................26
C/C++ Compilers ............................................................................26
2D Art Software................................................................................26
Sound Processing Software..............................................................26
3D Modelers ....................................................................................26
Music and MIDI Sequencing Programs ..........................................27
Setting Up to Get Down—Using the Compiler ....................................27
An Example: FreakOut..........................................................................29
Summary................................................................................................46
2 The Windows Programming Model 47
The Genesis of Windows ......................................................................48
Early Windows Versions ..................................................................48
Windows 3.x ....................................................................................48
Windows 95......................................................................................49
Windows 98......................................................................................50
Windows NT ....................................................................................50
Basic Windows Architecture:Win9X/NT........................................50
Multitasking and Multithreading ..........................................................51
Getting Info on the Threads ............................................................52
The Event Model..............................................................................53

0072313618 FM 10/26/99 9:32 AM Page vi
vi
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Programming the Microsoft Way: Hungarian Notation........................55
Variable Naming ..............................................................................56
Function Naming..............................................................................56
Type and Constant Naming..............................................................57
Class Naming....................................................................................57
Parameter Naming............................................................................58
The World’s Simplest Windows Program..............................................58
It All Begins with
WinMain() ..........................................................59
Dissecting the Program....................................................................60
Choosing a Message Box ................................................................63
Real-World Windows Applications (Without Puck)..............................66
The Windows Class ..............................................................................66
Registering the Windows Class ............................................................74
Creating the Window ............................................................................75
The Event Handler ................................................................................77
The Main Event Loop............................................................................84
Making a Real-Time Event Loop..........................................................89
Opening More Windows........................................................................90
Summary................................................................................................93
3 Advanced Windows Programming 95
Using Resources....................................................................................96
Putting Your Resources Together ....................................................98
Using Icon Resources ......................................................................99
Using Cursor Resources ................................................................102
Creating String Table Resources....................................................106
Using Sound
.WAV Resources ........................................................108
Last, But Not Least—Using the Compiler to Create
.RC Files ....114
Working with Menus ..........................................................................116
Creating a Menu ............................................................................116
Loading a Menu..............................................................................119
Responding to Menu Event Messages ..........................................122
Introduction to GDI ............................................................................128
The
WM_PAINT Message Once Again ..............................................128
Video Display Basics and Color....................................................133
RGB and Palletized Modes............................................................135
Basic Text Printing ........................................................................137
Handling Important Events..................................................................143
Window Manipulation....................................................................143
Banging on the Keyboard ..............................................................150
Squeezing the Mouse......................................................................158
Sending Messages Yourself ................................................................161
Summary..............................................................................................163

0072313618 FM 10/26/99 9:32 AM Page vii
vii
CONTENTS
4 Windows GDI, Controls, and Last-Minute Gift Ideas 165
Advanced GDI Graphics......................................................................166
Under the Hood with the Graphics Device Context......................166
Color, Pens, and Brushes................................................................167
Working with Pens ........................................................................168
Painting with Brushes ....................................................................172
Points, Lines, Polygons, and Circles ..................................................173
Straight to the Point........................................................................173
Getting a Line on Things................................................................175
Getting Rectangular........................................................................177
Round and Round She Goes—Circles ..........................................180
Polygon, Polygon,Wherefore Art Thou, Polygon? ......................181
More on Text and Fonts ......................................................................182
Timing Is Everything ..........................................................................184
The
WM_TIMER Message ..................................................................184
Low-Level Timing..........................................................................187
Playing with Controls..........................................................................190
Buttons............................................................................................191
Sending Messages to Child Controls ............................................195
Getting Information ............................................................................197
The T3D Game Console......................................................................205
Summary..............................................................................................210
PART II DirectX and 2D Fundamentals 211
5 DirectX Fundamentals and the Dreaded COM 213
DirectX Primer ....................................................................................214
The HEL and HAL ........................................................................216
The DirectX Foundation Classes in Depth ....................................216
COM: Is It the Work of Microsoft… or Demons?..............................218
What Exactly Is a COM Object?....................................................219
More on Interface IDs and GUIDs ................................................223
Building a Quasi-COM Object ......................................................224
A Quick Recap of COM ................................................................226
A Working COM Program ............................................................226
Working with DirectX COM Objects..................................................231
COM and Function Pointers ..........................................................232
Creating and Using DirectX Interfaces..........................................236
Querying for Interfaces..................................................................237
The Future of COM ............................................................................238
Summary..............................................................................................239

0072313618 FM 10/26/99 9:32 AM Page viii
viii
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
6 First Contact: DirectDraw 241
The Interfaces of DirectDraw..............................................................242
Interface Characteristics ................................................................242
Using the Interfaces Together ........................................................244
Creating a DirectDraw Object ............................................................245
Error Handling with DirectDraw....................................................246
Getting an Interface Lift ................................................................247
Cooperating with Windows ................................................................250
Getting into the Mode of Things ........................................................255
The Subtleties of Color........................................................................259
Building a Display Surface..................................................................263
Creating a Primary Surface............................................................264
Attaching the Palette......................................................................272
Plotting Pixels ................................................................................272
Cleaning Up....................................................................................284
Summary..............................................................................................285
7 Advanced DirectDraw and Bitmapped Graphics 287
Working with High-Color Modes........................................................288
16-Bit High-Color Mode................................................................289
Getting the Pixel Format................................................................290
24/32-Bit High-Color Mode ..........................................................299
Double Buffering ................................................................................301
Surface Dynamics................................................................................307
Page Flipping ......................................................................................311
Using the Blitter ..................................................................................317
Using the Blitter for Memory Filling ............................................320
Copying Bitmaps from Surface to Surface....................................328
Clipper Fundamentals..........................................................................332
Clipping Pixels to a Viewport ........................................................332
Clipping Bitmaps the Hard Way....................................................334
Making a DirectDraw Clip with
IDirectDrawClipper..................339
Working with Bitmaps ........................................................................345
Loading
.BMP files..........................................................................345
Working with Bitmaps....................................................................352
Loading an 8-Bit Bitmap................................................................353
Loading a 16-Bit Bitmap................................................................354
Loading a 24-Bit Bitmap................................................................355
Last Word on Bitmaps....................................................................356
Offscreen Surfaces ..............................................................................356
Creating Offscreen Surfaces ..........................................................356
Blitting Offscreen Surfaces............................................................358
Setting Up the Blitter......................................................................359
Color Keys......................................................................................360
Source Color Keying......................................................................361

0072313618 FM 10/26/99 9:32 AM Page ix
ix
CONTENTS
Destination Color Keying ..............................................................364
Using the Blitter (Finally!) ............................................................365
Bitmap Rotation and Scaling ..............................................................366
Discrete Sampling Theory ..................................................................368
Color Effects........................................................................................373
Color Animation in 256-Color Modes ..........................................373
Color Rotation in 256-Color Modes..............................................379
Tricks with RGB Modes ................................................................381
Manual Color Transforms and Lookup Tables....................................381
The New DirectX Color and Gamma Controls Interface....................382
Mixing GDI and DirectX ....................................................................383
Getting the Lowdown on DirectDraw ................................................386
The Main DirectDraw Object ........................................................386
Surfing on Surfaces........................................................................388
Playing with Palettes......................................................................389
Using DirectDraw in Windowed Modes..............................................390
Drawing Pixels in a Window..........................................................392
Finding the Real Client Area (51)..................................................395
Clipping a DirectX Window ..........................................................397
Working with 8-Bit Windowed Modes..........................................398
Summary..............................................................................................400
8 Vector Rasterization and 2D Transformations 401
Drawing Lines......................................................................................402
Bresenham’s Algorithm..................................................................403
Speeding Up the Algorithm............................................................409
Basic 2D Clipping................................................................................411
Computing the Intersection of Two Lines Using the Point
Slope Form ..................................................................................413
Computing the Intersection of Two Lines Using
the General Form ........................................................................416
Computing the Intersection of Two Lines Using
the Matrix Form ..........................................................................416
Clipping the Line............................................................................419
The Cohen-Sutherland Algorithm..................................................420
Wireframe Polygons............................................................................427
Polygon Data Structures ................................................................428
Drawing and Clipping Polygons....................................................430
Transformations in the 2D Plane ........................................................432
Translation......................................................................................433
Rotation..........................................................................................435
Scaling............................................................................................445
Introduction to Matrices......................................................................446
The Identity Matrix........................................................................448
Matrix Addition..............................................................................449

0072313618 FM 10/26/99 9:32 AM Page x
x
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Matrix Multiplication ....................................................................449
Transformations Using Matrices....................................................452
Translation ..........................................................................................454
Scaling..................................................................................................455
Rotation................................................................................................455
Solid Filled Polygons ..........................................................................458
Types of Triangles and Quadrilaterals............................................459
Drawing Triangles and Quadrilaterals............................................461
Triangular Deconstruction Details ................................................464
The General Case of Rasterizing a Quadrilateral..........................472
Triangulating Quads ......................................................................473
Collision Detection with Polygons......................................................478
Proximity AKA Bounding Sphere/Circle ......................................478
Bounding Box ................................................................................481
Point Containment..........................................................................484
More on Timing and Synchronization ................................................486
Scrolling and Panning..........................................................................488
Page Scrolling Engines ..................................................................488
Homogeneous Tile Engines............................................................489
Sparse Bitmap Tile Engines ..........................................................494
Fake 3D Isometric Engines..................................................................496
Method 1: Cell-Based, Totally 2D ................................................496
Method 2: Full-Screen-Based, with 2D or 3D
Collision Networks......................................................................498
Method 3: Using Full 3D Math, with a Fixed Camera View ........500
The T3DLIB1 Library ........................................................................500
The Engine Architecture ................................................................500
Basic Definitions............................................................................501
Working Macros ............................................................................502
Data Types and Structures..............................................................503
Global Domination ........................................................................506
The DirectDraw Interface ..............................................................507
2D Polygon Functions....................................................................511
2D Graphic Primitives....................................................................513
Math and Error Functions..............................................................517
Bitmap Functions............................................................................519
Palette Functions............................................................................522
Utility Functions ............................................................................525
The BOB (Blitter Object) Engine........................................................527
Summary..............................................................................................535
9 Uplinking with DirectInput and Force Feedback 537
The Input Loop Revisited....................................................................538
DirectInput Overture............................................................................539
The Components of DirectInput ....................................................541
The General Steps for Setting Up DirectInput ..............................542

0072313618 FM 10/26/99 9:32 AM Page xi
xi
CONTENTS
Data Acquisition Modes ................................................................544
Creating the Main DirectInput Object............................................544
The 101-Key Control Pad ..............................................................546
Problem During Reading: Reacquisition........................................554
Trapping the Mouse........................................................................556
Working the Joystick......................................................................561
Massaging Your Input ....................................................................576
Going Deeper with Force Feedback....................................................579
The Physics of Force Feedback......................................................580
Setting Up Force Feedback............................................................580
A Force Feedback Demo................................................................581
Writing a Generalized Input System:
T3DLIB2.CPP ............................582
The T3D Library at a Glance ........................................................588
Summary..............................................................................................588
10 Sounding Off with DirectSound and DirectMusic 589
Sound Programming on the PC ..........................................................589
And Then There Was Sound…............................................................590
Digital versus MIDI—Sounds Great, Less Filling..............................594
Digital Sound—Let the Bits Begin................................................594
Synthesized Sound and MIDI........................................................596
It’s MIDI Time!..............................................................................597
Sound Hardware..................................................................................598
Wave Table Synthesis ....................................................................598
Wave Guide Synthesis....................................................................598
Digital Recording: Tools and Techniques............................................599
Recording Sounds ..........................................................................600
Processing Your Sounds ................................................................600
DirectSound on the Mic ......................................................................601
Starting Up DirectSound......................................................................602
Understanding the Cooperation Level............................................604
Setting the Cooperation Level........................................................605
Primary and Secondary Sound Buffers ..............................................606
Working with Secondary Buffers ..................................................606
Creating Secondary Sound Buffers................................................607
Writing Data to Secondary Buffers................................................610
Rendering Sounds................................................................................612
Playing a Sound..............................................................................612
Stopping a Sound............................................................................612
Controlling the Volume..................................................................612
Freaking with the Frequency..........................................................613
Panning in 3D ................................................................................614
Making DirectSound Talk Back..........................................................614
Reading Sounds from Disk..................................................................616
The
.WAV Format ............................................................................616
Reading
.WAV Files ........................................................................617

0072313618 FM 10/26/99 9:32 AM Page xii
xii
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
DirectMusic: The Great Experiment ..................................................622
DirectMusic Architecture ....................................................................622
Starting Up DirectMusic......................................................................624
Initializing COM............................................................................624
Creating the Performance ..............................................................625
Adding a Port to the Performance..................................................626
Loading a MIDI Segment....................................................................626
Creating the Loader........................................................................627
Loading the MIDI File ..................................................................627
Manipulating MIDI Segments ............................................................630
Playing a MIDI Segment................................................................630
Stopping a MIDI Segment..............................................................631
Checking the Status of a MIDI Segment ......................................631
Releasing a MIDI Segment............................................................631
Shutting Down DirectMusic ..........................................................631
A Little DirectMusic Example ......................................................632
The
T3DLIB3 Sound and Music Library ..............................................632
The Header ....................................................................................633
The Types ......................................................................................633
Global Domination ........................................................................634
The DirectSound API Wrapper......................................................635
The DirectMusic API Rapper—Get It?..........................................640
Summary..............................................................................................643
PART III Hard Core Game Programming 645
11 Algorithms, Data Structures, Memory Management,
and Multithreading 647
Data Structures ....................................................................................648
Static Structures and Arrays ..........................................................648
Linked Lists....................................................................................649
Algorithmic Analysis ..........................................................................657
Recursion ............................................................................................659
Trees ....................................................................................................662
Building BSTs................................................................................666
Searching BSTs..............................................................................668
Optimization Theory............................................................................671
Using Your Head ............................................................................671
Mathematical Tricks ......................................................................672
Fixed-Point Math............................................................................673
Unrolling the Loop ........................................................................677
Look-Up Tables..............................................................................678
Assembly Language ......................................................................679
Making Demos ....................................................................................680
Prerecorded Demos........................................................................680
AI-Controlled Demos ....................................................................682

0072313618 FM 10/26/99 9:32 AM Page xiii
xiii
CONTENTS
Strategies for Saving the Game ..........................................................682
Implementing Multiple Players ..........................................................683
Taking Turns ..................................................................................683
Split-Screen Setups ........................................................................684
Multithreaded Programming Techniques ............................................685
Multithreaded Programming Terminology ....................................686
Why Use Threads in a Game?........................................................687
Conjuring a Thread from the Plasma Pool ....................................689
Sending Messages from Thread to Thread ....................................697
Waiting for the Right Moment ......................................................702
Multithreading and DirectX ..........................................................709
Advanced Multithreading ..............................................................711
Summary..............................................................................................711
12 Making Silicon Think with Artificial Intelligence 713
Artificial Intelligence Primer ..............................................................714
Deterministic AI Algorithms................................................................715
Random Motion..............................................................................716
Tracking Algorithms ......................................................................717
Anti-Tracking: Evasion Algorithms ..............................................722
Patterns and Basic Control Scripting ..................................................722
Basic Patterns ................................................................................723
Patterns with Conditional Logic Processing..................................727
Modeling Behavioral State Systems....................................................729
Elementary State Machines............................................................730
Adding More Robust Behaviors with Personality..........................734
Modeling Memory and Learning with Software ................................736
Planning and Decision Trees ..............................................................740
Coding Plans ..................................................................................742
Implementing a Real Planner ........................................................745
Pathfinding ..........................................................................................747
Trial and Error................................................................................748
Contour Tracing..............................................................................749
Collision Avoidance Tracks............................................................749
Waypoint Pathfinding ....................................................................750
A Racing Example..........................................................................753
Robust Pathfinding ........................................................................754
Advanced AI Scripting ........................................................................759
Designing the Scripting Language ................................................759
Using the C/C++ Compiler............................................................762
Artificial Neural Networks..................................................................767
Genetic Algorithms..............................................................................770
Fuzzy Logic ........................................................................................772
Normal Set Theory ........................................................................773
Fuzzy Set Theory............................................................................774

0072313618 FM 10/26/99 9:32 AM Page xiv
xiv
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
Fuzzy Linguistic Variables and Rules............................................776
Fuzzy Manifolds and Membership ................................................779
Fuzzy Associative Matrices............................................................783
Processing the FAM with the Fuzzified Inputs..............................787
Warm and Fuzzy ............................................................................794
Building Real AI for Games................................................................794
Summary..............................................................................................795
13 Playing God: Basic Physics Modeling 797
Fundamental Laws of Physics ............................................................798
Mass (m) ........................................................................................799
Time (t) ..........................................................................................799
Position (s)......................................................................................800
Velocity (v) ....................................................................................802
Acceleration (a)..............................................................................804
Force (F) ........................................................................................807
Forces in Higher Dimensions ........................................................808
Momentum (P)................................................................................809
The Physics of Linear Momentum: Conservation and Transfer ........810
Modeling Gravity Effects....................................................................813
Modeling a Gravity Well................................................................815
Modeling Projectile Trajectories....................................................818
The Evil Head of Friction....................................................................821
Basic Friction Concepts..................................................................821
Friction on an Inclined Plane (Advanced) ....................................823
Basic Ad Hoc Collision Response ......................................................828
Simple x,y Bounce Physics............................................................828
Computing the Collision Response with Planes of
Any Orientation ..........................................................................830
An Example of Vector Reflection..................................................834
Intersection of Line Segments........................................................835
Real 2D Object-to-Object Collision Response (Advanced)................841
Resolving the n-t Coordinate System..................................................846
Simple Kinematics ..............................................................................853
Solving the Forward Kinematic Problem ......................................854
Solving the Inverse Kinematic Problem ........................................858
Particle Systems ..................................................................................859
What Every Particle Needs ............................................................859
Designing a Particle Engine ..........................................................860
The Particle Engine Software ........................................................861
Generating the Initial Conditions ..................................................866
Putting the Particle System Together ............................................869
Playing God: Constructing Physics Models for Games......................870
Data Structures for Physics Modeling............................................870
Frame-Based Versus Time-Based Modeling..................................871
Summary..............................................................................................873

0072313618 FM 10/26/99 9:32 AM Page xv
xv
CONTENTS
14 Putting It All Together: You Got Game! 875
The Initial Design of Outpost..............................................................876
The Story........................................................................................876
Designing the Gameplay................................................................877
The Tools Used to Write the Game ....................................................877
The Game Universe: Scrolling in Space..............................................878
The Player’s Ship: “The Wraith” ........................................................880
The Asteroid Field ..............................................................................882
The Enemies........................................................................................884
The Outposts ..................................................................................885
The Predator Mines........................................................................886
The Gunships..................................................................................888
The Power-Ups....................................................................................891
The HUDS ..........................................................................................892
The Particle System ............................................................................896
Playing the Game ................................................................................896
Compiling Outpost ..............................................................................897
Compilation Files ..........................................................................897
Runtime Files..................................................................................898
Epilogue ..............................................................................................898
P
ART IV Appendixes 901
A What’s on the CD 903
B Installing DirectX and Using the C/C++ Compiler 907
Using the C/C++ Compiler..................................................................908
C Math and Trigonometry Review 911
Trigonometry ......................................................................................911
Vectors..................................................................................................915
Vector Length ................................................................................916
Normalization ................................................................................917
Scalar Multiplication......................................................................917
Vector Addition ..............................................................................918
Vector Subtraction..........................................................................919
The Inner Product, or the “Dot” Product ......................................919
The Cross Product..........................................................................921
The Zero Vector..............................................................................923
Position Vectors..............................................................................923
Vectors as Linear Combinations ....................................................924

0072313618 FM 10/26/99 9:32 AM Page xvi
xvi
TRICKS OF THE WINDOWS GAME PROGRAMMING GURUS
D C++ Primer 925
What Is C++? ......................................................................................925
The Minimum You Need to Know About C++ ..................................928
New Types, Keywords, and Conventions............................................929
Comments ......................................................................................929
Constants........................................................................................929
Referential Variables ......................................................................929
Creating Variables On-the-Fly........................................................930
Memory Management..........................................................................931
Stream I/O............................................................................................932
Classes..................................................................................................934
The New Struct in Town ................................................................934
Just a Simple Class ........................................................................935
Public Versus Private......................................................................936
Class Member Functions (A.K.A. Methods) ................................937
Constructors and Destructors ........................................................938
Writing a Constructor ....................................................................939
Writing a Destructor ......................................................................941
The Scope Resolution Operator ..........................................................943
Function and Operator Overloading....................................................945
Summary..............................................................................................947
E Game Programming Resources 949
Game Programming Sites....................................................................949
Download Points..................................................................................950
2D/3D Engines ....................................................................................950
Game Programming Books..................................................................951
Microsoft DirectX Multimedia Exposition..........................................951
Usenet Newsgroups ............................................................................951
Keeping Up with the Industry: Blues News........................................952
Game Development Magazines ..........................................................952
Game Web Site Developers ................................................................953
Xtreme Games LLC ............................................................................953
F ASCII Tables 955
Index 961

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧