some fixes to spherical positioning, changed strategies for the feature to use xen's suggestion

This commit is contained in:
FreezeDriedMangoes 2022-06-23 18:14:41 -04:00
parent 756a08d342
commit 4a20b22859

View File

@ -114,7 +114,8 @@ namespace NewHorizons.Utility.DebugMenu
Vector3 latestPropPosDelta = VectorInput(_dpp.mostRecentlyPlacedPropGO.transform.localPosition, propPosDelta, out propPosDelta, "x", "y", "z"); Vector3 latestPropPosDelta = VectorInput(_dpp.mostRecentlyPlacedPropGO.transform.localPosition, propPosDelta, out propPosDelta, "x", "y", "z");
_dpp.mostRecentlyPlacedPropGO.transform.localPosition += latestPropPosDelta; _dpp.mostRecentlyPlacedPropGO.transform.localPosition += latestPropPosDelta;
if (latestPropPosDelta != Vector3.zero) mostRecentlyPlacedPropSphericalPos = DeltaSphericalPosition(mostRecentlyPlacedProp, Vector3.zero);
GUILayout.Space(5); GUILayout.Space(5);
@ -125,30 +126,44 @@ namespace NewHorizons.Utility.DebugMenu
} }
Vector3 latestPropSphericalPosDelta = VectorInput(mostRecentlyPlacedPropSphericalPos, propSphericalPosDelta, out propSphericalPosDelta, "lat ", "lon ", "height"); Vector3 latestPropSphericalPosDelta = VectorInput(mostRecentlyPlacedPropSphericalPos, propSphericalPosDelta, out propSphericalPosDelta, "lat ", "lon ", "height");
if (latestPropPosDelta != Vector3.zero) if (latestPropSphericalPosDelta != Vector3.zero)
{ {
mostRecentlyPlacedPropSphericalPos = DeltaSphericalPosition(mostRecentlyPlacedProp, latestPropSphericalPosDelta); Logger.Log("Prop pos delta "+latestPropSphericalPosDelta);
mostRecentlyPlacedPropSphericalPos = DeltaSphericalPosition(mostRecentlyPlacedProp, mostRecentlyPlacedPropSphericalPos+latestPropSphericalPosDelta);
} }
} }
} }
private Vector3 DeltaSphericalPosition(GameObject go, Vector3 deltaSpherical) private Vector3 DeltaSphericalPosition(GameObject prop, Vector3 deltaSpherical)
{ {
sphericalPlacer.transform.parent = _dpp.mostRecentlyPlacedPropGO.transform.parent; // note: prop was originally named go
sphericalPlacer.transform.localPosition = Vector3.zero; //sphericalPlacer.transform.parent = go.transform.parent;
sphericalPlacer.transform.LookAt(_dpp.mostRecentlyPlacedPropGO.transform.localPosition); //sphericalPlacer.transform.localPosition = Vector3.zero;
sphericalPlacer.transform.localEulerAngles = new Vector3(sphericalPlacer.transform.localEulerAngles.x, sphericalPlacer.transform.localEulerAngles.y, 0); //sphericalPlacer.transform.LookAt(go.transform.localPosition);
//sphericalPlacer.transform.localEulerAngles = new Vector3(sphericalPlacer.transform.localEulerAngles.x, sphericalPlacer.transform.localEulerAngles.y, 0);
go.transform.parent = sphericalPlacer.transform; //go.transform.parent = sphericalPlacer.transform;
Vector3 currentSpherical = sphericalPlacer.transform.localEulerAngles + new Vector3(0,0, go.transform.localPosition.z); // lat, lon, height //Vector3 currentSpherical = sphericalPlacer.transform.localEulerAngles + new Vector3(0,0, go.transform.localPosition.z); // lat, lon, height
sphericalPlacer.transform.localEulerAngles += new Vector3(deltaSpherical.x, deltaSpherical.y, 0); //sphericalPlacer.transform.localEulerAngles += new Vector3(deltaSpherical.x, deltaSpherical.y, 0);
_dpp.mostRecentlyPlacedPropGO.transform.localPosition += new Vector3(0, 0, deltaSpherical.z); //go.transform.localPosition += new Vector3(0, 0, deltaSpherical.z);
_dpp.mostRecentlyPlacedPropGO.transform.parent = sphericalPlacer.transform.parent; //go.transform.parent = sphericalPlacer.transform.parent;
return currentSpherical+deltaSpherical; //return currentSpherical+deltaSpherical;
Vector3 originalLocalPos = prop.transform.parent.InverseTransformPoint(prop.transform.position); // parent is the sector, this gives localPos relative to the astroobject
Vector3 sphericalPos = CoordinateUtilities.CartesianToSpherical(originalLocalPos);
Vector3 finalLocalPosition = CoordinateUtilities.SphericalToCartesian(sphericalPos+deltaSpherical);
if (deltaSpherical == Vector3.zero) return sphericalPos;
Vector3 finalAbsolutePosition = prop.transform.parent.TransformPoint(finalLocalPosition);
prop.transform.localPosition = prop.transform.InverseTransformPoint(finalAbsolutePosition);
prop.transform.rotation = prop.transform.rotation * Quaternion.FromToRotation(originalLocalPos.normalized, finalLocalPosition.normalized);
return sphericalPos+deltaSpherical;
} }
private Vector3 VectorInput(Vector3 input, Vector3 deltaControls, out Vector3 deltaControlsOut, string labelX, string labelY, string labelZ) private Vector3 VectorInput(Vector3 input, Vector3 deltaControls, out Vector3 deltaControlsOut, string labelX, string labelY, string labelZ)