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.CreateTranslation(origin) *
    Matrix.CreateRotationY(MathHelper.ToRadians(allrot)) *
    Matrix.CreateScale(xScale, yScale, zScale)

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.

  • \$\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\$ – user1990950 Jul 3 '13 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 '13 at 1:07
  • \$\begingroup\$ Is "offset" the right word? \$\endgroup\$ – user1990950 Jul 5 '13 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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