Why does camera.lookatTransform stop rendering

Hi, I’m using camera.lookatTransform method to adjust my camera to achieve pilot view. My code is like this:

{

text:‘track plane from pilot view’,

onselect:function(){

viewer.clock.onTick.addEventListener(function(clock){

var referencePoint=positions.getValue(clock.currentTime);

var transform=Cesium.Matrix4.fromTranslationQuaternionRotationScale(

plane05.position.getValue(clock.currentTime),

plane05.orientation.getValue(clock.currentTime),

new Cesium.Cartesian3(1,1,1),

new Cesium.Matrix4()

);

// always look at the plane from behind

viewer.camera.lookAtTransform(transform, new Cesium.Cartesian3(-100.0,0.0,100.0));

});

}

}

Whenever I run this code, it stops rendering and alerts ‘Normal must be normalized.’ Can anybody kindly tell me what’s wrong with my code? Or is there a better way to adjust the camera so that I can track the plane and keep looking from behind it?

Hi there,

Check out this thread on creating a follow-camera: https://groups.google.com/forum/?hl=en#!searchin/cesium-dev/chase$20cam|sort:relevance/cesium-dev/-mDNh2qlTZQ/8Zk9zbQUAQAJ

That code should work for you.

Hope that helps,

  • Rachel

Thank you very much for your time, Rachel. I ran that demo in sandcastle successfully, but it won’t work locally.
I add console.log() to test

//Set up chase camera

var matrix3Scratch = new Cesium.Matrix3();

var positionScratch = new Cesium.Cartesian3();

var orientationScratch = new Cesium.Quaternion();

function getModelMatrix(entity, time, result) {

var position = Cesium.Property.getValueOrUndefined(entity.position, time, positionScratch);

if (!Cesium.defined(position)) {

return undefined;

}

var orientation = Cesium.Property.getValueOrUndefined(entity.orientation, time, orientationScratch);

if (!Cesium.defined(orientation)) {

result = Cesium.Transforms.eastNorthUpToFixedFrame(position, undefined, result);

} else {

result = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation, matrix3Scratch), position, result);

}

return result;

}

var scratch = new Cesium.Matrix4();

var camera = viewer.scene.camera;

viewer.scene.preRender.addEventListener(function(){

getModelMatrix(entity, viewer.clock.currentTime, scratch);

**console.log(scratch);**

camera.lookAtTransform(scratch, new Cesium.Cartesian3(-50, 0, 10));

});

It seems that rendering stops after several successful iterations. I am really puzzled.

Germaine

Hi Germaine,

If it works in th sandcastle but not locally, make sure your Cesium is up to date with the latest release.

Best,

  • Rachel