Question

I'm trying to perform some matrix transformations with the spritebatch and I don't understand what is happening with the scale matrix.

       rotM = Matrix.CreateTranslation(0, 0, 0)
                * Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(startRotations.Y)
                                              , MathHelper.ToRadians(startRotations.X)
                                              , MathHelper.ToRadians(startRotations.Z))
                * Matrix.CreateScale(endScale.X, endScale.Y, 0)
                * Matrix.CreateTranslation((Origin.X + PositionRec.X + Offset.X) * endScale.X
                                         , (Origin.Y + PositionRec.Y + Offset.Y) * endScale.Y, 0);

        sp.Begin(SpriteSortMode.Deferred, null, null, null, null, null, rotM);
        sp.Draw(BackgroundTexture, Vector2.Zero, PositionRec, BackgroundColor * alpha);
        sp.End();

Usualy I get best looking results with this order, however if I change the scale to be before the rotation everything gets weird, even using (1.1.0) scale, so I'm just getting the original size.

Lets fix the scale to 1 (excluding Z), why/how does it affect the rotations if I leave the vertices intact with the scale(I think)?

Examples:

Translation-> Rotation->Scale->Translation

http://imgur.com/ihdlepa

Translation->Scale-> Rotation->Translation

http://imgur.com/YpbOnqw

Thanks in advance, Roger

Was it helpful?

Solution

Well after some thought i think I understood it.

So i'm drawing sprites, 2d, in 3d space. after rotation the z coordinate has value, so using 0 as z scale destroys that value.

Since I'm not using no lights or shading, it was hard co check what was happening.

Is this right?

Thanks, Roger

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top