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

Use modelsUnderRay() with the #detailed option to find where a ray from the mouse touches a model<br />

The following handler places the group “Sphere_Parent” on the point on the surface of the model “Terrain”, which<br />

appears directly under the mouse.<br />

on exitFrame(me)<br />

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

vMember = vSprite.member<br />

vParent = vMember.group("Sphere_Parent")<br />

vTerrain = vMember.model("Terrain")<br />

-- Find the point on the terrain under the mouse<br />

vCamera = vSprite.camera<br />

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

vRayInfo = [:]<br />

vRayInfo[#maxNumberOfModels] = 1<br />

vRayInfo[#levelOfDetail] = #detailed<br />

vRayInfo[#modelList] = [vTerrain]<br />

vRayData = vCamera.modelsUnderLoc(vSpriteLoc, vRayInfo)<br />

if not vRayData.count then<br />

exit<br />

end if<br />

vPosition = vRayData[1].isectPosition<br />

vParent.worldPosition = vPosition<br />

end exitFrame<br />

You can use a similar technique to drag a model over the surface of any model. To place a model representing a<br />

painting on a vertical wall, you would simply use the Wall model in the #modelList of the modelsUnderLoc()<br />

options list.<br />

Dragging a model parallel to the sprite viewport<br />

To drag a model in the plane that is parallel to the sprite viewport, you need to know which way the camera is pointing.<br />

This is given by the zAxis property of the camera's transform in world space.<br />

vZAxis = aCamera.getWorldTransform().zAxis<br />

Tip: In fact, the camera's zAxis points out of the sprite towards you.<br />

Last updated 8/26/2011<br />

252

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

Saved successfully!

Ooh no, something went wrong!