[SOLVED] How to initialize camera by matrix?

I have view matrix (4x4) and projection matrix (4x4), can I initialize the camera by them ?
I notice pc.Mat4 has the getEulerAngles and getTranslation API, but I don’t know how to calculate the camera’s position, eulerangles, scale correctly…
Can anyone help ?

Nobody can help me ? :joy:

The camera’s view matrix is the inverse of the world transformation matrix. So you could invert the matrix and then call getTranslation and getEulerAngles on it:

var viewMatrix = new pc.Mat4();
var pos = viewMatrix.getTranslation();
var eulers = viewMatrix.getEulerAngles();

// Now set the camera entity's position and rotation
1 Like

:laughing: Thank you, you save my day!

1 Like

What about the projection matrix?
Is that affect the camera’s fov?
And how to use the projection matrix?

To extract the fov from a projection matrix in PlayCanvas, you can do:

 var m11 = this.entity.camera.projectionMatrix.data[5];
 var fov = Math.atan(1 / m11) * 2 * 180 / Math.PI;

Should work the same for your matrix values. Just use the [1, 1] element of your matrix.

1 Like