Skip to content

Commit

Permalink
Merge pull request #277 from BarthPaleologue/264-use-keplerian-orbita…
Browse files Browse the repository at this point in the history
…l-elements-to-characterize-orbits-in-orbital-object-models

Change circular orbits to Keplerian orbits
  • Loading branch information
BarthPaleologue authored Feb 1, 2025
2 parents 0c79efd + 6798194 commit a253e08
Show file tree
Hide file tree
Showing 48 changed files with 886 additions and 561 deletions.
1 change: 0 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ This means that in the previous diagram, in the `Orbital Objects` tree, are only
classDiagram
class OrbitalObject {
+getOrbitSettings()
+getRotationAxis()
+updateOrbitPosition()
+updateRotation()
}
Expand Down
2 changes: 2 additions & 0 deletions src/styles/targetCursors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

cursor: none;

pointer-events: none;

&.transparent {
opacity: 0;
pointer-events: none;
Expand Down
27 changes: 13 additions & 14 deletions src/ts/alphaTestis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { newSeededTelluricSatelliteModel } from "./planets/telluricPlanet/tellur
import { newSeededTelluricPlanetModel } from "./planets/telluricPlanet/telluricPlanetModel";
import { newSeededSpaceElevatorModel } from "./spacestation/spaceElevatorModel";
import { celsiusToKelvin, getOrbitRadiusFromPeriod } from "./utils/physics";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Tools } from "@babylonjs/core/Misc/tools";

const engine = await CosmosJourneyer.CreateAsync();
engine.setAutoSaveEnabled(false);
Expand All @@ -51,15 +51,14 @@ const systemCoordinates: StarSystemCoordinates = {

const sunModel = newSeededStarModel(420, "Weierstrass", []);
sunModel.physics.blackBodyTemperature = 5778;
sunModel.orbit.period = 60 * 60 * 24;

/*const secundaModel = new StarModel(-672446, sunModel);
secundaModel.orbit.radius = 30 * sunModel.radius;
secundaModel.orbit.semiMajorAxis = 30 * sunModel.radius;
secundaModel.orbit.period = 60 * 60;
const secunda = StarSystemHelper.makeStar(starSystem, secundaModel);
const terminaModel = new StarModel(756263, sunModel);
terminaModel.orbit.radius = 50 * sunModel.radius;
terminaModel.orbit.semiMajorAxis = 50 * sunModel.radius;
terminaModel.orbit.period = 60 * 60;
const termina = StarSystemHelper.makeStar(starSystem, terminaModel);*/

Expand All @@ -69,9 +68,7 @@ hecateModel.physics.maxTemperature = celsiusToKelvin(30);

hecateModel.physics.siderealDaySeconds = 6 * 60 * 60;

hecateModel.orbit.period = 60 * 60 * 24 * 365.25;
hecateModel.orbit.radius = 25000 * hecateModel.radius;
hecateModel.orbit.orientation = Quaternion.Identity();
hecateModel.orbit.semiMajorAxis = 21000 * hecateModel.radius;

const spaceStationModel = newSeededSpaceElevatorModel(
0,
Expand All @@ -93,8 +90,12 @@ moonModel.physics.minTemperature = celsiusToKelvin(-180);
moonModel.physics.maxTemperature = celsiusToKelvin(200);
moonModel.physics.waterAmount = 0.9;

moonModel.orbit.period = moonModel.physics.siderealDaySeconds;
moonModel.orbit.radius = getOrbitRadiusFromPeriod(moonModel.orbit.period, hecateModel.physics.mass);
moonModel.orbit.inclination = Tools.ToRadians(45);

moonModel.orbit.semiMajorAxis = getOrbitRadiusFromPeriod(
moonModel.physics.siderealDaySeconds,
hecateModel.physics.mass
);

const aresModel = newSeededTelluricPlanetModel(0.3725, "Ares", [sunModel]);
if (aresModel.clouds !== null) aresModel.clouds.coverage = 1;
Expand All @@ -106,17 +107,15 @@ aresModel.physics.pressure = Settings.EARTH_SEA_LEVEL_PRESSURE * 0.5;
aresModel.physics.waterAmount = 0.2;
aresModel.physics.oceanLevel = 0;

aresModel.orbit.period = 60 * 60 * 24 * 365.24;
aresModel.orbit.radius = 25020 * hecateModel.radius;
aresModel.orbit.semiMajorAxis = 25100 * hecateModel.radius;

//aresModel.terrainSettings.continents_fragmentation = 0.0;
//aresModel.terrainSettings.continent_base_height = 10e3;
//aresModel.terrainSettings.max_mountain_height = 20e3;

const andromaqueModel = newSeededGasPlanetModel(0.28711440474126226, "Andromaque", [sunModel]);
andromaqueModel.orbit.period = 60 * 60 * 24 * 365.25;
andromaqueModel.orbit.radius = 25300 * hecateModel.radius;
andromaqueModel.orbit.orientation = Quaternion.Identity();
andromaqueModel.orbit.semiMajorAxis = 25300 * hecateModel.radius;
andromaqueModel.orbit.eccentricity = 0.8;

const starSystemModel: StarSystemModel = {
name: systemName,
Expand Down
25 changes: 12 additions & 13 deletions src/ts/anomalies/julia/juliaSetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,23 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { normalRandom } from "extended-random";
import { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { Orbit } from "../../orbit/orbit";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { GenerationSteps } from "../../utils/generationSteps";
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { AnomalyModel } from "../anomaly";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { Tools } from "@babylonjs/core/Misc/tools";

export type JuliaSetModel = AnomalyModel & {
readonly type: OrbitalObjectType.JULIA_SET;
readonly accentColor: Color3;
};

export function newSeededJuliaSetModel(seed: number, name: string, parentBodies: CelestialBodyModel[]): JuliaSetModel {
export function newSeededJuliaSetModel(seed: number, name: string): JuliaSetModel {
const rng = getRngFromSeed(seed);

const radius = 1000e3;
Expand All @@ -45,23 +43,24 @@ export function newSeededJuliaSetModel(seed: number, name: string, parentBodies:
);

// Todo: do not hardcode
let orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));
orbitRadius += orbitRadius - getPeriapsis(orbitRadius, orbitalP);

const parentMassSum = parentBodies?.reduce((sum, body) => sum + body.physics.mass, 0) ?? 0;
const orbit: Orbit = {
radius: orbitRadius,
semiMajorAxis: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.Identity()
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT))
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
Expand Down
27 changes: 11 additions & 16 deletions src/ts/anomalies/mandelbox/mandelboxModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { AnomalyModel } from "../anomaly";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { Tools } from "@babylonjs/core/Misc/tools";

export type MandelboxModel = AnomalyModel & {
readonly type: OrbitalObjectType.MANDELBOX;
Expand All @@ -43,11 +41,7 @@ export type MandelboxModel = AnomalyModel & {
readonly spread: number;
};

export function newSeededMandelboxModel(
seed: number,
name: string,
parentBodies: CelestialBodyModel[]
): MandelboxModel {
export function newSeededMandelboxModel(seed: number, name: string): MandelboxModel {
const rng = getRngFromSeed(seed);

const radius = 200e3;
Expand All @@ -61,23 +55,24 @@ export function newSeededMandelboxModel(
);

// Todo: do not hardcode
let orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));
orbitRadius += orbitRadius - getPeriapsis(orbitRadius, orbitalP);

const parentMassSum = parentBodies?.reduce((sum, body) => sum + body.physics.mass, 0) ?? 0;
const orbit: Orbit = {
radius: orbitRadius,
semiMajorAxis: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.Identity()
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT))
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
Expand Down
28 changes: 11 additions & 17 deletions src/ts/anomalies/mandelbulb/mandelbulbModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,21 @@
import { Color3 } from "@babylonjs/core/Maths/math.color";
import { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { AnomalyModel } from "../anomaly";

import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { Tools } from "@babylonjs/core/Misc/tools";

export type MandelbulbModel = AnomalyModel & {
readonly type: OrbitalObjectType.MANDELBULB;
readonly power: number;
readonly accentColor: Color3;
};

export function newSeededMandelbulbModel(
seed: number,
name: string,
parentBodies: CelestialBodyModel[]
): MandelbulbModel {
export function newSeededMandelbulbModel(seed: number, name: string): MandelbulbModel {
const rng = getRngFromSeed(seed);

const radius = 1000e3;
Expand All @@ -52,23 +45,24 @@ export function newSeededMandelbulbModel(
);

// Todo: do not hardcode
let orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));
orbitRadius += orbitRadius - getPeriapsis(orbitRadius, orbitalP);

const parentMassSum = parentBodies?.reduce((sum, body) => sum + body.physics.mass, 0) ?? 0;
const orbit: Orbit = {
radius: orbitRadius,
semiMajorAxis: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.Identity()
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT))
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
Expand Down
29 changes: 12 additions & 17 deletions src/ts/anomalies/mengerSponge/mengerSpongeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,22 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import { Color3 } from "@babylonjs/core/Maths/math.color";
import { normalRandom } from "extended-random";
import { normalRandom, randRange } from "extended-random";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { Orbit } from "../../orbit/orbit";
import { GenerationSteps } from "../../utils/generationSteps";
import { OrbitalObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { AnomalyModel } from "../anomaly";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { Tools } from "@babylonjs/core/Misc/tools";

export type MengerSpongeModel = AnomalyModel & {
readonly type: OrbitalObjectType.MENGER_SPONGE;
readonly accentColor: Color3;
};

export function newSeededMengerSpongeModel(
seed: number,
name: string,
parentBodies: CelestialBodyModel[]
): MengerSpongeModel {
export function newSeededMengerSpongeModel(seed: number, name: string): MengerSpongeModel {
const rng = getRngFromSeed(seed);

const radius = 200e3;
Expand All @@ -49,23 +43,24 @@ export function newSeededMengerSpongeModel(
);

// Todo: do not hardcode
let orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;
const orbitRadius = rng(GenerationSteps.ORBIT) * 15e9;

const orbitalP = clamp(0.5, 3.0, normalRandom(1.0, 0.3, rng, GenerationSteps.ORBIT + 80));
orbitRadius += orbitRadius - getPeriapsis(orbitRadius, orbitalP);

const parentMassSum = parentBodies?.reduce((sum, body) => sum + body.physics.mass, 0) ?? 0;
const orbit: Orbit = {
radius: orbitRadius,
semiMajorAxis: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.Identity()
inclination: Tools.ToRadians(normalRandom(90, 20, rng, GenerationSteps.ORBIT + 160)),
eccentricity: randRange(0.1, 0.9, rng, GenerationSteps.ORBIT + 240),
longitudeOfAscendingNode: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 320),
argumentOfPeriapsis: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 400),
initialMeanAnomaly: randRange(0, 2 * Math.PI, rng, GenerationSteps.ORBIT + 480)
};

const physicalProperties: OrbitalObjectPhysicsInfo = {
mass: 10,
siderealDaySeconds: 0,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT))
axialTilt: normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)
};

return {
Expand Down
Loading

0 comments on commit a253e08

Please sign in to comment.