Moving Models in 1.0

I was wondering what the appropriate method for moving models in 1.0 is now.

bearing = bearing * -1;
var rotMatrix = new Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(bearing));
var left = Cesium.Transforms.eastNorthUpToFixedFrame(this.llaToCartesian(position));
var right = Cesium.Matrix4.fromRotationTranslation(
    new Cesium.Cartesian3(0.0, 0.0, 0 * 0.5)
var modelMatrix = Cesium.Matrix4.multiply(left, right);

I've been using the following code to send a position and bearing and set the position of the model on the globe but I'm getting errors now when attempting to change the modelMatrix. Specifically, I'm getting errors when trying to do the last step, the Cesium.Matrix4.multiply. I'm getting an error that I Cannot set property '0' of undefined.

I thought that it was the first "breaking change" in the changelog, that apparently the result parameter is required on Matrix2, Matrix3, and Matrix4 functions but that didn't seem to help. I'm not really sure how to test this but I wouldn't think that it would be the breaking change where "If Primitive.modelMatrix is changed after creation, it only affects primitives with one instance and only in 3D mode".


Actually, I finally figured it out on my own. The fix for me was, I was just trying to init a variable and pass that as the 3rd param in the multiply function. Initializing the variable as an empty object fixed it. Bearing was the main thing I needed from this. I could move the model, I just couldn't point it in the right direction.

So changing this...

var modelMatrix = Cesium.Matrix4.multiply(left, right);

to this..

var modelMatrix = {};
Cesium.Matrix4.multiply(left, right, modelMatrix);

Glad you found the fix. You’ll get better performance if you replace

var modelMatrix = {};


var modelMatrix = new Cesium.Matrix4();

which will help the JavaScript optimizer.


Awesome, thanks for the input Patrick