Skip to content

Commit

Permalink
Made the sun angle change with the seasons. DF is assumed to be in ce…
Browse files Browse the repository at this point in the history
…ntral Europe for this purpose.
  • Loading branch information
RosaryMala committed Feb 27, 2016
1 parent 07a4c97 commit 6244e5a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
14 changes: 13 additions & 1 deletion Assets/CelestialScripts/DFTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum MonthName

public DFTime(long ticks)
{
this._ticks = ticks;
_ticks = ticks;
}

/// <summary>
Expand Down Expand Up @@ -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;
}
}
}
28 changes: 28 additions & 0 deletions Assets/CelestialScripts/SunRotate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Assets/Materials/WaterMaterial.mat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Assets/RemoteClientDF/RemoteFortressReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
42 changes: 37 additions & 5 deletions Assets/Start.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 6244e5a

Please sign in to comment.