I have a bunch of satellites rendered as billboards. When a user picks one, I want to position the camera “above” it looking through the satellite toward my Earth ellipsoid so the satellite billboard is visually centered on the Earth.
I can get the satellite’s position with billboard.getPosition(). I presume I want to make the camera’s ‘target’ be the center of the ellipsoid with Cartesian3.ZERO, and that ‘up’ might be as simple as Cartesian3(0.0, 0.0, 1.0). I’ve tried setting ‘eye’ to the position of the billboard, but it’s not locating the camera anywhere near where I hoped it would be.
I think I’m being dumb/naive or not understanding the proper coordinate systems. The billboard collection has a TEME rotation like:
satBillboards.modelMatrix =
Cesium.Matrix4.fromRotationTranslation(
Cesium.Transforms.computeTemeToPseudoFixedMatrix(now),
Cesium.Cartesian3.ZERO);
Any suggestions?
Thanks!
Hi Chris,
Did you try multiplying by that rotation matrix to get your billboard (and camera) position in world coordinates?
e.g. something like…
var pos = billboard.getPosition();
var pos4 = new Cesium.Cartesian4(pos.x,pos.y,pos.z,1.0);
var satPosWorld = satBillboards.modelMatrix.multiplyByVector(pos4);
or alternatively you might be able to apply the rotation matrix to the camera transform.
Cheers,
Chris
I poked around with some code in the docs for computeTemeToPseudoFixedMatrix
and ended up with something which appears to work:
var target = Cesium.Cartesian3.ZERO;
var up = new Cesium.Cartesian3(0, 0, 1);
var pos = billboard.getPosition();
// Transform to put me "over" satellite location.
scene.getCamera().transform = Cesium.Matrix4.fromRotationTranslation(
Cesium.Transforms.computeTemeToPseudoFixedMatrix(new Cesium.JulianDate()),
Cesium.Cartesian3.ZERO);
eye = new Cesium.Cartesian3.clone(pos);
eye = eye.multiplyByScalar(1.5); // Zoom out a bit from the satellite
scene.getCamera().lookAt(eye, target, up);
I was concerned that this might “double” the transform since I’m already using the TEME to Fixed rotation on the Billboard but that doesn’t seem to be the case. I think I’m confused about what coordinate system the billboard is using.
Moving the camera “out” by 1.5 the distance of the billboard gives me a reasonable view but seems a naive hack
Thanks!