Jump to content

Decomposing negative scaling matrices


Eelis
 Share

Recommended Posts

Consider:

var s = new BABYLON.Vector3();
var r = new BABYLON.Quaternion();
var t = new BABYLON.Vector3();

if (BABYLON.Matrix.Scaling(1, -1, 1).decompose(s, r, t))
{
	console.log("scale: " + s);
}

I get the following output:

scale: {X: 1 Y:1 Z:1}

Naively I expected to get {1, -1, 1} back out again. What am I missing here? :)

Thanks

Link to comment
Share on other sites

I'm not 100% sure about what I'm going to tell, but this reminds me old things.

If I remember correctly most of the matrix decomposition routines can't extract non uniform scale (i.e. not the same scale value for x, y & z). I think it has something to do with finding the matrix determinant which is needed after. Well can't remember exactly but googling will tell you if I'm right or not.

 

Link to comment
Share on other sites

1 hour ago, Eelis said:

Hmm, well if the decompose function only yields correct outputs for certain inputs, it would be useful if the documentation stated these preconditions. :)

Well, mixing 3 different matrices into one may lead to information loss, which means you can't decompose to get back what you had initially in some cases. There's no mystery, the decomposition only works if some specific conditions are met.

But we, you're right, documentation should state the limitations of this methods. Overall if you deal with non uniform scale be aware there could be other "issues" like that. A good general rule is to allow non uniform scaling only for final stage animation (vertex blending/bones/etc.).

If you still need to get it back I suggest you to work with a custom structure I used to call PRS: Position (Vector3), Rotation (Quaternion) and Scale (Vector3), you can easily create a matrix from it and you will always have each info stored specifically. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...