Extract derived 3D scaling from a 3D Sprite to set to a 2D billboard

Posted by Bill Kotsias on Game Development See other posts from Game Development or by Bill Kotsias
Published on 2012-10-07T11:20:31Z Indexed on 2012/10/07 15:50 UTC
Read the original article Hit count: 362

I am trying to get the derived position and scaling of a 3D Sprite and set them to a 2D Sprite.

I have managed to do the first part like this:

        var p:Point = sprite3d.local3DToGlobal(new Vector3D(0,0,0));
        billboard.x = p.x;
        billboard.y = p.y;

But I can't get the scaling part correctly. I am trying this:

        var mat:Matrix3D = sprite3d.transform.getRelativeMatrix3D(stage); // get derived matrix(?)
        var scaleV:Vector3D = mat.decompose()[2]; // get scaling vector from derived matrix
        var scale:Number = scaleV.length;
        billboard.scaleX = scale;
        billboard.scaleY = scale;

...but the result is apparently wrong.

PS. One might ask what I am trying to achieve. I am trying to create "billboard" 3D sprites, i.e. sprites which are affected by all 3D transformations except rotations, thus they always face the "camera".

© Game Development or respective owner

Related posts about flash

Related posts about actionscript-3