question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

translate, rotate Matrix4

See original GitHub issue

Hello, 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:closed
  • Created 10 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
xoppacommented, Oct 20, 2013

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.

0reactions
charlmertcommented, Jul 31, 2015

Thanks so much for this!! was struggling with the exact same thing, so changing the location without post multiplication it is using Matrix4#trn

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Flutter: Matrix4 And Perspective Transformations
While Flutter provides easy ways to do transformations such as translation, scaling, and rotation, we can use the Matrix4 to create even ...
Read more >
Matrix4 class - vector_math_64 library - Flutter - Dart API docs
Copies the rotation matrix from this homogeneous transformation matrix into rotation . decompose(Vector3 translation, Quaternion rotation, Vector3 scale) ...
Read more >
Matrix4#makeTranslation – three.js docs
This allows a Vector3 representing a point in 3D space to undergo transformations such as translation, rotation, shear, scale, reflection, orthogonal or ...
Read more >
matrix4_transform | Flutter Package - Pub.dev
This package is a helper math class that makes it easy to create Matrix4 transformations. Example: // Rotates the Container 45 degrees and...
Read more >
Exploring Transform And Matrix4 In Flutter - YouTube
One of the most powerful widgets in the Flutter catalog (and for me, one of the most underrated) is the Transform widget.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found