december/january 1996 G A M E D E V E L O P E R M A G A Z I N E GGAAMMEE G A M E P L A N Spare a Quarter for Microsoft? F Editor Alex Dunne irst, it conquered the desktop. of the game. This kind of work could be [email protected] Then it set its sights on the done by one or two developers familiar Managing Editor Tor Berg [email protected] Internet. Now Microsoft is tar- with the game engine, and perhaps a spe- Editorial Assistant Chris Minnick geting the arcade? That’s right. cialist in coin-op development. Market- [email protected] Microsoft is launching an ini- ing doesn’t take a very big bite out of Contributing Editors Larry O’Brien tiative to make Windows the your budget in the coin-op world, so [email protected] operating system for the next you’d save some money on that front. All Chris Hecker [email protected] generation of coin-op games. in all, you’re not looking at a tremendous David Sieks Unveiled at Microsoft’s recent Judge- outlay to port a game to coin-op using [email protected] ment Day event (its second annual Win- Microsoft’s model. Web Site Manager Phil Keppeler dows 95 games showcase), the initiative That begs the question: What kind [email protected] is still in its early stages, but could turn of cash could you expect from a coin-op Cover Photography Carter Dow Photography the coin-op industry on its ear if it gains port of a Windows-based game? 4th enough momentum. Wave, a market research firm, worked up Publisher Veronica Costanza Basically the plan goes like this: A some numbers in an attempt to answer Group Director Katie Brennan number of hardware companies would that. 4th Wave assumed an installed base Special Projects Manager Nicole Freeman produce Windows-based coin-op of approximately 15,000 Windows-based [email protected] Advertising Sales Staff machines, which would probably be coin-op machines in the first year of powered by Pentium Pros or equivalently availability (starting in mid-1997) and Western Regional Sales Manager Steve Nikkola (415) 905-2256 powerful processors. You, the game projected that each machine would run a [email protected] developer, would ship games for the little over two games during that time- Western Account Manager coin-op market in the same manner that span, creating a market for about 32,000 Barbara Wren (415) 356-3362 you currently ship into the home market. title-units. If you assume a traditional [email protected] After telling the manufacturer of the distribution spread, then of the top 15 Eastern Sales game which standard controls your game games, one would sell about 9,600 units; John Travers (212) 615-2682 requires, and perhaps creating the jazzy four would sell about 3,100 units each; [email protected] artwork for the playfield and marquee, and ten would sell approximately 1,000 Marketing Manager Susan McDonald the manufacturer would just slap the units each. Assume conservatively that Marketing Graphic Designer Azriel Hayes proper components into place and ship your title is in the bottom 10—that’s Advertising Production Coordinator Denise Temple your game. 1,000 units sold at about $750 each, of Director of Production Andrew A. Mickus This is a big leap from today’s coin- which you, the publisher, get a fair chunk Vice President/Circulation Jerry M. Okabe op games, most of which require special- (probably around two-thirds). That’s Group Circulation Manager Mike Poplardo ized hardware under the hood. In many about a $500K return for your two or Assistant Circulation Manager Jamai Deuberry cases, this hardware acts as a form of three person porting effort. Granted, Subscription Marketing Manager Melina Kaplanis copy protection so that the game can’t be these are extremely rough numbers, but Newsstand Manager Eric Alekman pirated. Microsoft’s plan would remove it’s something to chew on. Reprints Stella Valdez (916) 729-3633 the need for game-specific hardware and Microsoft makes no bones about in its place use an as-yet-unspecified another aspect of this initiative that Chairman/CEO Marshall W. Freeman form of copy protection. benefits them greatly. A Windows-based President/COO Donald A. Pazour In terms of your resources as a game in an arcade is an advertisement for Senior Vice President/CFO Warren “Andy” Ambrose developer of PC games, it probably the home version of the game. That’s Senior Vice Presidents David Nussbaum, Darrell wouldn’t involve many additional per- great for you, because it could boost your Denny, Ted Bahr, Wini D. Ragus, Regina Ridley son-hours of time to tweak a game for sell-through to consumers. It’s great for Vice President/Production Andrew A. Mickus coin-op using this model. You’d want to Microsoft because people have to buy Vice President/Circulation Jerry Okabe simplify your game for the arcade ver- copies of Windows 95 to play your game. Senior Vice President/ sion, and tune it up to get as much speed That demon seems to lurk behind every- Software Development Division Regina Starr Ridley out of it as you could. You would also thing they do, doesn’t it? n want to change your levels around so that Alex Dunne Miller Freeman they weren’t identical your home version Editor A United News & Media publication 6GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com/ S E Z U ! WWHHIICCHH WWAAYY DDOO II GGOO?? worked. I originally tested the code in the article Developer. He touched upon many key points Dear Editor: on both IPX and modem servers, but I admit that I was pleased to read about. W ould you recommend developing that the DirectX 1.0 DirectPlay implementation I ordered 3D Studio Max and am happier with games for DOS using Watcom C/C++ acted a little flaky at times. this investment having read such a review from 10.6 with DOS/4GW, or games that someone who clearly knows what constitutes an run on Win32s using Visual C++ 4.1 and the BBEENNCCHHMMAARRKKIINNGG CCOOMMPPIILLEERRSS outstanding program. DirectX 2 SDK? Dear Editor: Anonymous I Dan Mintz read Chris Hecker’s article “More Compiler Via Internet Via Internet Results, and What To Do About It” in the DDEELLAAYY OOFF GGAAMMEE August/September 1996 issue and have a Chris Hecker replies: question. Dear Editor: I It actually doesn’t matter. The important parts How were the timings measured? Did he read Dan Teven and Vincent Lee’s article of game programming, such as mathematics, count clock cycles from the assembler code, or “Optimizing CD-ROM Performance under user interface, gameplay tuning, artificial intel- did he run timed benchmarks? If he ran timed DOS/4GW” (August/September 1996). We ligence, and so on, are totally platform indepen- benchmarks, what operating systems were used play all of our game’s music off of CD audio dent. I’d say start with whatever is easiest or for each test? tracks, and when I use the STOP and PLAY com- cheapest, and learn to write good code. If you Also, his Macintosh bias needn’t have been mands, there’s a long delay (the game stops for do that, you can write for whatever platform included in the article. The PowerPC 604 is not a period of one to two seconds). MSCDEX docu- you’d like. “a pretty fair comparison” to a Pentium. Every- mentation states that these two functions one (except Hecker apparently) gives the “fair should return immediately, but that isn’t hap- DDIIRREECCTTPPLLAAYY DDIIFFFFIICCUULLTTYY comparison” nod to the PowerPC 604 vs. the pening. Any ideas? Dear Editor: Pentium Pro at similar clock speeds. I would be Pablo Testa I enjoyed Michael Morrison’s article “Network- interested in those results. Via Internet ing Your Game Using DirectPlay” (June/July Randy Rynkewicz 1996). I used it as a tutorial for learning Via Internet Dan Teven replies: DirectPlay. I discovered a problem when running Although you’re working with the CD audio calls the TicTacToe game in conjunction with the TCP Chris Hecker replies: and not using the “seek” call, this problem and IPX service providers. Morrison’s code was I timed the functions by doing a bunch of loops sounds very similar to one Vince Lee and I men- failing in the IDirectPlay::EnumPlayerscall. I and using Microseconds on the Mac and tioned in our article. Because the MSCDEX notice he calls IDirectPlay::Openprior to call- QueryPerformanceCounter on Windows 95. I interface is synchronous and some calls may ing EnumPlayers,which the DirectPlay docu- timed the non-Windows 95 compilers’ outputs not return quickly, you need to use a multi- mentation warns against. I modified the code to by linking in their object modules into my Win- threaded architecture if you want to keep these delay calling Openuntil after EnumPlayerswas dows 95 timing program. Most of the compilers calls from slowing down your game. Whenever called, and everything worked fine (at least in output COFF objects, and I converted the others. you want to stop a track or play a new one, your the TCP and IPX worlds). I assume Morrison’s I’ve never been accused of having a Macin- program should create a new thread to issue code worked as published when using the tosh bias before. By “a pretty fair comparison,” the MSCDEX call. Meanwhile, the rest of your modem server provider. Why is that? I meant my 132Mhz PPC and the 133Mhz Pen- program can continue to execute. Matt D’Ercole tium were similar systems from a clock-rate Windows 95 features multithreading support. Via Internet and memory standpoint. Cross-architecture If you’re developing for real-mode DOS, there comparisons are basically impossible to get are commercial libraries available. Multithread- Michael Morrison replies: right anyway, so it was meant as more of a side ing libraries also exist for the DOS/4GW, Phar I double checked both the DirectX 1 and 2 docu- comment than a well-researched result. Lap, and Causeway DOS extenders. mentation and they both mention calling The length of the delay also will depend on the EnumPlayersafter calling Opento connect to a SSIIEEKKSS SSIIZZZZLLEESS CD-ROM driver you’re using. Some drivers dis- session. In fact, I’m not sure how DirectPlay Dear Editor: able interrupts for long periods of time and can D could know about other players without being avid Sieks wrote an intelligent assess- interfere with a preemptive multitasker. If this connected to a session via Open. However, it ment of 3D Studio Max in the is the case, creating another thread won’t cure sounds like the change you made to your code August/September 1996 issue of Game the delay. GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 9 http://www.gdmag.com B I T B L A S T S Dear Santa... Tor Berg X-ponents paths that are fully editable. And support librium has also included bandwidth for QuickDraw 3D for Windows lets conservation tools for multimedia and MicroHelp Inc. has shipped its new you import and export 3DMF objects. web graphics. Over 90 file formats are development package, Game+Multime- Infini-D 3.5 for the MacOS is supported, and the list is optimized for dia X-ponents. X-ponents are program- available now. The Windows 95/NT the Windows 95 and NT environments. ming objects that encapsulate Micro- version is scheduled to ship at the end of DeBabelizer for Windows will soft’s DirectX programming interfaces, November. List price is $649. ship in the last quarter of 1996, and combining object-oriented development n Specular International Ltd. will list at $595. practices with the power and speed of Amherst, Mass. n Equilibrium accessing hardware directly. (413) 253-3100 Sausalito, Calif. http://www.specular.com (415) 332-4343 X-ponents are optimized for Inter- http://www.equilibrium.com net download and are based on the MotionStar ActiveX framework. They are divided Geppetto into component families including: For more realistic character animation, MhDirectDraw, which encapsulates you might want to look into a magnetic QuantumWorks has made its per- interfaces that directly access video mem- motion sensor. Ascension Technology formance animation system avail- ory and the bit manipulation capabilities Corp. has just released it’s MotionStar able to the public. of the hardware; MhDirectPlay, which Wireless magnetic tracker. Geppetto is designed for lip sync, eases the connectivity of games over Wireless technology has really facial control, and overall expressiveness. modem links or networks; MhDirect- improved this magnetic tracking system. The built-in gesture recognition system Sound, which encapsulates the Direct- Although magnetic tracking is cheaper can map any input data combination to Sound and DirectSoundBuffer interfaces, than optical systems, the cabling was any set of control points on the avatar’s enabling hardware and software sound heavy and restricted motion. The geometry. Geppetto has the advantage mixing and playback; and others. MotionStar yields real-time results and of being open and extensible. 3D appli- MicroHelp Game+Multimedia X- doesn’t require a line-of sight between cation developers can integrate Geppet- ponents lists for $249. the sensors and the transmitter. to libraries into their own applications, n MicroHelp Inc. The tracker has a range of up to 20 and the system supports input devices Marietta, Ga. feet diameter, with the transmitter in from the high end (Motion Analysis’s (770) 516-0899 the center. Up to 14 sensors are mount- Face Tracker) to the low end (off-the- http://www.microhelp.com ed at key points on the model. Motion shelf MIDI controllers). Geppetto also Infini-D 3.5 cues can be derived for animation soft- has the ability to output sound and ani- ware from Alias/Wavefront, Softimage, mation data as .AVI image files, 3D Specular International Ltd. is set to MediaLab, 3D Studio, and others. dynamic deformation databases, 3D release a Windows 95/NT version of its n Ascension Technology Corp. function curves, MIDI sound events, Infini-D 3.5 3D modeling and render- Burlington, Vermont and .WAV files. (802) 860-6440 ing software. Following the MacOS ver- Geppetto runs on a high-end Win- http://www.ascension-tech.com sion that shipped last summer, this dows 95/NT box. The system is avail- release will feature full support for DeBabelizer able in a range of configurations, from a Apple’s QuickDraw 3D and QuickTime software-only product—which includes on a Windows platform. Also on the moving-to-Windows front, the MIDI controller and a year of sup- Infini-D 3.5 offers a spline-based Equilibrium, maker of the DeBabelizer port—sold for $8,000, to a complete modeler and photorealistic rendering. automated graphics processing software turnkey package—including the Face Interesting effects include animated for the MacOS, has developed a Win- Tracker, road cases, a spycam system, Boolean rendering, with which you can dow 95/NT version of its product. and rack-mounted hardware—for about “carve” your 3D objects using any 3D DeBabelizer automatically prepares $50,000. shape as a tool, and animated lens flare images, animations, and digital video n QuantumWorks Corp. effects that you can edit on the screen. through file-format conversion, batch Sherman Oaks, Calif. (818) 906-3322 Animations are handled with an event- processing, color-palette reduction, http://users.aol.com/setpci/qw.htm based sequencer and on-screen motion image processing, and scripting. Equi- 12 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com B E H I N D T H E S C R E E N Physics, Part 2: Angular Effects I just want to block the door with them rotational) effects in today’s games that take advantage of the something heavy, so the bad guy games is that programmers perceive expressive power of angular effects, or can’t get in. Is that too much to ask? angular physics to be difficult to under- at the very least, let you shoot your I want to flip over his car with a stand and implement. High-school friend’s feet out from under her in a carefully placed explosion, I want to physics courses (where we all learned deathmatch game. jam the huge gears to which I’m F=ma) usually don’t cover angular strapped before they crush me, and effects, and it’s not immediately clear Recap I want to rig up a seesaw-type thing how to translate a force applied to an Whenever I’m writing a series of to catapult a nice flaming present over object into a spin for that object. While columns on a single topic, I always his castle’s protective wall. You might the dynamics of angular motion are reread my last column before starting the think that my antagonist is the one stop- slightly more difficult to understand latest one so I can figure out where I left ping me from doing these things, but the than the dynamics of linear motion, off. I just got finished doing that with person stopping me is actually the pro- they’re not thatmuch more complicated. the first part of this series on physics, grammer behind the game’s physics Anybody who can implement a linear and wow, we covered a lot of ground, engine, because at the heart of each of physics engine based on the material we and without any code or references to these tasks lies an angular effect. Few covered in the last column will be able boot! Before we get started, let’s quickly games today try even to model angular to implement one that supports angular review the material from last time. effects, let alone try to get them right. effects based on the information in this Table 1 contains the important The main reason for the lack of column. Hopefully, once this knowl- results for doing linear rigid body support for angular (you might call edge is out there, we’ll start to see dynamics. Eq. 1 shows that the position vector (denoted by r), the velocity vector Table 1. Important Equations from Part 1 of This Series (v), and the acceleration vector (a) are all related by derivatives (and integrals in Eq. 1 Relationship of d2r dr˙ dv the opposite direction). As a reminder, position (r), velocity (v), =˙r˙= = = v˙ =a we denote differentiation with respect to and acceleration (a) dt2 dt dt time with a dotted vector, so “ r˙” is the same as dr/dt, and “ ˙r˙” is the same as the second time derivative. Eq. 2 shows how Eq. 2 Force (F) equals the derivative of linear F =p˙ = dp = d(mv) =mv˙ =ma force is related to linear momentum momentum (p), or dt dt (mass times velocity), mass, and accelera- mass (m) times tion. Eq. 3 gives the definition of the acceleration center of mass, which is the point where all the masses and distances balance each Eq. 3 Center of Mass (CM) MrCM = (cid:229) miri other out. Eq. 4 says that the total linear momentum for a rigid body is the sum of i all the momentums, which, luckily for us, Eq. 4 Total linear momentum (cid:229) d(MrCM) simply equals the momentum of the cen- equals the momentum pT = mivi = = MvCM ter of mass (CM). Eq. 5 is the real gem; of CM dt i it uses Eq. 4 to show that the accelera- tion of our object’s CM is related to the Eq. 5 Ttoottaal l mfoarscse (eMqu) atilms ethse FT =p˙T = Mv˙CM = MaCM total force–the vector sum of all forces CM acceleration currently acting on our object–by a sim- ple scalar, the total mass of the object. 14 GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com So, to summarize the results from add another kinematic quantity, orienta- the last column, we first find the total tion (denoted by W, capital omega), to Chris Hecker force on our CM by summing all the that configuration so we can support our forces applied to the body (including angular effects. To define W , we need to To properly model things like gravity, the bad guy’s tractor pick a coordinate system fixed in our beam, the nearby explosion, our engine rigid body and a fixed world coordinate thrust, whatever). Then, we divide this system, and specifyW as the angular dif- vector sum by the total mass to get the ference between them in radians, as physics in your game, CM acceleration, and then integrate that shown in Figure 1. In the figure, x ,y w w acceleration over time (using the numer- are the world axes, and x,y are the body b b ical integration techniques mentioned at axes. W is positive in the counterclock- the end of the last column) to get our wise direction. At this point, it should be body’s new velocity and position. clear why we’re learning 2D dynamics you have to Although Eq. 5 is a nice piece of before moving up to 3D: The orienta- work, you’ll notice that it contains no tion in 2D is just a scalar (the angle concept of where the forces act on the between the coordinate systems in radi- body, which is the key to figuring out ans), while specifying an orientation in how those forces rotate the body. Eq. 5 3D is much more complicated. understand rotational isn’t wrong—it’s exactly right for calcu- As our body rotates in the world, lating the linear acceleration—we’re just W changes. This change leads us to our missing half the story. But let’s start at next new kinematic quantity, angular the beginning… velocity (denoted by w, lowercase effects. See how omega). In contrast with the position What’s Your Angle? and its linear velocity, we don’t usually W˙ The last column ignored rotation, so we signify the angular velocity by “ .” only needed the position vector and its However, we sometimes signify the derivatives to describe our rigid body’s velocity’s time derivative, or angular angular momentum, configuration in 2D. We now need to acceleration—which is our final new w˙ kinematic quantity—with “ ,” and Figure 1. The Definition of W sometimes with an a (lowercase alpha). y Don’t blame me, I don’t make these w x w rules, and every book I read has a torque, and other slightly different convention. Our y b angular analog to Eq. 1 is xW b d2W = dw =w˙ =a yw dt2 dt (Eq. 6) forces can be Much like Eq. 1, if we differentiate w with respect to time, we get a ; and if we integrate a over time, we get w , and x w so on. Clearly, as in our analytic integra- modeled in a game. tion example for linear movement in the previous column, if we know the angular http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 15 B E H I N D T H E S C R E E N Figure 2. C=W r vB =w rO^ B (Eq. 7) d(W r) = dW = w r r Eq. 7 introduces a bunch of new dt dt (Eq. 8) notation, so let’s take it apart one piece The radius drops out of the deriva- at a time. First, I’m using superscripts tive because it’s constant (B is simply to denote which parameters “belong” to rotating, not translating as well), and the C which points, so vB is the velocity of time derivative of W is w by Eq. 6. Thus, B point B in our body. Similarly, rOB the magnitude of B’s velocity vector is w r. means the vector from the origin of our If we look at Eq. 7, we see that it W r body O to point B. The funny upside- gets the magnitude correct because the down T subscript is the “perpendicular perpendicular operator clearly does not O operator,” which takes a vector (like rin effect a vector’s length, and rOB is the Eq. 7) and rotates it counterclockwise radius vector from the origin to B. We’re by 90 degrees. In other words, it creates halfway done. acceleration a , we can integrate it twice a new vector that’s perpendicular to the To show that the direction of the to find the new orientation; but the key old vector. In 2D, the perpendicular of velocity in Eq. 7 is correct, we’ll start by is we need to know a to do this. a vector (x,y) is just (-y,x), as you can convincing ourselves the velocity vector’s As you might expect, our goal for easily verify on a piece of graph paper. direction must be perpendicular to the this column is to derive angular analogs I’ll say more on this operator shortly. radius vector. This assumption makes for each of the linear physics equations Finally, the perpendicular vector is sense intuitively, because a point rotating in Table 1, and then link the linear and scaled by the angular velocity w to give around another fixed point can only move angular equations together so we can the linear velocity vB. So, in English, perpendicularly to the vector between the take a given force on our object and use Eq. 7 says the velocity of a point on a points at any instant; it can’t move closer it to calculate the linear acceleration a, rotating body is calculated by scaling or farther away, or the movement and the angular acceleration a . Finally, the perpendicular vector from the origin wouldn’t be a simple rotation. We could we can numerically integrate these accel- to the point by the angular velocity. make this assumption rigorous using a erations to find our body’s new position How in the heck did I come up with tiny bit of vector calculus, but I’m running and orientation. this thing? Well, I read about it in a out of space, so we’ll consider ourselves The first way we’ll link the linear book, but that’s obviously not very illu- convinced. (If you want to prove it to and angular quantities together is with a minating, so let’s prove for ourselves yourself, try differentiating the dot prod- neat and not-so-obvious trick using angu- that it works. uct of a fixed length vector with itself.) lar velocity. When we’re doing dynamics, We’ll prove Eq. 7 does what I say it Finally, we need to make sure the we often need to find the velocity of an does in two stages. First, we’ll prove that sign of the velocity vector is correct, arbitrary point on our object. For exam- the magnitude of the resulting velocity since there are actually two vectors of the ple, when we cover collision response, vector is correct; then, we’ll prove it’s same length that are perpendicular to the we’ll need to know the velocity of the col- pointing in the right direction. To prove radius: v and -v. Since we’re measuring liding points to figure out how hard they the first part, we’ll use Figure 2. Figure 2 W in the counterclockwise direction, w is hit each other. If our bodies aren’t rotat- shows our point B moving W radians positive when the point is rotating coun- ing, the velocity of any point in the body during the body’s rotation, with the terclockwise. The perpendicular operator is the same; we can just keep track of the radius vector from the origin to B as r Figure 3. Linear Velocity velocity of the body’s CM and be done units long. B has moved C units of with it. However, if our bodies are rotat- arclength on the circle, where C=W r by from Angular Velocity ing, then every point in them might have the definition of radians. (Radian mea- a different velocity. Obviously, we can’t sure is the measure of arclength scaled by keep track of the velocity of each of the the radius of the circle. The circumfer- infinity of points in our rigid body, so we ence of a circle is the well-known formu- need a better way. la 2p r, because it’s 2p [or 360 degrees] vB=w r^OB A simple way to find the linear worth of arclength.) velocity of any point inside an object A point’s speed is its change in B uses that object’s angular velocity. Let’s position over time. Thus, we can find B’s w first cover the case of a body rotating speed—which is another way of saying rOB with one point, the origin O, fixed, so the magnitude of its velocity vector—by O the body is rotating but not translating. differentiating the equation for its move- Eq. 7 shows how to calculate the velocity ment with respect to time. C=W r is the for a point B on this rotating body. equation for its movement. 18GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com points in the counterclockwise direction with the point’s linear momentum. This “rotating around” point A; that “rotating- relative to the radius vector. So, as Fig- operation is called the “perp-dot prod- around force” is called the torque. Eq. 11 ure 3 shows, Eq. 7 checks out. uct.” (It’s sort of the 2D analog to the lets us calculate the torque—and hence We can extend Eq. 7 to cover 3D cross product, but that discussion the angular momentum, if we integrate simultaneously rotating and translating will have to wait for another time.) that torque—from an applied force and bodies. We will consider any movement If you take Eq. 10 and draw out its position of application. of a rigid body as a simple translation of what it’s doing on a piece of paper—I’ve However, we still don’t have any a single point in the body and a simple drawn an example in Figure 4—you’ll relationship between the torque and the rotation of the rest of the body around see it produces a number that’s a mea- kinematic angular quantities we need to that point. This is known as Chasles’ sure of how much of B’s linear momen- spin our object around—such as the angu- Theorem, for those keeping score. tum is “rotating around” A. That is, if lar acceleration, angular velocity, or orien- Chasles’ Theorem breaks up our B’s linear momentum is aiming right at tation; so we can’t really do anything with motion into linear and angular compo- A or directly away from A, Eq. 10 is 0 our newfound dynamic quantities until nents. We consider the origin O in Eq. 7 (since r-perpendicular will form a right we’ve derived a few more equations. as the single translating point, then use w angle with p, and the dot product will be to keep track of the rotation around O, 0). As more of B’s momentum is direct- The Moment We’ve All Been which gives us the general form of Eq. 7. ed perpendicular to A, Eq. 10 produces a Waiting For vB = vO +w rOB larger angular momentum. As you can Before we can examine the relationship ^ (Eq. 9) see in Figure 4, the dot product in Eq. between the dynamic and kinematic Eq. 9 says we can calculate the 10 is measuring the cosine of q between quantities, we need to define the total velocity of any point in a moving body by rAB-perpendicular and pB, which is what angular momentum, much as we have taking the known linear velocity of our you’d expect from a dot product. How- defined the total linear momentum in Eq. body’s origin and adding to it the velocity ever, if we look at it another way, the 4. I didn’t forget the angular equivalent of generated from the body’s rotation. perp-dot product is measuring the sine the CM in Eq. 3; it will come to us in the of f between our original unperpendicu- total angular momentum equation. A Moment-us Occasion larized rAB and pB (the sine is another The total angular momentum about Now we’re in a position to work on the clue to the similarity between the perp- point A is denoted LATand is defined by angular analog of Eq. 2, the force equa- dot and the 3D cross product). Eq. 12. tion. We’ll start by defining the angular Whichever way we look at it, Eq. 10 is LAT =(cid:229)rAi(cid:215)pi momentum, LAB, of one point, B, about producing a measure of how much of B’s ^ i another point, A, as follows: linear momentum is in the “rotating- around direction” with respect to A. =(cid:229)rAi(cid:215)mivi LAB = r^AB (cid:215) pB (Eq. 10) In the same way we used the linear i ^ (Eq. 12) The angular momentum of a point momentum’s derivative to define force, Eq. 12 is a summation of all the differs from the linear momentum of a we’ll use the angular momentum’s deriv- angular momentums of all the points, as point in that the angular version is mea- ative to define force’s angular twin, measured from point A. On the right- sured from a specific position in space. torque (denoted by t, lowercase tau). hand side, I’ve used the definition of linear That is, while linear momentum is just a ( ) momentum to expand p into mass times property of a given point (its mass times dLAB d r^AB (cid:215) pB velocity (mv) because we’re going to tAB = = its velocity), the angular momentum of manipulate this term to turn Eq. 12 into dt dt the point must be measured from anoth- something more manageable. As it stands, = rAB (cid:215) maB = rAB (cid:215) FB er place in the world. The superscript ^ ^ notation in Eq. 10 shows this. The nota- (Eq. 11) Figure 4. Angular Momentum tion LABsays that the first superscript, A, To save space, I actually cheated a bit is the point about which the momentum in Eq. 11 and left out a couple of tricky is measured, and the second superscript, steps involving the product rule for deriva- B, is the point whose angular momen- tives. Still, when all is said and done, the pB tum is being measured. Think about an torque ends up being related to the force q f arrow from the first superscript to the at a specific point by the perp-dot product. LAB=rAB pB ^ second; A is “looking at” B’s momen- At last, we find a dynamics equation B tum. This arrow from A to B is the that uses the point where a force was radius vector between the two points, applied, which is ignored in the equa- rAB designated by rAB. So, the angular tions for linear movement. Eq. 11 uses momentum of a point is the dot product the perp-dot product to measure how A of the “perpendicularized” radius vector much of the force applied at point B is http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 19 B E H I N D T H E S C R E E N if we want to calculate the total angular I’ll describe Eq. 13 one step at a 13 constant for each body, so we can cal- momentum for our object, we’d have to time. First, we substitute Eq. 7 into Eq. culate it offline before we begin. To sum all of the angular momentums for 12 to get the first summation in Eq. 13. rephrase in English, IAis the sum of the each of the points. For a rigid body com- This substitution lets us write the angu- squared distances from point A to each posed of surfaces rather than separate lar momentum in terms of the angular other point in the body, and each points, we’d have to perform an integra- velocity. Next, we bring the w out of the squared distance is scaled by the mass of tion instead of a discrete summation. summation because it’s the same for all each point. Much like the CM, if the Luckily, we can simplify this calcu- the points (the angular velocity is body is continuous rather than made lation by introducing a new quantity, defined for the body, not the points from discrete points, the summations called the moment of inertia, in the same individually), and we write the mass for above would turn into integrals. Howev- way we introduced the CM to simplify point i on the left-hand side so we can er, the moment of inertia would still the equations for linear movement. We see that we’re really taking the dot prod- exist and be defined the same way. start by remembering that Eq. 7 gives us uct of the radius vector with itself. This The definition of the moment of an alternate way of writing the velocity dot product is just the radius vector’s inertia about a point is a mouthful, but of a point in terms of the angular veloci- length squared. (The dot product of any think of IAas a measure of how hard it is ty. If we treat the point A in Eq. 12 as vector with itself is the length squared; to rotate the body about point A. For the origin in Eq. 7, and the point index i remember the perpendicular operator example, think about a pencil (a 2D pen- in Eq. 12 as the point B in Eq. 7, we can doesn’t change a vector’s length.) Finally, cil). If we measure the moment of inertia substitute Eq. 7 into Eq. 12 and write we write the letter IA to designate the about the middle of the pencil, we get a LAT=(cid:229)rAi(cid:215)miwrAi moment of inertia about point A. The certain value by summing the mass-scaled ^ ^ moment of inertia for a 2D rigid body is squared distances. However, if we mea- i a particularly nice number, because the sure the inertia about the tip of the same =w(cid:229)mirAi(cid:215) rAi ^ ^ points that make up the body can't pencil, we get a much larger value, i change their mass or their distance from because the squared term in Eq. 13 makes =w(cid:229)mi(rAi)2=wIA the measurement point. These two the masses that are farther away (toward ^ i (Eq. 13) properties make the summation in Eq. the eraser of our pencil) contribute much 20GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 http://www.gdmag.com more to the value. This is saying mathe- tation via integration—by dividing the 6. Divide the total torque by the matically what we all know intuitively: torque by the moment of inertia. moment of inertia at the CM to find the Turning a pencil about its center is a lot angular acceleration (Eq. 14). easier (read: takes less force) than turning The Dynamics Algorithm 7. Numerically integrate the linear it about one of its ends. We may not recognize it through the acceleration and angular acceleration to Finally, we’re ready to provide a use- flurry of equations, but that’s all of it. update the position, linear velocity, ori- ful link between the angular dynamics We’ve developed enough equations to do entation, and angular velocity (see last equations and the angular kinematics great 2D dynamics with arbitrary forces issue). equations. If we differentiate Eq. 13, we and torques moving and spinning our 8. Draw the object in the new posi- get the total torque on the left side, and on objects around. How do we use all these tion, and go to Step 3. the right side we get the moment of iner- equations? Here’s the basic algorithm: There are only two steps in the tia times the angular acceleration. (IA is 1. Calculate the CM and the above algorithm that I haven’t yet constant so it drops out of the derivative.) moment of inertia at the CM. explained. First, how does one calculate 2. Set the body’s initial position, the moment of inertia in Step 1 for a dLAT d(IAw) tAT = = orientation, and linear and angular continuous object? Second, how do you dt dt velocities. figure out the forces on an object for = IAw˙ = IAa (Eq. 14) 3. Figure out all of the forces on Step 3? The answer to the first question the body, including their points of can be found in the sample program ref- This equation is the angular equiva- application. erenced at the end of this article (you lent of Eq. 5; it’s basically F=ma for 4. Sum all the forces and divide by perform an integration over the surface angular dynamics. It relates the total the total mass to find the CM’s linear of the object). Most dynamics books torque and the body’s angular accelera- acceleration (Eq. 5). have the moments of inertia for common tion through the scalar moment of iner- 5. For each force, form the perp- shapes listed in the back, so you don’t tia. If we know the torque on our body, dot product from the CM to the point of usually have to derive them from scratch. we can find its angular acceleration—and force application and add the value into The answer to how to compute the therefore, the angular velocity and orien- the total torque at the CM (Eq. 11). forces in Step 3 depends on the applica- http://www.gdmag.com GAME DEVELOPER • DECEMBER 1996/JANUARY 1997 21