banner ad
Wednesday, January 30, 2008
Towards Z in 3D and now in AS3

This code is heavily based on the 3D flythrough post  I had written in AS2.  I rewrote it in AS3 since most of if not all of my 3D experiments are based on this engine.  The equation bellow moves each element's Z position to sync with the camera's z value, this creates the illusion of a traveling camera in 3D.  Now I know the Fiash has no _z property, but there is no reason why we cant create on in order to achieve our goal. Interact with slider to see it in action.

Create 10 identical clips and arrange them one after the other along an imaginary z axis.  Create a camera object and compute its position through the slider. This version explores the movement of 3D cameras along the Z axis. The experiment uses an external class to create the slider.  You can download the slider class here.

	// camera z position
clip.dz = centerZ - dir*(oCamera.dz - clip.z) * distance;

// Calculating actual scale values according to scale = fl/(fl+dz) formula
var scale:Number = focalLength/(focalLength+clip.dz);

// set size
clip.scaleX = clip.scaleY = scale;


»comments

Lee said...

What's the difference between this, and just managing scales with a multiplier variable?


paul+ortchanian said...

No difference, 3D is always a question of scale management and this is the way i choose to approach it. It works for me.


X. said...

[What's the difference between this, and just managing scales with a multiplier variable?]

Perspective is maintained, otherwise it appears artificial to the eye and might actually cause nausea.


doc said...

props to Freddy for stating "the client problem". Many times we've had clients that want something very particular. It's so particular, that it contradicts the elegant solution of well written code. This is where the Flash IDE saves my life. At the end of the day, the client is only going to pay for you something that does what they want, the way they want, to their satisfaction.
I do not fear code, but I do wish they'd settle on something. I cursed for days after the initial switch from AS 1.0 to AS 2.0, and my limited experience with AS 3.0 is already sending up familiar red flags, but I will adapt.

doc

PS...I think Flex is for lazy people :D


voyance said...

Cool concept and good work !


Stroller said...

Good stuff.. Strong concept and a strong will power to execute it.


Name
URL
Email
*email address is not published
Remember Me
Comments

CAPTCHA






banner ad