Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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".

share|improve this question
    
I think the scale in the Matrix will have been changed by the rotation of the 3D sprite, in which case you may need to multiply it by the inverse of the rotation matrix? –  Jonathan Connell Oct 7 '12 at 11:27
    
see a relevant Q&A on SO: stackoverflow.com/questions/12446835/… –  gilad hoch Oct 7 '12 at 11:27
    
@Jonathan Connell Come again? –  Bill Kotsias Oct 7 '12 at 17:46
add comment

1 Answer 1

You could project each vertex of your 3d sprite to screenspace and then calculate the distance between these points to get the size of the sprite on screen.

To do billboarding, I always find a helper LookAt function is useful. It will orientate your game entity towards a point in space. To billboard you just make it LookAt the camera position. (The alternative is getting the inverse of your view matrix and using that to apply the appropriate rotation).

Here's a link to at LookAt implementation: http://msdn.microsoft.com/en-us/library/windows/desktop/bb281710%28v=vs.85%29.aspx

share|improve this answer
    
+1 For simplicity. The result is that the sprite's new Forward vector for its transformation matrix is the opposite of LookAt. –  ChrisC Feb 15 '13 at 20:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.