Skip to content

Commit 7adb889

Browse files
authored
Merge pull request #7 from Dozed12/patch-1
Longitude Optimization
2 parents fdbcb71 + 79f02a4 commit 7adb889

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Assets/Scripts/SphericalWorldGenerator.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,16 @@ protected override void GetData()
168168
// Convert Lat/Long coordinates to x/y/z for spherical mapping
169169
void LatLonToXYZ(float lat, float lon, ref float x, ref float y, ref float z)
170170
{
171-
float r = Mathf.Cos (Mathf.Deg2Rad * lon);
172-
x = r * Mathf.Cos (Mathf.Deg2Rad * lat);
173-
y = Mathf.Sin (Mathf.Deg2Rad * lon);
174-
z = r * Mathf.Sin (Mathf.Deg2Rad * lat);
171+
float r = Mathf.Cos(Mathf.Deg2Rad * lon);
172+
173+
//Longitude Optimization
174+
float sin = Mathf.Sqrt(1 * 1 - r * r);
175+
if (lon < 0)
176+
sin = -sin;
177+
178+
x = r * Mathf.Cos(Mathf.Deg2Rad * lat);
179+
y = sin;
180+
z = r * Mathf.Sin(Mathf.Deg2Rad * lat);
175181
}
176182

177183
protected override Tile GetTop(Tile t)

0 commit comments

Comments
 (0)