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;
}
}