07.12.2012 Views

Adobe Director Basics

Adobe Director Basics

Adobe Director Basics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ADOBE DIRECTOR BASICS<br />

3D: Controlling action<br />

You find examples that use these characteristics at “3D mathematics recipes” on page 378.<br />

Cross product<br />

In mathematics, the cross product of vector u by vector v is written: u x v<br />

The cross product of two vectors creates a new vector that is at right angles to both vectors. Its length will depend on<br />

both the angle between the vectors and their magnitude. In most cases, you will be interested in the direction of the<br />

crossProduct and not its length.<br />

All three of the techniques below will give the same result.<br />

vCrossProduct = vector1.cross(vector2)<br />

vCrossProduct = vector1.crossProduct(vector2)<br />

vCrossProduct = vector1.perpendicularTo(vector2)<br />

To visualize the direction of the output vector, use the thumb, index finger and middle finger of your right hand. (If<br />

you are left-handed, you must still use your right hand). Point your thumb in the direction of vector1, your index<br />

finger in the direction of the vector2, and turn your middle finger at right angles to both of the input vectors.<br />

Note: The order in which you use the vectors is important. Imagine that the input vectors point upwards and to the right.<br />

If you point your thumb upwards and your index finger to the right, your middle finger will point away from you. If you<br />

point your thumb to the right and your index finger upwards, your middle finger will point towards you.<br />

The crossProduct is useful for determining the axis of a rotation. Imagine that you have a spaceship pointing at planetA<br />

and you want to turn it to point at planetB, using the least amount of fuel. You can define two vectors:<br />

vToPlanetA = vPlanetA.worldPosition - vSpaceShip.worldPosition<br />

vToPlanetB = vPlanetM.worldPosition - vSpaceShip.worldPosition<br />

You can now obtain the axis of rotation using crossProduct():<br />

vAxisOfRotation = vToPlanetA.crossProduct(vToPlanetB)<br />

When you turn around an axis, you use a different right-hand rule. Point your thumb in the direction of the axis and<br />

curl your fingers: your fingers will point in the direction of positive rotation. Imagine that the spaceship is pointing at<br />

planetA straight ahead of you, and that planetB is off to your right and slightly downwards. With your right hand, point<br />

your thumb forwards and your index finger to the right and downwards. Your middle finger will probably now be<br />

pointing to the ground just beneath you. That is the direction of the axis of rotation.<br />

Point your right thumb in the direction of the axis of rotation and point your fingers forward. curl your fingers round.<br />

Now curl your fingers round: they will turn in the direction your imaginary spaceship needs to turn in order to point<br />

at the imaginary planetB.<br />

It takes just two more lines to put your spaceship on target:<br />

vAngleOfRotation = vToPlanetA.angleBetween(vToPlanetB)<br />

vSpaceShip.rotate(vSpaceShip.worldPosition, vAxisOfRotation, vAngleOfRotation)<br />

Transforms<br />

In this section and in the following sections, the terms are grouped together by usage and by type.<br />

Last updated 8/26/2011<br />

370

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!