Model orientation/rotation

I’m trying to rotate a model around its Y axis.
All code that I see setting a model position uses Cesium.Transforms.eastNorthUpToFixedFrame()
I though about multiplying the result of that with a rotation matrix, but rotation matrices are 3x3 and this returns a 4x4 matrix.

So I tried using the following code:

var rotMat = Cesium.Matrix3.fromRotationY(this._rotation);
targetObject.modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotMat, this._position, this._transformMatrix);

“this._rotation” is in radians, however the rotations look completly wrong.
Is there another way to do this?

Hi Sergio,

Once you have the 4x4 rotation matrix, multiple it with the east-north-up matrix. In your code, _transformMatrix is just getting overwritten. See https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Matrix4.js#L1271

Patrick

Thanks Patrick, I changed the code a bit and it now works.
However it seems there isnt any method to transform a Matrix3 to Matrix4, as required for the matrix mult.

This is my working code in case anyone needs:

        var rotation = Cesium.Matrix3.fromRotationZ(this._rotation);                       
        var rotMat = new Cesium.Matrix4(rotation[0], rotation[3], rotation[6], 0.0,
                           rotation[1], rotation[4], rotation[7], 0.0,
                           rotation[2], rotation[5], rotation[8], 0.0,
                                   0.0,         0.0,         0.0,           1.0);
                                  
        var posMat =  Cesium.Transforms.eastNorthUpToFixedFrame(this._position);                                      
       
        targetObject.modelMatrix = Cesium.Matrix4.multiply(posMat, rotMat, this._transformMatrix);

Sergio,

Use fromRotationTranslation with Cesium.Cartesian3.ZERO for the translation parameter:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Matrix4.js#L296

Patrick