Just to coalesce a couple of threads
https://groups.google.com/forum/#!topic/cesium-dev/4rLKtasnubY
https://groups.google.com/forum/#!topic/cesium-dev/QcaG4hMW9tU
The reference ellipsoid doesn’t clip building basements at many camera tilt ranges, so it’s best to use terrain that does clip. To manually toggle terrain first press the imagery button on the top right, then scroll down to the terrain section (perhaps terrain should have it’s own button?) I’ve created a SandCastle app that allows one to move a building up and down(do full-screen to access all buttons.)
-Zoom out and try it with terrain on and with terrain off. With terrain off set ellipsoid+30 then move down, you’ll notice that there’s no clipping with the reference ellipsoid (well depending on the camera tilt angle.)
-With terrain on tHeight + 30 places the bottom on the terrain and the center is 30 meters above the bottom.
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var CC3 = Cesium.Cartesian3;
var tLon = -90.1922703175/180*Math.PI;
var tLat = 38.6286636758/180*Math.PI;
var mycarto = new Cesium.Cartographic();
mycarto.longitude=tLon;mycarto.latitude=tLat;mycarto.height=0;
console.log(mycarto); //defined
var tHeight=viewer.scene.globe.getHeight(mycarto);
console.log(tHeight); //undefined, but why?
tHeight=110.139218977672; //just manually set for now
var thebox = viewer.entities.add({
name : ‘building’,
position: Cesium.Cartesian3.fromDegrees(-90.1922703175, 38.6286636758, 30),
box : {
dimensions : new Cesium.Cartesian3(40, 30, 60),
material : Cesium.Color.RED,
outline : true,
outlineColor : Cesium.Color.BLACK
}
});
viewer.zoomTo(viewer.entities);
function gohere(height)
{
var test = new Cesium.Cartographic(tLon,tLat,height);
var mypos = Cesium.Ellipsoid.WGS84.cartographicToCartesian(test);
thebox.position = mypos;
}
function upAndDown(scalar)
{
var mycarte = thebox._position._value;
var mynormal = Cesium.Ellipsoid.WGS84.geodeticSurfaceNormal(mycarte);
var relMove = CC3.multiplyByScalar(mynormal,scalar,new CC3());
CC3.add(mycarte,relMove,mycarte);
thebox.position = mycarte;
}
Sandcastle.addToolbarButton(‘up 5 meters’, function()
{upAndDown(5);});
Sandcastle.addToolbarButton(‘down 5 meters’, function()
{upAndDown(-5);});
//note that this is center of the building, not the bottom
Sandcastle.addToolbarButton(‘ellipsoid+30’, function()
{gohere(0+30);});
Sandcastle.addToolbarButton(‘tHeight+10’, function()
{gohere(tHeight+10);});
Sandcastle.addToolbarButton(‘tHeight+20’, function()
{gohere(tHeight+20);});
Sandcastle.addToolbarButton(‘tHeight+30’, function()
{gohere(tHeight+30);});
Sandcastle.addToolbarButton(‘tHeight+40’, function()
{gohere(tHeight+40);});
Sandcastle.addToolbarButton(‘tHeight+50’, function()
{gohere(tHeight+50);});
``
If anyone knows why var tHeight=viewer.scene.globe.getHeight(mycarto); is failing please let me know.