diff --git a/Apps/Sandcastle/gallery/Moon.html b/Apps/Sandcastle/gallery/Moon.html
index 381a78ae9a62..e3d49678815a 100644
--- a/Apps/Sandcastle/gallery/Moon.html
+++ b/Apps/Sandcastle/gallery/Moon.html
@@ -37,13 +37,10 @@
Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhZDUyNTc2YS1hMmQyLTQ2NGUtYmE2Ny01ZmQ5MmRmNGEyOGQiLCJpZCI6MTQsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1ODgxODAxNDB9.q3KJVaTTtaMs404afZYo2RQSbYglE09Xfrm7BkZP694";
+ Cesium.Ellipsoid.default = Cesium.Ellipsoid.MOON;
const moonOptions = {
- ellipsoid: Cesium.Ellipsoid.MOON,
terrainProvider: await Cesium.CesiumTerrainProvider.fromIonAssetId(
- 1238,
- {
- ellipsoid: Cesium.Ellipsoid.MOON,
- }
+ 1238
),
baseLayer: Cesium.ImageryLayer.fromProviderAsync(
Cesium.IonImageryProvider.fromAssetId(1208)
@@ -53,12 +50,17 @@
const viewer = new Cesium.Viewer("cesiumContainer", {
...moonOptions,
useBrowserRecommendedResolution: false,
- timeline: false,
- animation: false,
+ //timeline: false,
+ //animation: false,
baseLayerPicker: false,
geocoder: false,
});
- viewer.scene.msaaSamples = 4;
+ viewer.clock.multiplier = 3 * 60 * 60 * 24;
+ viewer.clock.shouldAnimate = true;
+
+ const scene = viewer.scene;
+ scene.msaaSamples = 4;
+ scene.globe.enableLighting = true;
// Positions courtesy of https://www.sciencedirect.com/science/article/abs/pii/S0019103516301518?via%3Dihub
const pointsOfInterest = [
diff --git a/packages/engine/Source/Core/Simon1994PlanetaryPositions.js b/packages/engine/Source/Core/Simon1994PlanetaryPositions.js
index 990a9f850b7f..cf733d6a02a4 100644
--- a/packages/engine/Source/Core/Simon1994PlanetaryPositions.js
+++ b/packages/engine/Source/Core/Simon1994PlanetaryPositions.js
@@ -627,6 +627,7 @@ const axesTransformation = new Matrix3(
0.9174820620691819
);
let translation = new Cartesian3();
+
/**
* Computes the position of the Sun in the Earth-centered inertial frame
*
@@ -662,7 +663,7 @@ Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame = function (
/**
* Computes the position of the Moon in the Earth-centered inertial frame
*
- * @param {JulianDate} [julianDate] The time at which to compute the Sun's position, if not provided the current system time is used.
+ * @param {JulianDate} [julianDate] The time at which to compute the Moon's position, if not provided the current system time is used.
* @param {Cartesian3} [result] The object onto which to store the result.
* @returns {Cartesian3} Calculated moon position
*/
@@ -681,11 +682,11 @@ Simon1994PlanetaryPositions.computeMoonPositionInEarthInertialFrame = function (
};
/**
- * Computes the position of the Sun in the Moon-centered inertial frame
+ * Computes the position of the Sun in the Moon-centered fixed frame
*
* @param {JulianDate} [julianDate] The time at which to compute the Sun's position, if not provided the current system time is used.
* @param {Cartesian3} [result] The object onto which to store the result.
- * @returns {Cartesian3} Calculated sun position
+ * @returns {Cartesian3} Calculated Sun position
*/
Simon1994PlanetaryPositions.computeSunPositionInMoonInertialFrame = function (
julianDate,
@@ -707,7 +708,8 @@ Simon1994PlanetaryPositions.computeSunPositionInMoonInertialFrame = function (
computeSimonMoon(julianDate, translation);
Cartesian3.subtract(result, translation, result);
- Matrix3.multiplyByVector(axesTransformation, result, result);
+
+ //Matrix3.multiplyByVector(rotation, result, result); TODO: ?
return result;
};
diff --git a/packages/engine/Source/Core/Transforms.js b/packages/engine/Source/Core/Transforms.js
index 3bea2f359d85..713b663d157a 100644
--- a/packages/engine/Source/Core/Transforms.js
+++ b/packages/engine/Source/Core/Transforms.js
@@ -726,6 +726,77 @@ Transforms.computeIcrfToFixedMatrix = function (date, result) {
return Matrix3.transpose(fixedToIcrfMtx, result);
};
+const TdtMinusTai = 32.184;
+const J2000d = 2451545;
+const scratchHpr = new HeadingPitchRoll();
+const scratchRotationMatrix = new Matrix3();
+const dateScratch = new JulianDate();
+Transforms.computeMoonFixedToIcrfMatrix = function (date, result) {
+ //>>includeStart('debug', pragmas.debug);
+ if (!defined(date)) {
+ throw new DeveloperError("date is required.");
+ }
+ //>>includeEnd('debug');
+
+ if (!defined(result)) {
+ result = new Matrix3();
+ }
+
+ // Converts TAI to TT
+ const secondsTT = JulianDate.addSeconds(date, TdtMinusTai, dateScratch);
+
+ // Converts TT to TDB, interval in days since the standard epoch
+ const d = JulianDate.totalDays(secondsTT) - J2000d;
+
+ // Compute the approximate rotation, using https://articles.adsabs.harvard.edu//full/1980CeMec..22..205D/0000209.000.html
+ const e1 = CesiumMath.toRadians(12.112) - CesiumMath.toRadians(0.052992) * d;
+ const e2 = CesiumMath.toRadians(24.224) - CesiumMath.toRadians(0.105984) * d;
+ const e3 = CesiumMath.toRadians(227.645) + CesiumMath.toRadians(13.012) * d;
+ const e4 =
+ CesiumMath.toRadians(261.105) + CesiumMath.toRadians(13.340716) * d;
+ const e5 = CesiumMath.toRadians(358.0) + CesiumMath.toRadians(0.9856) * d;
+
+ scratchHpr.heading =
+ CesiumMath.toRadians(270.0) -
+ CesiumMath.toRadians(3.878) * Math.sin(e1) -
+ CesiumMath.toRadians(0.12) * Math.sin(e2) +
+ CesiumMath.toRadians(0.07) * Math.sin(e3) -
+ CesiumMath.toRadians(0.017) * Math.sin(e4);
+ scratchHpr.pitch =
+ CesiumMath.toRadians(66.534) +
+ CesiumMath.toRadians(1.543) * Math.cos(e1) +
+ CesiumMath.toRadians(0.24) * Math.cos(e2) -
+ CesiumMath.toRadians(0.028) * Math.cos(e3) +
+ CesiumMath.toRadians(0.007) * Math.cos(e4);
+ scratchHpr.roll =
+ CesiumMath.toRadians(244.375) +
+ CesiumMath.toRadians(13.17635831) * d +
+ CesiumMath.toRadians(3.558) * Math.sin(e1) +
+ CesiumMath.toRadians(0.121) * Math.sin(e2) -
+ CesiumMath.toRadians(0.064) * Math.sin(e3) +
+ CesiumMath.toRadians(0.016) * Math.sin(e4) +
+ CesiumMath.toRadians(0.025) * Math.sin(e5);
+ return Matrix3.fromHeadingPitchRoll(scratchHpr, scratchRotationMatrix);
+};
+
+Transforms.computeIcrfToMoonFixedMatrix = function (date, result) {
+ //>>includeStart('debug', pragmas.debug);
+ if (!defined(date)) {
+ throw new DeveloperError("date is required.");
+ }
+ //>>includeEnd('debug');
+ if (!defined(result)) {
+ result = new Matrix3();
+ }
+
+ const fixedToIcrfMtx = Transforms.computeMoonFixedToIcrfMatrix(date, result);
+ if (!defined(fixedToIcrfMtx)) {
+ return undefined;
+ }
+
+ return Matrix3.transpose(fixedToIcrfMtx, result);
+};
+
const xysScratch = new Iau2006XysSample(0.0, 0.0, 0.0);
const eopScratch = new EarthOrientationParametersSample(
0.0,
diff --git a/packages/engine/Source/Renderer/UniformState.js b/packages/engine/Source/Renderer/UniformState.js
index 24083c548468..2192fe0bc02c 100644
--- a/packages/engine/Source/Renderer/UniformState.js
+++ b/packages/engine/Source/Renderer/UniformState.js
@@ -1305,19 +1305,21 @@ function setCamera(uniformState, camera) {
);
}
-let transformMatrix = new Matrix3();
+const transformMatrix = new Matrix3();
const sunCartographicScratch = new Cartographic();
function setSunAndMoonDirections(uniformState, frameState) {
- if (
- !defined(
- Transforms.computeIcrfToFixedMatrix(frameState.time, transformMatrix)
- )
- ) {
- transformMatrix = Transforms.computeTemeToPseudoFixedMatrix(
- frameState.time,
- transformMatrix
- );
- }
+ // if (
+ // !defined(
+ // Transforms.computeIcrfToFixedMatrix(frameState.time, transformMatrix)
+ // )
+ // ) {
+ // transformMatrix = Transforms.computeTemeToPseudoFixedMatrix(
+ // frameState.time,
+ // transformMatrix
+ // );
+ // }
+
+ Transforms.computeIcrfToMoonFixedMatrix(frameState.time, transformMatrix);
let position = Simon1994PlanetaryPositions.computeSunPositionInMoonInertialFrame(
frameState.time,