Gravity: one potential per zone owns acceleration and height
GravityField is the law of one well (logarithmic tail, softened core).
Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from
the force for ship tilt; Flow and Ship read GetForce. Well strength, core
radius and Roche limit are PlanetSettings curves of mass, height
exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate,
GravityStrength, the PowerPulse well, GetNormal's finite differences and
BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves.
Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every
BodyData type, a body-derived giant sweep. Not yet built or run (verify job
follows); this commit may not build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 04:36:28 +02:00
|
|
|
using CultMath;
|
|
|
|
|
using static CultMath.math;
|
|
|
|
|
using float2 = CultMath.float2;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The law of one gravity well: a 2D point mass with a softened core. Outside the core radius the potential is
|
|
|
|
|
/// logarithmic and the pull is c / r; inside it the pull falls linearly to zero at the centre and meets the tail in
|
|
|
|
|
/// value and slope at the core radius. c is the well's strength (u^2/s^2), R its core radius (u). No threshold
|
|
|
|
|
/// anywhere: a well pulls at every distance. Zone.GetForce and Zone.GetHeight sum this over a zone's bodies.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class GravityField
|
|
|
|
|
{
|
2026-10-15 08:44:11 +02:00
|
|
|
// The tail's additive constant: it makes the tail meet the core in value at the core radius. Gravity.cginc is generated from it.
|
|
|
|
|
public const float TailOffset = .5f;
|
|
|
|
|
|
Gravity: one potential per zone owns acceleration and height
GravityField is the law of one well (logarithmic tail, softened core).
Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from
the force for ship tilt; Flow and Ship read GetForce. Well strength, core
radius and Roche limit are PlanetSettings curves of mass, height
exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate,
GravityStrength, the PowerPulse well, GetNormal's finite differences and
BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves.
Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every
BodyData type, a body-derived giant sweep. Not yet built or run (verify job
follows); this commit may not build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 04:36:28 +02:00
|
|
|
// The potential at distance r from the body, defined up to a constant (callers subtract their reference).
|
2026-10-15 05:02:48 +02:00
|
|
|
// A well of no strength (a body whose curves are unauthored, so c = 0 and R = 0) digs nothing.
|
Gravity: one potential per zone owns acceleration and height
GravityField is the law of one well (logarithmic tail, softened core).
Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from
the force for ship tilt; Flow and Ship read GetForce. Well strength, core
radius and Roche limit are PlanetSettings curves of mass, height
exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate,
GravityStrength, the PowerPulse well, GetNormal's finite differences and
BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves.
Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every
BodyData type, a body-derived giant sweep. Not yet built or run (verify job
follows); this commit may not build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 04:36:28 +02:00
|
|
|
public static float Potential(float c, float coreRadius, float r) =>
|
2026-10-15 05:02:48 +02:00
|
|
|
c == 0f ? 0f :
|
Gravity: one potential per zone owns acceleration and height
GravityField is the law of one well (logarithmic tail, softened core).
Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from
the force for ship tilt; Flow and Ship read GetForce. Well strength, core
radius and Roche limit are PlanetSettings curves of mass, height
exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate,
GravityStrength, the PowerPulse well, GetNormal's finite differences and
BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves.
Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every
BodyData type, a body-derived giant sweep. Not yet built or run (verify job
follows); this commit may not build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 04:36:28 +02:00
|
|
|
r < coreRadius
|
|
|
|
|
? c * r * r / (2 * coreRadius * coreRadius)
|
2026-10-15 08:44:11 +02:00
|
|
|
: c * (log(r / coreRadius) + TailOffset);
|
Gravity: one potential per zone owns acceleration and height
GravityField is the law of one well (logarithmic tail, softened core).
Zone.GetForce and GetHeight sum it over the bodies; GetNormal derives from
the force for ship tilt; Flow and Ship read GetForce. Well strength, core
radius and Roche limit are PlanetSettings curves of mass, height
exaggeration K one global. Deletes GravityAcceleration, GravityReferenceRate,
GravityStrength, the PowerPulse well, GetNormal's finite differences and
BodyData.GravityDepthExponent. Settings.asset carries the calibrated curves.
Tests: PotentialOwnerTests, the moon's moon placement, retired keys over every
BodyData type, a body-derived giant sweep. Not yet built or run (verify job
follows); this commit may not build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 04:36:28 +02:00
|
|
|
|
|
|
|
|
// The acceleration at `offsetFromBody`, toward the body: zero at the body itself.
|
|
|
|
|
public static float2 Acceleration(float c, float coreRadius, float2 offsetFromBody)
|
|
|
|
|
{
|
|
|
|
|
var r = length(offsetFromBody);
|
|
|
|
|
if (r == 0f) return float2.zero;
|
|
|
|
|
var pull = r < coreRadius ? c * r / (coreRadius * coreRadius) : c / r;
|
|
|
|
|
return -offsetFromBody / r * pull;
|
|
|
|
|
}
|
|
|
|
|
}
|