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

If the resulting vSpriteLoc is VOID, then the box is not allowed to move to the proposed new position.<br />

Note: For more information on how the dragging feature is implemented, see “Dragging” on page 250.<br />

spriteSpaceToWorldSpace()<br />

The function spriteSpaceToWorldSpace works in reverse. For input, it accepts a 2D point, representing an offset from<br />

the top left corner of the 3D sprite as a parameter. For output, it returns a 3D position vector representing one of the<br />

points in the 3D world that appears under that point in the sprite.<br />

At that location in the sprite, there will be an infinite number of 3D points. The precise value of the point is rarely useful<br />

on its own. However, if you subtract the worldPosition of the camera from the value returned by<br />

spriteSpaceToWorldSpace(), you obtain a vector pointing from the camera into the 3D world through that point.<br />

Here is a handler called GetRayUnderLoc()that accepts two parameters:<br />

aSpriteLoc : a 2D point, representing an offset from the top left corner of the 3D sprite<br />

aCamera: the camera of the 3D sprite<br />

The GetRayUnderLoc()handler returns a unit vector which points from the camera into the world. In other words,<br />

GetRayUnderLoc() tells you the direction in which the mouse is pointing when it is at aSpriteLoc.<br />

on GetRayUnderLoc(aSpriteLoc, aCamera)<br />

vCameraLoc = aCamera.worldPosition<br />

vDistantLoc = pCamera.spriteSpaceToWorldSpace(aSpriteLoc)<br />

vRay = vDistantLoc - vCameraLoc<br />

vRay.normalize()<br />

return vRay<br />

on GetRayUnderLoc<br />

Placing a model under the mouse<br />

Here's a mouseUp() handler from a 3D behavior. It will place a model named “Ball” so that its center appears directly<br />

under the mouse at a distance of 200 world units from the camera:<br />

on mouseUp(me)<br />

vSprite = sprite(me.spriteNum)<br />

vCamera = vSprite.camera<br />

vCameraPoint = vCamera.worldPosition<br />

vBall = vSprite.member.model("Ball")<br />

vSpriteLoc = the mouseLoc - [vSprite.left, vSprite.top]<br />

vWorldSpace = vCamera.spriteSpaceToWorldSpace(vSpriteLoc)<br />

vRay = vWorldSpace - vCameraPoint<br />

vRay.normalize()<br />

vBallPoint = vCameraPoint + vRay * 200<br />

vBall.worldPosition = vBallPoint<br />

end mouseUp<br />

To see a demonstration of this handler, download and launch the movie PlaceBall.dir.<br />

Last updated 8/26/2011<br />

249

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

Saved successfully!

Ooh no, something went wrong!