Jump to content

Vector & Quaternion division functions


JCPalmer
 Share

Recommended Posts

I found myself making a class called MatrixComp, which is the rotation, translation, & scaling components of a BABYLON.Matrix broken out.  When trying to scale the matrices of a pose from a library, more than just scaling the translation is required to account for skeletons which might have different postures / builds  (rotation at rest).  Otherwise, the skeleton assumes the posture of the skeleton used to make the library, which can look weird.

I added methods to compute the ratios of each component's rest value (called basis) to the rest value that of the library.  Often, the translation of a dimension is zero, so using the divide function results in a NaN.  I wrote my own, shown below.  Is there any interest in changing the division behavior to this?  a NaN is really not useful.

this.translationBasisRatio = BABYLON.Vector3.Zero();
if (libraryBasis.translation.x !== 0) this.translationBasisRatio.x = this.translation.x / libraryBasis.translation.x;
if (libraryBasis.translation.y !== 0) this.translationBasisRatio.y = this.translation.y / libraryBasis.translation.y;
if (libraryBasis.translation.z !== 0) this.translationBasisRatio.z = this.translation.z / libraryBasis.translation.z;

Also, there is no divide for a Quaternion, but this equivalent.  Maybe, a wrapper?

this.rotationBasisRatio = this.rotation.multiply(BABYLON.Quaternion.Inverse(libraryBasis.rotation));

I also ended up with my own versions of Vector3.LerpToRef & SlerpToRef.  I am fine keeping all of this in my code, but some could be moved if wanted.

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...