home / blog

Cesium 3D model translation

If you’re using the primitive API rather than the entity API then you do not have easy access to the orientation parameters.

It’s possible to do all this from scratch, but it’s hard work….

var getModelMatrix = function(lon, lat, rotationZ) {
    // 1) create a translation position matrix
    var posMat = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(lon, lat));

    // 2) create a Matrix3 with a given Z rotation
    var rotMat3 = Cesium.Matrix3.fromRotationZ(Math.random() * 360);                        

    // 3) transform the Matrix3 into a Matrix4 with no translation
    var rotMat4 = Cesium.Matrix4.fromRotationTranslation(rotMat3, undefined, undefined);

    // 4) empty matrix to place result in
    var result = new Cesium.Matrix4();

    // 5) multiply position by rotation
    return Cesium.Matrix4.multiply(posMat, rotMat4, result);             
This entry was posted in geek and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.