Jump to content

Define matrices directly instead of computing them


yuccai
 Share

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.

Thanks for your help,

Link to comment
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);
}

 

Link to comment
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.

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