flash 10 orthographic projection

2019-07-15 14:25发布

问题:

I've been playing a bit with the new flash 10 3d possibilities, and found out that rotating a sprite in 3d is fairly easy:

var card:Sprite = new MyCard()
card.x = 100
card.y = 100
card.z = 200
card.rotationX = -60
addChild(card)

Simple and effective, this shows the card rotated with perspective.

Now I want to use an orthographic projection, and I have no clue where to start. DisplayObject does have a perspectiveProjection member, but that can only make perspective projections of course. Maybe I should use the transform.matrix3D?

I'd think this should not be too hard, but I don't see how to tackle this issue.

UPDATE: as one of the comments suggests: setting the perspectiveProjection.fieldOfView to something close to 0 (10 actually produces a nicer result in my setup than something like 0.1) you get a projection that is nearly orthographic, that might be good enough.

回答1:

I finally got it working.

        var m:Matrix3D = new Matrix3D()
        var v3:Vector.<Vector3D> = new Vector.<Vector3D>(3);
        v3 = m.decompose();
        v3[2] = new Vector3D(1,1,0);
        m.recompose(v3)
        transform.matrix3D.appendRotation( -90, Vector3D.X_AXIS );
        transform.matrix3D.appendRotation( -45, Vector3D.Y_AXIS );
        transform.matrix3D.appendRotation( 35.264, Vector3D.X_AXIS );
        transform.matrix3D.append(m)

Now any element added to the sprite that has this transform applied to it will show up in isometric projection. (that 35.264 number is an approximation see http://en.wikipedia.org/wiki/Isometric_projection)



回答2:

You could set the fieldOfView property of PerspectiveProjection to NEAR 0. I'm unsure if this is the best way.

Reference: http://thebackbutton.com/misc/f10api/flash/geom/PerspectiveProjection.html