Flylib.com

Books Software

 
 
 

Important Formulas in This Chapter

Important Formulas in This Chapter

Heres a reminder of the two main formulas introduced in this chapter.

Coordinate rotation:

x1 = Math.cos(angle) * x




Math.sin(angle) * y;
y1 = Math.cos(angle) * y

+

Math.sin(angle) * x;

Reverse coordinate rotation:

x1 = Math.cos(angle) * x

+

Math.sin(angle) * y;
y1 = Math.cos(angle) * y




Math.sin(angle) * x;

Summary

As youve seen in this chapter, coordinate rotation can give you some very complex behavior, but it all boils down to a couple of formulas that never change. Once youre comfortable with the formulas, you can use them anywhere . I hope youre starting to see how you can create very complicated and richly realistic motion just by adding in more and more simple techniques.

Youll be using the coordinate rotation formula quite a bit in the next chapter, where youll learn how to handle the results of collisions of objects with different velocities and masses.

Chapter 11: Billiard Ball Physics

Overview

What well cover in this chapter:

  • Mass

  • Momentum

  • Conservation of momentum

  • Important formulas in this chapter

As you might expect in a technical book like this, things start off simple and gradually become more complex. With this chapter, you reach a pinnacle of complexity. Not that the rest of the chapters after this are all downhill, but I think this one in particular requires that you have not skimped on the material that came earlier. That said, Ill walk you through the concepts step by step, and if youve followed along reasonably well up to now, you should be fine.

Specifically, this chapter will focus on momentum: What happens to the momentum of two objects that collide, the conservation of momentum, and how to apply this conservation of momentum in ActionScript to movie clips.

As the objects used in these examples are all round, for simplicitys sake, this subject is often referred to as billiard ball physics. And youll soon see that these examples really do look like a bunch of different- sized billiard balls hitting each other.

As in previous chapters, when I get to the code, Ill start you out on one dimension to keep things simpler and easier to understand. Then Ill move into two dimensions, at which point youll need to jump into some coordinate rotation (the subject of the previous chapter). Essentially, youll be rotating the two-dimensional scene so it lies flat. You can then ignore one axis and treat it as a one-dimensional scene. But all that is just to whet your appetite for whats coming up. Lets start with the simple concepts of mass and momentum.

Mass

The earlier chapters of the book have gone into several aspects of motion: velocity, acceleration, vectors, friction, bouncing, easing, springing, and gravity. One thing that I have pretty successfully gotten away with ignoring is the concept of the mass of the object being moved around. Now, Im going to reissue my standard disclaimer here, and say that there are probably several points in the book so far where, scientifically speaking, mass should have been in the equation. But Ive generally concentrated on doing things mostly correctly, and kept the emphasis on making sure it looks right. Most important, the final result must be efficient enough that it wont totally kill Flash in the process.

Unfortunately, or maybe fortunately, I have reached a point where I just cant ignore mass any longer. Mass is just so tied up in the subject of momentum that Im just going to have to confront it head on.

So just what is mass? Here on earth, we usually think of mass as how much something weighs. And thats pretty close, as weight is proportional to mass. The more mass something has, the more it weighs. In fact, we use the same terms to measure mass and velocity: kilograms, pounds , and so on. Technically speaking though, mass is the measurement of how much an object resists change in velocity. Thus, the more mass an object has, the harder it is to move that object or to change how that object is moving (slow it down, speed it up, or change its direction).

This also relates to acceleration and force. The more mass something has, the more force you need to apply to it to produce a given acceleration. The engine in my Chevy Cavalier is designed to produce enough force to provide reasonable acceleration on the mass of a Chevy Cavalier ( barely ). Its not going to produce enough force to accelerate a large truck. The engine would need a lot more force, because the truck has a lot more mass.