diff --git a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs index f2640052..7eca709f 100644 --- a/NewHorizons/Builder/Body/Geometry/CubeSphere.cs +++ b/NewHorizons/Builder/Body/Geometry/CubeSphere.cs @@ -125,7 +125,7 @@ namespace NewHorizons.Builder.Body.Geometry v.z = v2.z * Mathf.Sqrt(1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f); // The shader uses real coords - var sphericals = CoordinateUtilities.CartesianToSpherical(v, false); + var sphericals = CoordinateUtilities.CartesianToSpherical(v, true); float longitude = sphericals.x; float latitude = sphericals.y; diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index b5658965..6189a30d 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -161,7 +161,7 @@ namespace NewHorizons.Builder.Body var superGroup = planetGO.GetComponent(); if (superGroup != null) cubeSphere.AddComponent()._superGroup = superGroup; - // rotate for back compat :P + // rotate for backwards compat :P cubeSphere.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(0, -90, 0)); cubeSphere.transform.position = planetGO.transform.position; diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index fdb1720d..ecfbce9a 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -98,7 +98,7 @@ namespace NewHorizons.Builder.Props var height = radius; if (heightMapTexture != null) { - var sphericals = CoordinateUtilities.CartesianToSpherical(point, false); + var sphericals = CoordinateUtilities.CartesianToSpherical(point, true); float longitude = sphericals.x; float latitude = sphericals.y; diff --git a/NewHorizons/Utility/Geometry/CoordinateUtilities.cs b/NewHorizons/Utility/Geometry/CoordinateUtilities.cs index 10f8728d..fc677121 100644 --- a/NewHorizons/Utility/Geometry/CoordinateUtilities.cs +++ b/NewHorizons/Utility/Geometry/CoordinateUtilities.cs @@ -5,22 +5,23 @@ namespace NewHorizons.Utility.Geometry { // Longitude and latitude are in degrees // Using the phi and theta convention used on https://mathworld.wolfram.com/SphericalCoordinates.html (Mathematics not physics convention) - public static Vector3 CartesianToSpherical(Vector3 v, bool useUnityCoords = true) + public static Vector3 CartesianToSpherical(Vector3 v, bool useShaderCoords = false) { float x, y, z; - if (useUnityCoords) + if (useShaderCoords) + { + // shader does some jank stuff to match standard shader + x = -v.z; + y = v.x; + z = -v.y; + } + else { // Y is up in unity x = v.x; y = v.z; z = v.y; } - else - { - x = v.x; - y = v.y; - z = v.z; - } float dist = Mathf.Sqrt(x * x + y * y + z * z); @@ -33,7 +34,7 @@ namespace NewHorizons.Utility.Geometry return new Vector3(longitude, latitude, dist); } - public static Vector3 SphericalToCartesian(Vector3 v, bool useUnityCoords = true) + public static Vector3 SphericalToCartesian(Vector3 v) { var longitude = v.x; var latitude = v.y; @@ -44,18 +45,9 @@ namespace NewHorizons.Utility.Geometry float x, y, z; - if (useUnityCoords) - { - x = r * Mathf.Cos(theta) * Mathf.Sin(phi); - z = r * Mathf.Sin(theta) * Mathf.Sin(phi); - y = r * Mathf.Cos(phi); - } - else - { - x = r * Mathf.Cos(theta) * Mathf.Sin(phi); - y = r * Mathf.Sin(theta) * Mathf.Sin(phi); - z = r * Mathf.Cos(phi); - } + x = r * Mathf.Cos(theta) * Mathf.Sin(phi); + z = r * Mathf.Sin(theta) * Mathf.Sin(phi); + y = r * Mathf.Cos(phi); return new Vector3(x, y, z); }