Entity rotation using Matrix3

I want to rotate a 3d model.

I have 3x3 Matrix:

<M_00>-0.9999982912233401</M_00>

<M_01>-0.001636319085375301</M_01>

<M_02>-0.0008602425863163225</M_02>

<M_10>-0.001631068695467463</M_10>

<M_11>0.9999802528616577</M_11>

<M_12>-0.00606906089589293</M_12>

<M_20>0.0008701565192966738</M_20>

<M_21>-0.006067647409696231</M_21>

<M_22>-0.9999812130648239</M_22>

A 3x3 matrix, using the <M_ij> tags, where M_ij

denotes the coefficient of the (i+1)th row and the (j+1)th column of the rotation

matrix.

It defines the rotation matrix transforming world

coordinates into camera coordinates (with axes XRightYDown)

Here is my code:

var matrix3 = new Cesium.Matrix3(parseFloat(M_00), parseFloat(M_01), parseFloat(M_02), parseFloat(M_10), parseFloat(M_11), parseFloat(M_12), parseFloat(M_20), parseFloat(M_21), parseFloat(M_22));

var matrix4 = Cesium.Matrix4.fromRotationTranslation(matrix3);

var hpr = Cesium.Transforms.fixedFrameToHeadingPitchRoll(matrix4);

var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);

var entity = viewer.entities.add({

position: position,

orientation : orientation,

model : {

uri : url,

scale : 0.6

}

});

This does not set the orientation of model. What am I doing wrong?

I think it might be simpler here to just use the quaternion.fromRotationMatrix function directly on your Matrix3. So your code would look something like:

var matrix3 = new Cesium.Matrix3(parseFloat(M_00), parseFloat(M_01), parseFloat(M_02), parseFloat(M_10), parseFloat(M_11), parseFloat(M_12), parseFloat(M_20), parseFloat(M_21), parseFloat(M_22));

var entity = viewer.entities.add({

position: position,

orientation: Cesium.Quaternion.fromRotationMatrix(matrix3),

model : {

uri : url,

scale : 0.6

}

});

Here’s a running example in Sandcastle.