# Define matrices directly instead of computing them

## Recommended Posts

Hi,

I know that the worldMatrix and projectionMatrix are computed from other properties (like position/rotation/rotationQuaternion/scaling for worldMatrix and fieldOfView/ZNear/ZFar for projectionMatrix). I would like to know if I can proceed the inverse way. I mean I want to set these 2 matrices and automatically update the other properties which depend on it.

##### Share on other sites

There is currently not a way to update in that direction.

##### Share on other sites

You could probably write a function that executes in beforeRender that could do this using Matrix.decompose.

##### Share on other sites

to set the matrix for a mesh i use this typescript function:

``````public static setMatrix(pMesh: BABYLON.AbstractMesh, pMatrix: BABYLON.Matrix): boolean
{
let tPos = BABYLON.Vector3.Zero();
let tRot = new BABYLON.Quaternion();
let tScale = new BABYLON.Vector3(1, 1, 1);
if (pMatrix.decompose(tScale, tRot, tPos)) {
pMesh.position = tPos;
pMesh.rotationQuaternion = tRot;
pMesh.scaling = tScale;
return (true);
}
return (false);
}``````

##### Share on other sites

I know this possibility to set the worldMatrix but in this case I lost informations :

1. I have the matrix to set A
2. I compute the the scaling, rotation, position from A thanks to decompose
3. I get a new matrix B but  B is similar to A but not exactly the same.

I found a solution for this case :

1. Define a parent mesh that I call handler
2. Use handler.setPivotMatrix(A)

The visual result is exactly the same as if I had set A to the worldMatrix of the mesh I want to move but I can't find this kind of solution to set the projectionMatrix of a camera. I can retrieve fov/znear/zfar/aspectRatio from the original matrix, then set these values to the corresponding properties of the camera but then the projection matrix is still different of the original.

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