2
\$\begingroup\$

I want a matrix that scales first and then rotates. I tried the code below, but it didn't work. zRotation, yRotation and xRotation are rotations that shouldn't be affected by the origin. allrot should be affected. xScale, yScale and zScale are the scaling variables. The code below works except that it rotates and then scales.

Matrix worldMatrix = (
    Matrix.CreateRotationZ(MathHelper.ToRadians(zRotation)) *
    Matrix.CreateRotationX(MathHelper.ToRadians(xRotation)) *
    Matrix.CreateRotationY(MathHelper.ToRadians(yRotation))
) * (
    Matrix.CreateTranslation(origin) *
    Matrix.CreateRotationY(MathHelper.ToRadians(allrot)) *
    Matrix.CreateScale(xScale, yScale, zScale)
);
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Your code is showing rotation first, translation second, another rotation third and scale last. That's almost the opposite of what you know it needs to be based on what you indicated in your question. Have you tried it with scale first?

If you are coming from an OpenGL background where the order to combine matrices is from right to left, XNA applies them opposite: left to right.

\$\endgroup\$
3
  • \$\begingroup\$ I know, but the code almost works. And I tried scaling it first but the origin should also change with the scale. And x-, y- and zRotation shouldn't be affected by the origin. \$\endgroup\$ Jul 3, 2013 at 16:19
  • \$\begingroup\$ you are unclear about that. the origin is at 0,0,0. If that is scaled by anything it will remain 0,0,0 (anything multiplied by zero equals zero). Most likely you mean something else by the term 'origin' but we have no idea what. \$\endgroup\$
    – Steve H
    Jul 5, 2013 at 1:07
  • \$\begingroup\$ Is "offset" the right word? \$\endgroup\$ Jul 5, 2013 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .