Compare commits
2 commits
e379d1593a
...
a0504e74e9
| Author | SHA1 | Date | |
|---|---|---|---|
| a0504e74e9 | |||
|
|
8d0d0701ba |
2 changed files with 96 additions and 5 deletions
|
|
@ -100,7 +100,10 @@ mesh = SubResource("CylinderMesh_ygjfp")
|
|||
[node name="Pointer" type="Sprite3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo/Icosphere" unique_id=1498529325]
|
||||
unique_name_in_owner = true
|
||||
modulate = Color(1, 0, 0, 1)
|
||||
pixel_size = 0.0018184
|
||||
billboard = 1
|
||||
no_depth_test = true
|
||||
fixed_size = true
|
||||
texture = ExtResource("5_ygjfp")
|
||||
|
||||
[node name="Yaw" type="Node3D" parent="TabContainer/Planet/VBoxContainer/SubViewportContainer/SubViewport/ZaWarudo" unique_id=2073443785]
|
||||
|
|
@ -134,7 +137,8 @@ horizontal_alignment = 1
|
|||
[node name="SunAngle" type="HSlider" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=1452623828]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
max_value = 360.0
|
||||
max_value = 365.0
|
||||
tick_count = 14
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=1053749080]
|
||||
layout_mode = 2
|
||||
|
|
@ -147,7 +151,9 @@ horizontal_alignment = 1
|
|||
[node name="PlanetAngle" type="HSlider" parent="TabContainer/Planet/VBoxContainer/MarginContainer/VBoxContainer" unique_id=1574475714]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
max_value = 360.0
|
||||
max_value = 24.0
|
||||
step = 0.25
|
||||
tick_count = 3
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="TabContainer/Planet" unique_id=716838825]
|
||||
layout_mode = 2
|
||||
|
|
@ -221,6 +227,26 @@ max_length = 5
|
|||
[node name="HSeparator" type="HSeparator" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer" unique_id=1862016318]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label4" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer" unique_id=1664133820]
|
||||
layout_mode = 2
|
||||
text = "- World -"
|
||||
|
||||
[node name="HBoxContainer5" type="HBoxContainer" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer" unique_id=703726989]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Margin" type="VSeparator" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer5" unique_id=554179765]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer5" unique_id=416863531]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.4922884, 0.49228835, 0.49228835, 1)
|
||||
text = "Date: "
|
||||
|
||||
[node name="Date" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer5" unique_id=716565176]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "-1"
|
||||
|
||||
[node name="Label2" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer" unique_id=186838891]
|
||||
layout_mode = 2
|
||||
text = "- Point -"
|
||||
|
|
@ -254,6 +280,19 @@ unique_name_in_owner = true
|
|||
layout_mode = 2
|
||||
text = "-1"
|
||||
|
||||
[node name="VSeparator2" type="VSeparator" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer2" unique_id=521477767]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label2" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer2" unique_id=837979077]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.4922884, 0.49228835, 0.49228835, 1)
|
||||
text = "Local Time:"
|
||||
|
||||
[node name="LocalTime" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer/HBoxContainer2" unique_id=501459011]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "-1"
|
||||
|
||||
[node name="Label3" type="Label" parent="TabContainer/Planet/PanelContainer/MarginContainer/VBoxContainer2/VBoxContainer" unique_id=1412781677]
|
||||
layout_mode = 2
|
||||
text = " - Plate -"
|
||||
|
|
|
|||
58
src/Main.cs
58
src/Main.cs
|
|
@ -38,6 +38,7 @@ public partial class Main : Control
|
|||
UpdateStats();
|
||||
Projector.GatherPoints(_planetHelper, int.Parse(GetNode<LineEdit>("%Resolution").Text));
|
||||
AxialTiltChanged(GetNode<LineEdit>("%AxialTilt").Text);
|
||||
UpdateTime();
|
||||
}
|
||||
|
||||
Vector3 _pointerPosition = Vector3.Zero;
|
||||
|
|
@ -112,6 +113,7 @@ public partial class Main : Control
|
|||
vertexPos *= _meshInstance.Transform.Basis.Inverse().Orthonormalized();
|
||||
_pointerPosition = (Vector3)vertexPos + (vertexPos * (_vertex.Height + 0.01f) * 0.03f); // vertexPos * 1.01f;
|
||||
GetNode<Node3D>("%Pointer").GlobalPosition = _pointerPosition;
|
||||
UpdateTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -128,16 +130,65 @@ public partial class Main : Control
|
|||
_planetHelper.Process();
|
||||
if (_sunRotating)
|
||||
{
|
||||
_sunRotation = (double)(GetNode<HSlider>("%SunAngle").Value / 365.0);
|
||||
GetNode<Node3D>("%Sun").Rotation -= GetNode<Node3D>("%Sun").Rotation;
|
||||
GetNode<Node3D>("%Sun").Rotation += new Vector3(0, (float)Mathf.DegToRad(GetNode<HSlider>("%SunAngle").Value), 0);
|
||||
GetNode<Node3D>("%Sun").Rotation += new Vector3(0, Mathf.DegToRad((float)_sunRotation * 360f), 0);
|
||||
UpdateTime();
|
||||
}
|
||||
if (_planetRotating)
|
||||
{
|
||||
_planetRotation = (double)(GetNode<HSlider>("%PlanetAngle").Value / 24.0);
|
||||
_meshInstance.Rotation = Vector3.Zero;
|
||||
_meshInstance.RotateY((float)Mathf.DegToRad(GetNode<HSlider>("%PlanetAngle").Value));
|
||||
_meshInstance.RotateY((float)Mathf.DegToRad(_planetRotation * 360.0));
|
||||
_meshInstance.RotateZ(Mathf.DegToRad(_axialTilt));
|
||||
UpdateTime();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTime()
|
||||
{
|
||||
double hours = GetLocalTime(GetNode<Node3D>("%Pointer").GlobalPosition, GetNode<Node3D>("%Sun").GlobalTransform.Basis.Z,
|
||||
_meshInstance);
|
||||
GetNode<Label>("%LocalTime").Text = DaysToTime(_sunRotation * 365.0, hours);
|
||||
|
||||
GetNode<Label>("%Date").Text = DaysToDate(_sunRotation * 365.0, _planetRotation*24.0);
|
||||
}
|
||||
|
||||
public static double GetLocalTime(Vector3 surfacePoint, Vector3 sunPos, Node3D planet)
|
||||
{
|
||||
Vector3 center = planet.GlobalTransform.Origin;
|
||||
Vector3 axis = -planet.GlobalTransform.Basis.Y.Normalized();
|
||||
|
||||
Vector3 surfaceDir = (surfacePoint - center).Normalized();
|
||||
Vector3 sunDir = (sunPos - center).Normalized();
|
||||
|
||||
surfaceDir = (surfaceDir - axis * surfaceDir.Dot(axis)).Normalized();
|
||||
sunDir = (sunDir - axis * sunDir.Dot(axis)).Normalized();
|
||||
|
||||
double angle = Mathf.Atan2(
|
||||
axis.Dot(surfaceDir.Cross(sunDir)),
|
||||
surfaceDir.Dot(sunDir)
|
||||
);
|
||||
|
||||
double hours = Mathf.PosMod(angle / Mathf.Tau * 24.0 + 12.0, 24.0);
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
public string DaysToDate(double days, double hours)
|
||||
{
|
||||
DateTime dt = new DateTime(1, 1, 1);
|
||||
dt = dt.AddDays(days);
|
||||
dt = dt.AddHours(hours);
|
||||
return dt.ToString("'y'yyyy/'m'MM/'d'dd - 'h'HH':''m'mm':''s'ss");
|
||||
}
|
||||
public string DaysToTime(double days, double hours)
|
||||
{
|
||||
DateTime dt = new DateTime(1, 1, 1);
|
||||
dt = dt.AddDays(days);
|
||||
dt = dt.AddHours(hours);
|
||||
return dt.ToString("'h'HH':''m'mm':''s'ss");
|
||||
}
|
||||
public void UpdateStats()
|
||||
{
|
||||
if (_vertex != null)
|
||||
|
|
@ -239,6 +290,7 @@ public partial class Main : Control
|
|||
}
|
||||
|
||||
private bool _sunRotating = false;
|
||||
private double _sunRotation = 0.0;
|
||||
private float _axialTilt = 0f;
|
||||
public void SunAngleStart()
|
||||
{
|
||||
|
|
@ -250,7 +302,7 @@ public partial class Main : Control
|
|||
_sunRotating = false;
|
||||
}
|
||||
private bool _planetRotating = false;
|
||||
private float _planetRotation = 0f;
|
||||
private double _planetRotation = 0.0;
|
||||
public void PlanetAngleStart()
|
||||
{
|
||||
_planetRotating = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue