Improve Cesium cruise smoothness
This commit is contained in:
@@ -365,7 +365,8 @@
|
||||
polyline: {
|
||||
positions: Cesium.Cartesian3.fromDegreesArrayHeights(flat),
|
||||
width: 2,
|
||||
material: routeColor.withAlpha(0.75),
|
||||
material: routeColor,
|
||||
arcType: Cesium.ArcType.NONE,
|
||||
clampToGround: false
|
||||
}
|
||||
});
|
||||
@@ -434,9 +435,12 @@
|
||||
const up = new Cesium.Cartesian3();
|
||||
const east = new Cesium.Cartesian3();
|
||||
const north = new Cesium.Cartesian3();
|
||||
const aheadTime = new Cesium.JulianDate();
|
||||
const hpr = new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0);
|
||||
const base = new Cesium.Quaternion();
|
||||
return new Cesium.CallbackProperty((time, result) => {
|
||||
routePosition(route, start, time, speed, current);
|
||||
const aheadTime = Cesium.JulianDate.addSeconds(time, 0.8, new Cesium.JulianDate());
|
||||
Cesium.JulianDate.addSeconds(time, 0.8, aheadTime);
|
||||
routePosition(route, start, aheadTime, speed, ahead);
|
||||
Cesium.Cartesian3.subtract(ahead, current, direction);
|
||||
if (Cesium.Cartesian3.magnitudeSquared(direction) < 0.0001) {
|
||||
@@ -454,10 +458,13 @@
|
||||
Cesium.Cartesian3.normalize(north, north);
|
||||
const eastComponent = Cesium.Cartesian3.dot(direction, east);
|
||||
const northComponent = Cesium.Cartesian3.dot(direction, north);
|
||||
const heading = Math.atan2(eastComponent, northComponent);
|
||||
const base = Cesium.Transforms.headingPitchRollQuaternion(
|
||||
hpr.heading = Math.atan2(eastComponent, northComponent);
|
||||
Cesium.Transforms.headingPitchRollQuaternion(
|
||||
current,
|
||||
new Cesium.HeadingPitchRoll(heading, 0.0, 0.0)
|
||||
hpr,
|
||||
undefined,
|
||||
undefined,
|
||||
base
|
||||
);
|
||||
return Cesium.Quaternion.multiply(base, correction, result || new Cesium.Quaternion());
|
||||
}, false);
|
||||
@@ -470,6 +477,9 @@
|
||||
const scratchEast = new Cesium.Cartesian3();
|
||||
const scratchNorth = new Cesium.Cartesian3();
|
||||
const scratchUp = new Cesium.Cartesian3();
|
||||
const scratchPreviousTime = new Cesium.JulianDate();
|
||||
const scratchHpr = new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0);
|
||||
const scratchTransform = new Cesium.Matrix4();
|
||||
const offset = new Cesium.Cartesian3();
|
||||
const state = { enabled: false, distance: 36.0, height: 18.0 };
|
||||
|
||||
@@ -478,8 +488,8 @@
|
||||
const positions = positionsProvider();
|
||||
const position = positions.getValue(time, scratchPosition);
|
||||
if (!position) return;
|
||||
const previousTime = Cesium.JulianDate.addSeconds(time, -0.8, new Cesium.JulianDate());
|
||||
const previous = positions.getValue(previousTime, scratchPrevious);
|
||||
Cesium.JulianDate.addSeconds(time, -0.8, scratchPreviousTime);
|
||||
const previous = positions.getValue(scratchPreviousTime, scratchPrevious);
|
||||
if (previous) {
|
||||
Cesium.Cartesian3.subtract(position, previous, scratchDirection);
|
||||
} else {
|
||||
@@ -501,13 +511,16 @@
|
||||
|
||||
const eastComponent = Cesium.Cartesian3.dot(scratchDirection, scratchEast);
|
||||
const northComponent = Cesium.Cartesian3.dot(scratchDirection, scratchNorth);
|
||||
const heading = Math.atan2(eastComponent, northComponent);
|
||||
scratchHpr.heading = Math.atan2(eastComponent, northComponent);
|
||||
Cesium.Cartesian3.fromElements(0.0, -state.distance, state.height, offset);
|
||||
const transform = Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
Cesium.Transforms.headingPitchRollToFixedFrame(
|
||||
position,
|
||||
new Cesium.HeadingPitchRoll(heading, 0.0, 0.0)
|
||||
scratchHpr,
|
||||
undefined,
|
||||
undefined,
|
||||
scratchTransform
|
||||
);
|
||||
viewer.camera.lookAtTransform(transform, offset);
|
||||
viewer.camera.lookAtTransform(scratchTransform, offset);
|
||||
}
|
||||
|
||||
function onWheel(event) {
|
||||
|
||||
Reference in New Issue
Block a user