Matrix Create scale, what is happening here?

315 views Asked by At

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

https://i.stack.imgur.com/zG5NU.jpg

Translation->Scale-> Rotation->Translation

https://i.stack.imgur.com/Ch9Yi.jpg

Thanks in advance, Roger

1

There are 1 answers

0
Roger Martins On BEST ANSWER

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