Skip to content

Commit

Permalink
apply tidal lock to telluric and gas planets
Browse files Browse the repository at this point in the history
  • Loading branch information
BarthPaleologue committed Nov 3, 2024
1 parent 9db39c7 commit 2af3033
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
23 changes: 18 additions & 5 deletions src/ts/planets/gasPlanet/gasPlanetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ import { Axis } from "@babylonjs/core/Maths/math.axis";
import { clamp } from "../../utils/math";
import { getOrbitalPeriod, getPeriapsis, Orbit } from "../../orbit/orbit";
import { PlanetaryMassObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { newSeededRingsModel } from "../../rings/ringsModel";
import { GenerationSteps } from "../../utils/generationSteps";

import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { PlanetModel } from "../../architecture/planet";
import { StellarObjectModel } from "../../architecture/stellarObject";
import { getCurrentUniverseYear, getTidalLockingTimescale } from "../../utils/physics";
import { Lerp } from "@babylonjs/core/Maths/math.scalar.functions";

export type GasPlanetModel = PlanetModel & {
readonly type: OrbitalObjectType.GAS_PLANET;
};

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

const radius = randRangeInt(Settings.EARTH_RADIUS * 4, Settings.EARTH_RADIUS * 20, rng, GenerationSteps.RADIUS);
Expand All @@ -57,11 +59,22 @@ export function newSeededGasPlanetModel(seed: number, name: string, parentBodies
orientation: Quaternion.RotationAxis(Axis.X, (rng(GenerationSteps.ORBIT + 20 - 0.5) * 0.2))
};

//FIXME: when Settings.Earth radius gets to 1:1 scale, change this value by a variable in settings
const mass =Settings.JUPITER_MASS * (radius / 69_911e3) ** 3;

const tidalLockingTimescale = getTidalLockingTimescale(parentMassSum, mass, orbitRadius, radius, 0);

const parentMaxBirthYear = parentBodies.reduce((max, body) => Math.max(max, body.birthYear), 0);
const currentAge = getCurrentUniverseYear() - parentMaxBirthYear;

const tidalLockingFactor = Math.min(1, currentAge / tidalLockingTimescale);

const siderealDayDuration = Lerp(60 * 60 * 24, orbit.period, tidalLockingFactor);

const physicalProperties: PlanetaryMassObjectPhysicsInfo = {
//FIXME: when Settings.Earth radius gets to 1:1 scale, change this value by a variable in settings
mass: Settings.JUPITER_MASS * (radius / 69_911e3) ** 3,
mass: mass,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.4, rng, GenerationSteps.AXIAL_TILT)),
siderealDayDuration: (24 * 60 * 60) / 10,
siderealDayDuration: siderealDayDuration,
minTemperature: -180,
maxTemperature: 200,
pressure: 1
Expand Down
48 changes: 29 additions & 19 deletions src/ts/planets/telluricPlanet/telluricPlanetModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,59 @@

import { PlanetModel } from "../../architecture/planet";
import { OrbitalObjectType } from "../../architecture/orbitalObject";
import { CelestialBodyModel } from "../../architecture/celestialBody";
import { getRngFromSeed } from "../../utils/getRngFromSeed";
import { normalRandom, randRangeInt, uniformRandBool } from "extended-random";
import { GenerationSteps } from "../../utils/generationSteps";
import { Settings } from "../../settings";
import { TelluricPlanetaryMassObjectPhysicsInfo } from "../../architecture/physicsInfo";
import { hasLiquidWater } from "../../utils/physics";
import { getCurrentUniverseYear, getTidalLockingTimescale, hasLiquidWater } from "../../utils/physics";
import { CloudsModel, newCloudsModel } from "../../clouds/cloudsModel";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { Quaternion } from "@babylonjs/core/Maths/math";
import { Axis } from "@babylonjs/core/Maths/math.axis";
import { getOrbitalPeriod, Orbit } from "../../orbit/orbit";
import { clamp } from "terrain-generation";
import { newSeededRingsModel, RingsModel } from "../../rings/ringsModel";
import { TelluricPlanetaryMassObjectModel } from "./telluricPlanetaryMassObjectModel";
import { StellarObjectModel } from "../../architecture/stellarObject";
import { Lerp } from "@babylonjs/core/Maths/math.scalar.functions";

export type TelluricPlanetModel = PlanetModel &
TelluricPlanetaryMassObjectModel & {
readonly type: OrbitalObjectType.TELLURIC_PLANET;
};

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

const radius = Math.max(0.3, normalRandom(1.0, 0.1, rng, GenerationSteps.RADIUS)) * Settings.EARTH_RADIUS;

const parentMaxBirthYear = parentBodies.reduce((max, body) => Math.max(max, body.birthYear), 0);

const parentMaxRadius = parentBodies.reduce((max, body) => Math.max(max, body.radius), 0);
// Todo: do not hardcode
const orbitRadius = 2e9 + rng(GenerationSteps.ORBIT) * 15e9 + parentMaxRadius * 1.5;

const orbitalP = 2; //clamp(normalRandom(2.0, 0.3, this.rng, GenerationSteps.Orbit + 80), 0.7, 3.0);

const parentMassSum = parentBodies.reduce((sum, body) => sum + body.physics.mass, 0);
const orbit: Orbit = {
radius: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.RotationAxis(Axis.X, (rng(GenerationSteps.ORBIT + 20) - 0.5) * 0.2)
};

//TODO: make mass dependent on more physical properties like density
const mass = Settings.EARTH_MASS * (radius / 6_371e3) ** 3;

const tidalLockingTimescale = getTidalLockingTimescale(parentMassSum, mass, orbitRadius, radius, 0);

const currentAge = getCurrentUniverseYear() - parentMaxBirthYear;

const tidalLockingFactor = Math.min(1, currentAge / tidalLockingTimescale);

const siderealDayDuration = Lerp(60 * 60 * 24, orbit.period, tidalLockingFactor);

let pressure = Math.max(normalRandom(0.9, 0.2, rng, GenerationSteps.PRESSURE), 0);
if (radius <= 0.3 * Settings.EARTH_RADIUS) pressure = 0;

Expand All @@ -57,7 +81,7 @@ export function newSeededTelluricPlanetModel(seed: number, name: string, parentB
const physicalProperties: TelluricPlanetaryMassObjectPhysicsInfo = {
mass: mass,
axialTilt: Quaternion.RotationAxis(Axis.X, normalRandom(0, 0.2, rng, GenerationSteps.AXIAL_TILT)),
siderealDayDuration: (60 * 60 * 24) / 10,
siderealDayDuration: siderealDayDuration,
minTemperature: minTemperature,
maxTemperature: maxTemperature,
pressure: pressure,
Expand All @@ -75,20 +99,6 @@ export function newSeededTelluricPlanetModel(seed: number, name: string, parentB
clouds = newCloudsModel(radius + physicalProperties.oceanLevel, Settings.CLOUD_LAYER_HEIGHT, physicalProperties.waterAmount, physicalProperties.pressure);
}

const parentMaxRadius = parentBodies.reduce((max, body) => Math.max(max, body.radius), 0);
// Todo: do not hardcode
const orbitRadius = 2e9 + rng(GenerationSteps.ORBIT) * 15e9 + parentMaxRadius * 1.5;

const orbitalP = 2; //clamp(normalRandom(2.0, 0.3, this.rng, GenerationSteps.Orbit + 80), 0.7, 3.0);

const parentMassSum = parentBodies.reduce((sum, body) => sum + body.physics.mass, 0);
const orbit: Orbit = {
radius: orbitRadius,
p: orbitalP,
period: getOrbitalPeriod(orbitRadius, parentMassSum),
orientation: Quaternion.RotationAxis(Axis.X, (rng(GenerationSteps.ORBIT + 20) - 0.5) * 0.2)
};

const terrainSettings = {
continents_frequency: radius / Settings.EARTH_RADIUS,
continents_fragmentation: clamp(normalRandom(0.65, 0.03, rng, GenerationSteps.TERRAIN), 0, 0.95),
Expand Down

0 comments on commit 2af3033

Please sign in to comment.