Reputation: 41
I need to scale a model instance (a 1x1x1 qube) in the y axis and then rotate it around the z axis. So basically it should look like a beam that is rotating in the middle. Unfortunately what ever I do, rotation is always executed before scaling and the result is a dear shape. what I get and what I want
instance.transform.setToScaling(JUMP_GATE_SIZE, JUMP_GATE_SIZE * 5, JUMP_GATE_HIGHT);
instance.transform.setTranslation(x, y, 0);
rotationMatrix.setToRotation(zVector, r);
instance.transform.rotate(rotation);
Any idea how to do that? I am trying to scale the cube to bride between 2 locations in space.
Upvotes: 2
Views: 284
Reputation: 41
The solution was found by my wife, who is a mathematician. The order of matrix operations is the key. Basically all matrix operations that are applied are reverse applied to the model during draw operation. This means that because I execute the rotation operation last to the matrix, it is actually first applied to the model. Code that works
instance.transform.setToRotation(zVector,r);
instance.transform.scale(JUMP_GATE_SIZE, JUMP_GATE_SIZE * 5, JUMP_GATE_HIGHT);
instance.transform.setTranslation(x, y, 0);
Upvotes: 2