# Matrix rotation wrong orientation LibGDX

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);

That is ok, but after:

on render() method:

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

I need it rotate in world axis.

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

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);