From 6244e5a16a7b4b521e3dd2ed02600ad946dd0852 Mon Sep 17 00:00:00 2001 From: Japa Date: Sat, 27 Feb 2016 22:13:13 +0530 Subject: [PATCH] Made the sun angle change with the seasons. DF is assumed to be in central Europe for this purpose. --- Assets/CelestialScripts/DFTime.cs | 14 ++++++- Assets/CelestialScripts/SunRotate.cs | 28 +++++++++++++ Assets/Materials/WaterMaterial.mat | 2 +- Assets/RemoteClientDF/RemoteFortressReader.cs | 8 ++++ Assets/Start.unity | 42 ++++++++++++++++--- 5 files changed, 87 insertions(+), 7 deletions(-) diff --git a/Assets/CelestialScripts/DFTime.cs b/Assets/CelestialScripts/DFTime.cs index 5707133a9..6e76d37e7 100644 --- a/Assets/CelestialScripts/DFTime.cs +++ b/Assets/CelestialScripts/DFTime.cs @@ -51,7 +51,7 @@ public enum MonthName public DFTime(long ticks) { - this._ticks = ticks; + _ticks = ticks; } /// @@ -282,4 +282,16 @@ public static explicit operator DateTime(DFTime dfTime) { return t1.Ticks >= t2.Ticks; } + + public float SolsticeAngle + { + get + { + float angle = (_ticks % TicksPerYear) * 360.0f / TicksPerYear; + angle -= 105; + if (angle < 0) + angle += 360; + return angle; + } + } } diff --git a/Assets/CelestialScripts/SunRotate.cs b/Assets/CelestialScripts/SunRotate.cs index ad5fb4fd8..4840587e3 100644 --- a/Assets/CelestialScripts/SunRotate.cs +++ b/Assets/CelestialScripts/SunRotate.cs @@ -3,11 +3,39 @@ public class SunRotate : MonoBehaviour { public float rotationSpeed = 1.0f; + public float longitude; + public float axialTilt; + + public Transform longitudeAxis; + public Transform seasonAxis; + + public float GetLongitudeFromWorld(RemoteFortressReader.WorldMap world) + { + float tude = Mathf.InverseLerp(0, world.world_height, world.center_y); + switch (world.world_poles) + { + case RemoteFortressReader.WorldPoles.NO_POLES: + return 0; + case RemoteFortressReader.WorldPoles.NORTH_POLE: + tude = (1-tude) * 90; + break; + case RemoteFortressReader.WorldPoles.SOUTH_POLE: + tude = tude * 90; + break; + case RemoteFortressReader.WorldPoles.BOTH_POLES: + tude = ((tude * 2) - 1) * -180; + break; + default: + return 0; + } + return tude; + } // Update is called once per frame void Update() { Quaternion rotate = Quaternion.AngleAxis(TimeHolder.DisplayedTime.SunAngle, Vector3.back); transform.localRotation = rotate; + seasonAxis.localRotation = Quaternion.Euler((Mathf.Cos(TimeHolder.DisplayedTime.SolsticeAngle * Mathf.Deg2Rad) * axialTilt) + 90, 0, 0); } } diff --git a/Assets/Materials/WaterMaterial.mat b/Assets/Materials/WaterMaterial.mat index 9cc41e995..d518b0f49 100644 --- a/Assets/Materials/WaterMaterial.mat +++ b/Assets/Materials/WaterMaterial.mat @@ -22,7 +22,7 @@ Material: second: m_Texture: {fileID: 0} m_Scale: {x: 0.1, y: 0.1} - m_Offset: {x: 0.9552245, y: 1.704449} + m_Offset: {x: 0.6452888, y: 1.1513805} data: first: name: _BumpMap diff --git a/Assets/RemoteClientDF/RemoteFortressReader.cs b/Assets/RemoteClientDF/RemoteFortressReader.cs index 54fa7a05b..f7d20f6ec 100644 --- a/Assets/RemoteClientDF/RemoteFortressReader.cs +++ b/Assets/RemoteClientDF/RemoteFortressReader.cs @@ -1348,6 +1348,14 @@ public int cur_year_tick get { return _cur_year_tick; } set { _cur_year_tick = value; } } + private RemoteFortressReader.WorldPoles _world_poles = RemoteFortressReader.WorldPoles.NO_POLES; + [global::ProtoBuf.ProtoMember(22, IsRequired = false, Name=@"world_poles", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)] + [global::System.ComponentModel.DefaultValue(RemoteFortressReader.WorldPoles.NO_POLES)] + public RemoteFortressReader.WorldPoles world_poles + { + get { return _world_poles; } + set { _world_poles = value; } + } private global::ProtoBuf.IExtension extensionObject; global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } diff --git a/Assets/Start.unity b/Assets/Start.unity index 754c31a11..65d8ae169 100644 --- a/Assets/Start.unity +++ b/Assets/Start.unity @@ -313,7 +313,7 @@ Transform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 692705302} - m_LocalRotation: {x: 0, y: 0.50000006, z: 0, w: 0.8660254} + m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071067} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: @@ -481,6 +481,34 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 10 +--- !u!1 &831823944 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 831823945} + m_Layer: 0 + m_Name: Longitude Axis + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &831823945 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 831823944} + m_LocalRotation: {x: -0.27059808, y: 0.2705981, z: 0.65328157, w: 0.65328145} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1415142926} + m_Father: {fileID: 0} + m_RootOrder: 11 --- !u!1 &861361727 GameObject: m_ObjectHideFlags: 0 @@ -1107,13 +1135,13 @@ Transform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1415142925} - m_LocalRotation: {x: 0, y: 0, z: -0.7071068, w: 0.7071067} - m_LocalPosition: {x: 0, y: 0, z: -0} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 692705304} - m_Father: {fileID: 0} - m_RootOrder: 11 + m_Father: {fileID: 831823945} + m_RootOrder: 0 --- !u!114 &1415142927 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1126,6 +1154,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: rotationSpeed: 1 + longitude: 0 + axialTilt: 23.4 + longitudeAxis: {fileID: 831823945} + seasonAxis: {fileID: 692705304} --- !u!20 &1485797796 stripped Camera: m_PrefabParentObject: {fileID: 2024094, guid: cbcacdf4d5c2d1e4a8ea4ac440b8e52d,