Skip to content

Commit

Permalink
Doc / name nitpicks for parallelism with Unreal
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Feb 2, 2024
1 parent 84f3a12 commit a76dfeb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
### ? - ?

##### Additions :tada:
- `CesiumOriginShift` now allows specifying an activation distance instead of updating the origin every frame.

- Added a `distance` property to `CesiumOriginShift`, which specifies the maximum allowed distance from the current origin before it is shifted.

### v1.7.1 - 2023-12-14

Expand Down
25 changes: 18 additions & 7 deletions Runtime/CesiumOriginShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,28 @@ namespace CesiumForUnity
public class CesiumOriginShift : MonoBehaviour
{
/// <summary>
/// Specifies the minimum distance in meters from the old origin to the current origin before the
/// origin of the parent <see cref="CesiumGeoreference"/> will be shifted.
/// The maximum distance between the origin of the Unity coordinate system and
/// the game object to which this component is attached. When this distance is
/// exceeded, the <see cref="CesiumGeoreference"/> origin is shifted to bring it
/// close to the game object.
/// </summary>
public double activationDistance
/// <remarks>
/// When the value of this property is 0.0, the origin is shifted continuously.
/// </remarks>
public double distance
{
get => _activationDistance;
set => _activationDistance = value;
get => _distance;
set => _distance = value;
}

[SerializeField]
private double _activationDistance = 0.0;
[Min(0)]
[Tooltip("The maximum distance between the origin of the Unity coordinate system and " +
"the game object to which this component is attached. When this distance is" +
"exceeded, the CesiumGeoreference origin is shifted to bring it close to the " +
"game object.\n\n" +
"When the value of this property is 0.0, the origin is shifted continuously.")]
private double _distance = 0.0;

void LateUpdate()
{
Expand Down Expand Up @@ -112,7 +123,7 @@ private void UpdateFromEcef(CesiumGeoreference georeference, double3 ecef)

double distance = math.length(new double3(georeference.ecefX, georeference.ecefY, georeference.ecefZ) - ecef);

if (distance >= this._activationDistance)
if (distance >= this._distance)
{
// Update the origin if we've surpassed the distance threshold.
georeference.SetOriginEarthCenteredEarthFixed(ecef.x, ecef.y, ecef.z);
Expand Down
6 changes: 3 additions & 3 deletions Tests/TestCesiumOriginShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public IEnumerator UsesGeoreferenceTransformForActivationCheck()
}

[UnityTest]
public IEnumerator UsesActivationDistanceProperty()
public IEnumerator UsesDistanceProperty()
{
double3 baseEcef = new double3(-2694019.41, -4297353.83809221, 3854717.9087824);

Expand All @@ -115,7 +115,7 @@ public IEnumerator UsesActivationDistanceProperty()
CesiumGlobeAnchor globeAnchor = goOriginShift.AddComponent<CesiumGlobeAnchor>();

CesiumOriginShift originShift = goOriginShift.AddComponent<CesiumOriginShift>();
originShift.activationDistance = 5000;
originShift.distance = 5000;

yield return null;

Expand Down Expand Up @@ -154,7 +154,7 @@ public IEnumerator ShiftsOriginWithCharacterController()
CesiumGlobeAnchor globeAnchor = goOriginShift.AddComponent<CesiumGlobeAnchor>();

CesiumOriginShift originShift = goOriginShift.AddComponent<CesiumOriginShift>();
originShift.activationDistance = 5000;
originShift.distance = 5000;

CharacterController controller = goOriginShift.AddComponent<CharacterController>();
controller.radius = 1.0f;
Expand Down

0 comments on commit a76dfeb

Please sign in to comment.