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 />

Example<br />

vRigidBody = member("Physics").getRigidBodies()[1]<br />

vWorldPoint = vector(0, 0, 0)<br />

vStiffness = 1234.5<br />

vDamping = 321.0<br />

vConstraintDescriptor = ConstraintDesc("Test Constraint", vRigidBody, null,<br />

vRigidBody.position, vWorldPoint, vStiffness, vDamping)<br />

trace(vConstraintDescriptor)<br />

-- (Constraint Descriptor)<br />

Creating the constraint<br />

You can use the following functions to create the three different types of constraints:<br />

Note: Each function requires different parameters in addition to a ConstraintDesc object.<br />

physicsMember.createAngularJoint() requires a floating point rest length for the constraint<br />

physicsMember.createLinearJoint() requires an axisAngle list, containing an axis vector and a scalar angle<br />

physicsMember.createSpring() requires both a symbol force exertion mode and a floating point rest length for the<br />

constraint. The force exertion mode symbol can take one of three values: #kDuringCompression,<br />

#kDuringExpansion, or #kBoth.<br />

Examples<br />

In the examples below, it is assumed that a ConstraintDesc, using a unique name, has already been created, as<br />

described in the previous section. Although a ConstraintDesc is an independent object, a script error occurs if you<br />

try to use the same ConstraintDesc for two different controls. This is because the name for the control is stored in the<br />

ConstraintDesc, and each control must have a unique name.<br />

The first example shows the creation of an angular joint with a rest length of 23.59 world units.<br />

vRestLength = 23.59<br />

vAngularJoint = member("Physics").createAngularJoint(vAngularDescriptor, vRestLength)<br />

trace(vAngularJoint)<br />

-- constraint("angular")<br />

trace(vAngularJoint.constraintType)<br />

-- #angular<br />

trace(vAngularJoint.properties) -- [#length: 23.5900]<br />

The next example shows the creation of a linear joint with a random orientation.<br />

vAxis = randomVector()<br />

vAngle = random(360)<br />

vOrientation = [vAxis, vAngle]<br />

vLinearJoint = member("Physics").createLinearJoint(vLinearDescriptor, vOrientation)<br />

trace(vLinearJoint)<br />

-- constraint("linear")<br />

trace(vLinearJoint.constraintType)<br />

-- #linear<br />

trace(vLinearJoint.properties)<br />

-- [#axis: vector( 0.9598, 0.0499, -0.2761 ), #angle: 56.0000]<br />

The last example shows the creation of a spring which will resist both expansion and contraction, and which has a rest<br />

length of 17.23.<br />

Last updated 8/26/2011<br />

332

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

Saved successfully!

Ooh no, something went wrong!