# solved how and when to use the Matrix decompose() api?

## Recommended Posts

hi

i get confused by the function Matrix decompose() api

in this tutorial https://doc.babylonjs.com/resources/frame_of_reference

i know  mesh  has its world matrix and its local frame of reference

after apply some transform ( position,  rotate and scale)

whenever we want to get the mesh`s world matrix

we can call

mesh.getWorldMatrix(true);

right?

and i see lots of people use decompose() function

after i checking its usage

i thought the decompose() is for decompose a matrix like the mesh world matrix

to get how the mesh be transformed

that is to say

how a identuty matrix [ BABYLON.Matrix.Identity()]

be  position,  rotated and scaled

by using decompose(scale?: Vector3, rotation?: Quaternion, translation?: Vector3)

we can get those three components

am i right ?

till i see some people use it in this way

``m.decompose(BABYLON.Vector3.Zero(), BABYLON.Quaternion.Identity(), position)``

that make me confused

how can i set the components

the scale  set to BABYLON.Vector3.Zero()

the rotation set to BABYLON.Quaternion.Identity()

can some one tell me why?

and how the matrix decompose() exactly the correct usage

regards

##### Share on other sites

Hello! decompose is used to break a matrix into 3 basics component (scaling, quaternion and translation).

So if you have a mesh and you want to decompose the world matrix to get, let's say, the position you will call something like that:

``````var matrix = mesh.getWorldMatrix();
var position = BABYLON.Vector3.Zero();

matrix.decompose(null, null, position);

// position now contains the translation part of the matrix``````

##### Share on other sites

thanks

now i know the decompose() suage

regards @Deltakosh

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.