translate, rotate Matrix4
See original GitHub issueHello, have found the next bug: i’m loading model using G3dModelLoader, then creating ModelInstance using nodepart id. my instance.transform matrix has some default rotation. when i’m trying to translate modelinstance it behave in wrong way
ModelInstance instance = new ModelInstance(model, id);
Node node = instance.getNode(id);
instance.transform.set(node.globalTransform);
node.translation.set(0, 0, 0);
node.scale.set(1,1,1);
node.rotation.idt();
instance.calculateTransforms();
instance.transform.translate(0, -150, 0);
to behave in right way we need just remove default rotation (cache it), make translation, and then bring rotation back
.................
instance.calculateTransforms();
Quaternion rot = instance.transform.getRotation(new Quaternion());
instance.transform.setToRotation(0, 0, 0, 0);
instance.transform.translate(0, -150, 0);
instance.transform.rotate(rot);
this behavior isn’t surprise because matrix multiplication isn’t commutative operation. but i think that is better to add some check if the matrix was rotated before to the Matrix4 translate (float x, float y, float z) method and in case it was do the sequence of actions i described above (rotate to zero state, translate, rotate back). not sure that this is really a bug, maybe it should work like it works, please investigate and if it isn’t a bug advice please how to behave it such situations without making all the time this sequence of actions (rotate to zero state, translate, rotate back). thanks
Issue Analytics
- State:
- Created 10 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I still don’t get what the bug is. This is just how matrices work. If you want to change the location without post multiplication, use the Matrix4#setTranslation or Matrix4#trn method.
Thanks so much for this!! was struggling with the exact same thing, so changing the location without post multiplication it is using Matrix4#trn