# [SOLVED] Matrix to Quat Conversion

Hello,
haven’t posted stuff here for a while, but I’m still alive

I’m currently trying to visualize some cameras that I get from a photogrammetry suite in my playcanvas viewer, however I’m stuck on the coordinate conversion with my limited math skills and their sparse documentation Would be glad if somebody could help me out :>

I have a json object containing all my cameras, each with a 3x3 rotation matrix + position (at least I think it’s a 3x3 matrix).

``````"transform": {
"rotation": [
"0.9999193845748845",
"-0.0067983904445017788",
"0.010724096173963507",
"0.0068467717389110727",
"0.99996651966619976",
"-0.0044812122715727218",
"-0.010693272096957062",
"0.0045542764553496541",
"0.99993245396768116"
],
"position": [
"-0.010643984874932972",
"-0.0041727243704965328",
"0.033338095005651464"
]
``````

Using the center coordinates for positioning my cameras works, but I am stuck on converting the rotation data into a Quat, or Euler angles, so that I can apply it to my playcanvas entity.
pc.Quat has a function “setFromMat4“ but none for a Mat3.

Any ideas?

Greetings,

Martin

When you load the JSON file, it probably be easier to make the 3x3 rotation matrix and position into a 4x4 matrix that contains both the orientation and position.

Looking at the code setFromMat4, it actually only uses the 3x3 part of the matrix so creating a function that sets from mat3 is pretty easy if you really need that.

But the question is, how would I do that?

First thought so as well, but than I noticed in the documentation, that the Mat4 expects 15 numbers, while I have only 12 (9 rotation + 3 position).
Might be a super dump question, but I dont work with matrixes too often

``````                r[0]  = x.x;
r[1]  = x.y;
r[2]  = x.z;
r[3]  = 0;
r[4]  = y.x;
r[5]  = y.y;
r[6]  = y.z;
r[7]  = 0;
r[8]  = z.x;
r[9]  = z.y;
r[10] = z.z;
r[11] = 0;
r[12] = position.x;
r[13] = position.y;
r[14] = position.z;
r[15] = 1;
``````

Just quickly copied from the mat4.js file in the engine source.

One thing to keep in mind that PlayCanvas uses the right hand coordinate system where -Z is ‘forward’ so you may have to do some converting depending on which handiness your current matrices are in.

Yeah that seems to do the job on the first look, if I invert y & z on the matrix.

Will see tomorrow, if everything works as supposed, enough for today
Nether less, already thanks a lot yaustar, as usual super quick & helpful. I think I would have spent the rest of the evening without a result