Chase cam

1,611 views
Skip to first unread message

Fidel Perez-Smith

unread,
Apr 9, 2017, 10:10:52 AM4/9/17
to cesium-dev
Hi,

Is it possible to set the camera view to be locked behind the aircraft, in essence a chase cam?

I'm using the 3D Models sandcastle and I'm aiming to have the camera locked in this position:

Thank you,
Fidel


Rachel Hwang

unread,
Apr 11, 2017, 2:05:05 PM4/11/17
to cesium-dev
Hey,

We don't have direct support for a follow-cam right now, but you can right one yourself by updating camera position whenever the model moves. See the camera tutorial for some help: http://cesiumjs.org/tutorials/Camera-Tutorial/

Best,
- Rachel

Matthew Amato

unread,
Apr 14, 2017, 8:30:42 PM4/14/17
to cesiu...@googlegroups.com
Fidel,


The chase cam set up is at the bottom, I've re-pasted the relevant bits below.  Basically, you need to get the position and orientation of the entity, create a transform model matrix out of that, and then apply it to the camera where the offset is in reference to the object (negative X is behind, positive Y rotates right, and positive Z is above). We should probably have a chase cam example in Sandcastle.

//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);
    camera.lookAtTransform(scratch, new Cesium.Cartesian3(-50, 0, 10));
});

Hope that helps,

Matt

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Fidel Perez-Smith

unread,
Apr 15, 2017, 9:40:16 AM4/15/17
to cesium-dev
Thanks so much Matt, that looks perfect
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

Rachel Hwang

unread,
Apr 18, 2017, 1:15:59 PM4/18/17
to cesium-dev
Also, we're currently working on a drone racing game that uses a follow cam! The code isn't quite ready to be shared, but we plan on incorporating our trailing camera mode into core Cesium once we've cleaned up a bit. We'll keep you updated. :)

Fidel Perez-Smith

unread,
Apr 20, 2017, 2:38:50 AM4/20/17
to cesium-dev
That is superb. It worked perfectly. Thank you so much


On Saturday, 15 April 2017 10:30:42 UTC+10, Matthew Amato wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

Rachel Hwang

unread,
Apr 25, 2017, 6:17:12 PM4/25/17
to cesium-dev
Hi Fidel,

Just wanted to let you know, we've opened an issue for a follow camera. I can't make any promises about when we'll get our work merged into Cesium, but know that it's in active development and we'll keep you updated. Here's the issue.


Best,
- Rachel
Message has been deleted

xuncanzhe

unread,
May 15, 2017, 4:09:19 AM5/15/17
to cesium-dev
Hi Matt,

     I have some questions about camera control. Why the camera's posture needs three directions, direction/up/right. According to my understanding, the two directions to determine the camera posture should be completely enough, the third direction can be calculated according to the other two. Why i only set the two directions did not achieve the effect? 
viewer.clock.onTick.addEventListener(function(clock) {
var camera = viewer.camera;

var tempP = temp_entity.position.getValueInReferenceFrame(clock.currentTime, Cesium.ReferenceFrame.FIXED);
var tempMatrix3 = new Cesium.Matrix3.fromQuaternion(temp_entity.orientation.getValue(clock.currentTime));
var testDirection = new Cesium.Cartesian3(1.0 , 0.0, 0.0);
var upDirection = new Cesium.Cartesian3(0.0 , 0.0, 1);
Cesium.Matrix3.multiplyByVector(tempMatrix3, testDirection, testDirection);
Cesium.Matrix3.multiplyByVector(tempMatrix3, upDirection, upDirection);
var modelMatrix = Cesium.Matrix4.fromRotationTranslation(tempMatrix3,tempP);;
getModelMatrix(temp_entity, viewer.clock.currentTime, scratch);
console.log("------------------------start");
console.log(model.modelMatrix);
console.log(scratch);
console.log(model.modelMatrix.equals(scratch)); //is true
console.log("------------------------end");
//way 1
camera.lookAtTransform(model.modelMatrix, new Cesium.Cartesian3(-10, 0, 2));
//way 2
camera.position = tempP.clone();
     camera.direction = testDirection.clone();
     camera.up = upDirection.clone();

});
Way1 is normal. But way2 is somewhat weird. https://groups.google.com/forum/embed/?place=forum%2Fcesium-dev&showsearch=true&showpopout=true&hideforumtitle=true&fragments=true&parenturl=http%3A%2F%2Fcesiumjs.org%2Fforum.html#!topic/cesium-dev/tGeRe4c9yG4 if i add the camera.up will work. When the two directions are set in Cesium.camera, the third direction is not automatically updated? Causing this third direction to interfere with the camera's posture. This is just my guess, is it so? 


Xuncanzhe

在 2017年4月15日星期六 UTC+8上午8:30:42,Matthew Amato写道:
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

Rachel Hwang

unread,
May 22, 2017, 3:59:56 PM5/22/17
to cesium-dev
Hi Xuncanzhe,

It's true that you can compute the third direction from the first two, but our camera implementation requires you to provide three orthonormal vectors. Fortunately, as you point out, the computation isn't difficult! Just take the cross product of the first two (and make sure all vectors are normalized).

Hope that helps,
- Rachel
Reply all
Reply to author
Forward
0 new messages