mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
CoordinateUtilities.cs: match shader jank
This commit is contained in:
parent
468126b9b0
commit
cfd1fda28e
@ -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;
|
||||
|
||||
|
||||
@ -161,7 +161,7 @@ namespace NewHorizons.Builder.Body
|
||||
var superGroup = planetGO.GetComponent<ProxyShadowCasterSuperGroup>();
|
||||
if (superGroup != null) cubeSphere.AddComponent<ProxyShadowCaster>()._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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user