Skip to content

Commit

Permalink
Merge pull request #4 from Netherlands3D/bugfix/origin-coordinate
Browse files Browse the repository at this point in the history
Bugfix/origin coordinate
  • Loading branch information
mvangog authored Aug 21, 2024
2 parents 7a89788 + 3eaadd8 commit dd8c53f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2023-08-21

### Fixed

- Fixed calculation of origin coordinate, added function to recalculate origin and update position if the origin changes.

## [1.0.1] - 2023-08-19

### Fixed
Expand Down
23 changes: 15 additions & 8 deletions Runtime/Scripts/SunTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void Update()
{
UpdateTimeOfDayPartsFromTime();
timeOfDayChanged.Invoke(time);
SetPosition();
SetDirection();
}

frameStep = (frameStep + 1) % frameSteps;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void SetLocation(float longitude, float latitude)
this.longitude = longitude;
this.latitude = latitude;

SetPosition();
SetDirection();
}

public void SetUpdateSteps(int i)
Expand Down Expand Up @@ -194,19 +194,19 @@ private void Apply()
if (newTime != time)
{
time = newTime;
SetPosition();
SetDirection();
timeOfDayChanged.Invoke(newTime);
}
}

private void DetermineCurrentLocationFromOrigin()
{
var wgs84SceneCenter = CoordinateConverter.RDtoWGS84(EPSG7415.relativeCenter.x, EPSG7415.relativeCenter.y);
longitude = (float)wgs84SceneCenter.lon;
latitude = (float)wgs84SceneCenter.lat;
var wgs84SceneCenter = CoordinateSystems.CoordinateAtUnityOrigin.Convert(CoordinateSystem.WGS84_LatLon);
longitude = (float)wgs84SceneCenter.easting;
latitude = (float)wgs84SceneCenter.northing;
}

private void SetPosition()
private void SetDirection()
{
Vector3 angles = new Vector3();
SunPosition.CalculateSunPosition(time, (double)latitude, (double)longitude, out double azi, out double alt);
Expand All @@ -215,5 +215,12 @@ private void SetPosition()

sunDirectionalLight.transform.localRotation = Quaternion.Euler(angles);
}

//call this when the origin changes to recalculate the origin and set the sun position without calling the time change event
public void RecalculateOrigin()
{
DetermineCurrentLocationFromOrigin();
SetDirection();
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "eu.netherlands3d.sun",
"displayName": "Netherlands3D - Sun, Time of Day and Shadows",
"version": "1.0.1",
"version": "1.0.2",
"unity": "2022.2",
"description": "",
"type": "library",
Expand Down

0 comments on commit dd8c53f

Please sign in to comment.