# 3D Tile Rotation Model Matrix Calculation

Hi, I want to know how to calculate the rotation on 3D tileset.

The intension of the calculation is I want to create a platform to adjust the 3d tiles without using Cesium ion because I don’t want people to login my account but can twist and look at the preview of the model on my Platform.

To calculate the Matrix4 using longitude, latitude, altitude etc. I can use the following code to calculate a Matrix4 and pass into the 3dtile modelMatrix property.

``````const longitude = 114.25;
const latitude = 22.32331;
const height = -24.5000000013;

const position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);

const heading = 180; // in degree
const pitch = 0; // in degree
const roll = 0; // in degree

);

position,
hpr,
);
3dtileset.modelMatrix = resultMatrix;
``````

But this only works when the 3D tile location is not set. Obviously, I can ignore the process on adjusting the location on Cesium Ion and store in my side but that feels not right.

I can calculate the translation part of the model but of course planet earth is not flat, a rotation parameter is also needed.

``````const sourceMatrix = Cesium.Matrix4.transpose(
new Cesium.Matrix4(...root.transform), // get by Cesium API
new Cesium.Matrix4(),
);

const resultMatrix; // in above

const modelMatrix = Cesium.Matrix4.fromTranslation(  Cesium.Cartesian3.subtract(
Cesium.Matrix4.getTranslation(resultMatrix, new Cesium.Cartesian3()),
Cesium.Matrix4.getTranslation(sourceMatrix, new Cesium.Cartesian3()),
new Cesium.Cartesian3(),
););
``````

But I try to calculate the model Quaternion from the Matrix with

``````Cesium.Quaternion.multiply(sourceQuaternion, Cesium.Quaternion.invserse(resultQuaternion), new Cesium.Quaternion())
Cesium.Quaternion.multiply(Cesium.Quaternion.invserse(sourceQuaternion), resultQuaternion, new Cesium.Quaternion())
``````

and pass it into

``````const modelMatrix = Cesium.Matrix4.fromRotationTranslation(
Cesium.Matrix3.fromQuaternion(
modelQuaternion,
),
modelTranslation,
new Cesium.Matrix4(),
);
``````

with no succeed.

So I want to know how to calculate modelMatrix given sourceMatrix from Cesium Ion and resultMatrix from Cesium.Transforms.headingPitchRollToFixedFrame