Changing skeleton.setPosition()
will modify the input vertex positions that are then processed by the transform matrix (which is a combination of the model and view matrix, called modelview in OpenGL for example) and then by the projection matrix. So if any of the matrices scale the input object-space vertices, a translation of these input vertices will be scaled as well implicitly. While possible, it is not a good idea to apply inverse-scaled transformation and apply it to the input vertices via skeleton.setPosition()
, instead it would be better to apply transformations consistently in the right order.
While the above code modifies the projection matrix, it would be more appropriate to modify the transformation matrix for translation and model scale via setTransformMatrix()
. There you could then apply all transformations like scale, rotation and translation in the desired order.
Note that in libgdx matrices are multiplied with vertices in this order:
result_vertex_pos = Projection * Transform * input_vertex_pos
So with translation, rotation and scale this becomes:
result_vertex_pos = Projection * T * R * S * input_vertex_pos
Now you can additionally offset the scale pivot by replacing the scale matrix S with multiple matrices to scale it relative to a custom pivot. This is done by translation by -pivot_position
, then scaling and then translating back by pivot_position
.
S_pivot = (T_pivot * S * T_negative_pivot)
result_vertex_pos = Projection * T * R * (T_pivot * S * T_negative_pivot) * input_vertex_pos
So in summary, your Transform matrix could be set to this:
T * R * (T_pivot * S * T_negative_pivot)