07.12.2012 Views

Adobe Director Basics

Adobe Director Basics

Adobe Director Basics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ADOBE DIRECTOR BASICS<br />

3D: Controlling action<br />

Collision callbacks contact reports<br />

Each time there is a collision between either Ball and the Room, or between the two Balls, the FilterCollision()<br />

handler will be called. It will receive a linear list of ContactReport objects. The Physics member is initialized to use five<br />

substeps, and there are two dynamic rigidBody objects. This means that up to ten ContactReports can be generated<br />

per frame.<br />

To visualize what a ContactReport looks like, launch the BallRoom.dir movie, then execute the following command in<br />

the Message window to hijack the callback events:<br />

member("Physics").registerCollisionCallback(#TestCallback)<br />

Now, click on the 3D sprite. You can see the following output printed into the Message window:<br />

-- [(Contact Report), (Contact Report), (Contact Report)]<br />

-- (Contact Report)<br />

-- "<br />

objectA: rigidBody("room")<br />

objectB: rigidBody("ball2")<br />

contactPoints: [[vector( -3.8575, -28.6366, 129.8082 )]]<br />

contactNormals: [vector( 0.0000, -1.0000, 0.0000 )]"<br />

Then the movie will halt to prevent spamming your Message window with endless reports.<br />

You can find the #TestCallback() handler in the Test Callback movie script.<br />

Using a test handler to inspect the data sent to a collision callback<br />

Notice that the objectA and objectB values are listed in the order in which the rigidBody objects were created.<br />

RigidBody("room") was created before rigidBody("ball2"), so it appears first in the<br />

physicsMember.getRigidBodies() list, and is given top billing in the ContactReport.<br />

The contactPoints and contactNormals values are both lists. In the illustration above, they both contain only one<br />

vector each. This is because the ball in question is just in contact with the base of rigidBody("room"). If the ball were<br />

also in contact with a wall, it would be touching rigidBody("room") in two places, so both lists contain two vectors.<br />

In the case shown above, the contactNormal value is vector(0.0, -1.0, 0.0). This vector points downwards. It<br />

indicates that objectA touches objectB at a point where the normal to the surface of objectB is facing downwards.<br />

Last updated 8/26/2011<br />

325

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

Saved successfully!

Ooh no, something went wrong!