Axial tilt and sun rotation

This commit is contained in:
Aada 2026-03-03 20:02:39 +02:00
parent 63f4423baf
commit edffc76e05
5 changed files with 129 additions and 28 deletions

View file

@ -8,6 +8,7 @@ using Godot.Collections;
public partial class Main : Control
{
public static Random Random = Random.Shared;
private bool _moving = false;
[Export]
private Node3D _yawNode;
@ -35,17 +36,29 @@ public partial class Main : Control
_planetHelper = new PlanetHelper(_meshInstance, _textureRect);
UpdateStats();
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
AxialTiltChanged(GetNode<LineEdit>("%AxialTilt").Text);
}
Vector3 _pointerPosition = Vector3.Zero;
private const float RayLength = 1000.0f;
private bool _rotateable = false;
public void MouseInViewport()
{
_rotateable = true;
}
public void MouseLeftViewport()
{
_rotateable = false;
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton mouseEvent)
{
if (mouseEvent.ButtonIndex == MouseButton.Left)
{
_moving = mouseEvent.Pressed;
_moving = mouseEvent.Pressed && _rotateable;
}
if (mouseEvent.ButtonIndex == MouseButton.WheelUp)
{
@ -83,8 +96,8 @@ public partial class Main : Control
if (result.Count > 0)
{
Vector3 pos = result["position"].AsVector3();
GD.Print($"Hit: '{pos}'");
pos *= _meshInstance.Transform.Basis.Orthonormalized();
var closest = _planetHelper.Octree.SearchNearest(pos)?.Id;
if (closest != null)
{
@ -95,6 +108,7 @@ public partial class Main : Control
_plate = null;
UpdateStats();
Vector3 vertexPos = _planetHelper.Mdt.GetVertex(_vertex.Id) * 0.01f;
vertexPos *= _meshInstance.Transform.Basis.Inverse().Orthonormalized();
_pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.1f); // vertexPos * 1.01f;
}
@ -110,7 +124,12 @@ public partial class Main : Control
_planetHelper.AutoRun = true;
}
_planetHelper.Process();
GetNode<Node3D>("%Pointer").Position = _pointerPosition;
GetNode<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
if (_sunRotating)
{
GetNode<Node3D>("%Sun").Rotation -= GetNode<Node3D>("%Sun").Rotation;
GetNode<Node3D>("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode<HSlider>("%SunAngle").Value), 0);
}
}
public void UpdateStats()
{
@ -201,4 +220,26 @@ public partial class Main : Control
_resolution = Int32.Parse(change);
_resolution = Math.Clamp(_resolution, 64, 2048);
}
public void AxialTiltChanged(string value)
{
if (float.TryParse(value, out float tilt))
{
_meshInstance.RotateZ(-_meshInstance.Rotation.Z);
_meshInstance.RotateZ(Mathf.DegToRad(tilt));
_axialTilt = tilt;
}
}
private bool _sunRotating = false;
private float _axialTilt = 0f;
public void SunAngleStart()
{
_sunRotating = true;
}
public void SunAngleStop(bool changed)
{
_sunRotating = false;
}
}

View file

@ -13,7 +13,7 @@ public class PlanetHelper
{
public static float RandF(float min, float max)
{
return min + (max - min) * Random.Shared.NextSingle();
return min + (max - min) * Main.Random.NextSingle();
}
public class PlateData(int Id = 0, Color Color = new(), bool IsLandform = false, List<int> Vertices = null)
{
@ -115,7 +115,7 @@ public class PlanetHelper
for (int i = 0; i < Mdt.GetVertexCount(); i++)
{
Octree.Insert(new Node(i, Mdt.GetVertex(i) * 0.001f));
Octree.Insert(new Node(i, Mdt.GetVertex(i) * 0.01f));
Mdt.SetVertexColor(i, Colors.Black);
}
if (_meshInstance.GetSurfaceOverrideMaterial(0) is ShaderMaterial shaderMaterial)
@ -434,7 +434,7 @@ public class PlanetHelper
}
public void SpreadStress()
{
var availableVerts = Vertices.Where(d => d.StageComplete == false && d.IsEdge && d.StrainSamples.Any()).OrderByDescending(d => Mathf.Abs(d.StrainSamples.Max(s => s.Magnitude))).Take(500).ToList();
var availableVerts = Vertices.Where(d => d.StageComplete == false && d.IsEdge && d.StrainSamples.Any()).OrderByDescending(d => Mathf.Abs(d.StrainSamples.Max(s => s.Magnitude))).Take(2500).ToList();
foreach (VertexData vertexData in availableVerts)
{
var neighbours = GetNeighboringVertices(vertexData.Id, false).ToList();
@ -491,7 +491,7 @@ public class PlanetHelper
float mountainNoise = (1.0f + _mountainNoise.GetNoise3Dv(GetVertexPosition(vertexData.Id))) * 0.5f;
float hfNoise = _hfNoise.GetNoise3Dv(GetVertexPosition(vertexData.Id));
var majorStrain = AverageStrainList(vertexData.StrainSamples);
var normalRate = -majorStrain.NormalRate * majorStrain.Magnitude * (plate.IsLandform ? 1f : 0.5f);
var normalRate = -majorStrain.NormalRate * majorStrain.Magnitude; // * (plate.IsLandform ? 1f : 0.5f);
var edgeDistance = vertexData.EdgeDistance * (plate.IsLandform ? 1f : -1f);
float height = 0.5f;
//height *= plate.PlateExpansion;