views:

288

answers:

0

I am trying to match a setup the designer did in the Flash CS4 IDE:

cs3_view

I'm using Away3D for this project. I wrote a little as3 snippet that spits out the Location(x,y,z) and Rotation(rotationX,rotationY,rotationZ) of the planes, keeping in mind that in the IDE, top left is 0,0, not the centre of the stage and y increases in the opposite directions in CS4 compared to Away3D. Also, I'm getting the fieldOfView from the root perspectiveProjection and use that for the Away3D camera.fov and the focalLength (described as

the distance between the eye or the viewpoint's origin (0,0,0) and the display object located in the z axis.

as camera.z.

I don't know what to do with the projectionCenter, I tried to use for x and y *lookAt*() coordinates, but no luck.

I've spent a lot of time trying to get the last bits to match the view from Away3D to the view in the CS4 IDE and I'm getting a bit frustrated that I'm missing out on the last bits.

Here is my result so far:

away3d_view

Here's my snippet:

stop();

function navigate(event:KeyboardEvent) {
    if(event.keyCode == Keyboard.LEFT) prevFrame();
    if(event.keyCode == Keyboard.RIGHT) nextFrame();
    if(event.keyCode == Keyboard.SPACE) {
        for(var i:int = 0 ; i < numChildren; i++){
            var code:String = 'var ' + getChildAt(i).name + ':Picture3D = new Picture3D(null,new LocRot(';
            code += (getChildAt(i).x - stage.stageWidth * .5).toFixed(2) + ',';//pivot is at 0,0 top left, not centre
            code += ((getChildAt(i).y - stage.stageHeight * .5) * -1).toFixed(2) + ',';// * -1...Y increases up in away3d, opposite to flash cs4
            code += getChildAt(i).z.toFixed(2) + ',';
            code += getChildAt(i).rotationX.toFixed(2) + ',';
            code += getChildAt(i).rotationY.toFixed(2) + ',';
            code += getChildAt(i).rotationZ.toFixed(2) + '));';
            trace(code);
        }
        var pp:PerspectiveProjection = root.transform.perspectiveProjection;
        trace('camera = new Camera3D({fov: ' + pp.fieldOfView.toFixed(2) + ',z: ' + (pp.focalLength * -1).toFixed(2) +' });');
    }
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, navigate);

it spits out this in the Output Panel:

var pic5:Picture3D = new Picture3D(null,new LocRot(85.31,-79.92,847.04,-45.22,-3.07,1.11));
var pic4:Picture3D = new Picture3D(null,new LocRot(41.84,11.01,745.04,-44.95,-2.04,2.06));
var pic3:Picture3D = new Picture3D(null,new LocRot(9.79,99.23,672.03,-42.28,-0.99,2.02));
var pic2:Picture3D = new Picture3D(null,new LocRot(6.20,174.09,542.00,-40.02,0.59,2.11));
var pic1:Picture3D = new Picture3D(null,new LocRot(4.11,245.42,408.04,-34.24,1.85,1.22));
camera = new Camera3D({fov: 48.74,z: -1065.14 });

Picture3D is a class extending ObjectContainer3D and contains a cube with a small depth.LocRot is a value object containing x,y,z and rotationX,rotationY,rotationZ values.

I'm trying to understand the 'camera' on both ends (Flash CS4 IDE, Away3D) The 'camera' in CS4, or the 2D projection settings to be more exact are defined by PerspectiveProjection. There seem to be 3 main properties:

  • fieldOfView - which corresponds to Away3D's camera.fov
  • focalLength - the distance from the camera to the 3d object( Away3D's camera.z * -1)
  • projectionCentre - what I assume is Away3D's camera.lookAt() x and y

Away3D's camera seem to have 3 interesting properties among others:

  • focus - not sure what it is exactly from the livedocs, but according to the description in Papervision Essentials it is

    a positive number that represents the distance between the camera and the near plane (and thus our viewport). It is the shortest distance possible between the observer and a visible object.

I'm guessing focus means the same thing in Away3D as it does in Papervision3D. To me it sounds similar to camera.z but not quite. - fov - fieldOfView - lens - what is this ? what does it do ? how do I use it ? does it relate to cs4 ? how ?

Any hints will help.

Thanks, George