6
\$\begingroup\$

I'm having a problem with matrix rotation in libgdx. I rotate it using the method matrix.rotate(Vector3 axis, float angle) but the rotation happens in the model orientation and I need it happens in the world orientation.

For example:

on create() method:

matrix.rotate(new Vector3(0,0,1), 45);

enter image description here

That is ok, but after:

on render() method:

matrix.rotate(new Vector3(0,1,0), 1);

enter image description here

I need it rotate in world axis.

\$\endgroup\$
  • \$\begingroup\$ Transform the axis of rotation from model coordinates to world coordinates. \$\endgroup\$ – Dashto May 3 '14 at 19:31
0
\$\begingroup\$

You need to transform the world axis to your model's coordinate system first. You can do this by applying the model's current transformation matrix to the axis vector through multiplication; like so:

matrix.rotate(axis.mul(matrix), angle);
\$\endgroup\$
0
\$\begingroup\$

You need to transform the world space rotation vector to model space before applying the rotation. Vectors are transformed with inverse transpose of the matrix, i.e. v'=transpose(inverse(M))*v

Because models generally define model->world matrix you need to invert this to get world->model matrix. So you need to calculate v' = transpose(inverse(inverse(model_to_world)))*v = transpose(model_to_view)*v before applying the rotation. Also note that the w-component of the vector must be 0

\$\endgroup\$

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.