Skip to content

Commit

Permalink
Merge pull request #482 from CesiumGS/transform-direction
Browse files Browse the repository at this point in the history
Fix incorrect ECEF->LLH transformation in CesiumCartographicPolygon.
  • Loading branch information
csciguy8 authored Jul 31, 2024
2 parents f97f2f2 + 7832610 commit dc29f2b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##### Fixes :wrench:

- Fixed a bug that caused a `NullReferenceException` when attempting to get or set the `longitudeLatitudeHeight` property on a disabled `CesiumGlobeAnchor`.
- Fixed a bug introduced in v1.11.0 that caused `CesiumCartographicPolygon` positions to be interpreted incorrectly, making polygon clipping unusable.

### v1.11.0 - 2024-07-01

Expand Down
2 changes: 1 addition & 1 deletion Runtime/CesiumCartographicPolygon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal List<double2> GetCartographicPoints(Matrix4x4 worldToTileset)
float3 worldPosition = knot.Transform(localToWorld).Position;
float3 unityPosition = worldToTileset.MultiplyPoint3x4(worldPosition);
double3 ecefPosition = georeference.TransformUnityPositionToEarthCenteredEarthFixed(unityPosition);
double3 cartographicPosition = georeference.ellipsoid.LongitudeLatitudeHeightToCenteredFixed(ecefPosition);
double3 cartographicPosition = georeference.ellipsoid.CenteredFixedToLongitudeLatitudeHeight(ecefPosition);

cartographicPoints.Add(cartographicPosition.xy);
}
Expand Down
11 changes: 9 additions & 2 deletions Tests/CesiumTests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"CesiumRuntime",
"Unity.Mathematics"
"Unity.Mathematics",
"Unity.Splines"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -18,6 +19,12 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.splines",
"expression": "1.0.0",
"define": "SUPPORTS_SPLINES"
}
],
"noEngineReferences": false
}
62 changes: 62 additions & 0 deletions Tests/TestCesiumCartographicPolygon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using CesiumForUnity;
using NUnit.Framework;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

#if SUPPORTS_SPLINES
using UnityEngine.Splines;
#endif

public class TestCesiumCartographicPolygon
{
#if SUPPORTS_SPLINES
[Test]
public void GetCartographicPoints()
{
GameObject go = new GameObject("Game Object");

CesiumGeoreference georeference = go.AddComponent<CesiumGeoreference>();
georeference.SetOriginLongitudeLatitudeHeight(12.0, 23.0, 456.0);

CesiumCartographicPolygon polygonComponent = go.AddComponent<CesiumCartographicPolygon>();
SplineContainer splineContainer = go.GetComponent<SplineContainer>();

// Remove existing spline(s).
IReadOnlyList<Spline> splines = splineContainer.Splines;
for (int i = splines.Count - 1; i >= 0; i--)
{
splineContainer.RemoveSpline(splines[i]);
}

// Add a new spline.
Spline defaultSpline = new Spline();

BezierKnot[] knots = new BezierKnot[] {
new BezierKnot(new float3(-100.0f, 0f, -100.0f)),
new BezierKnot(new float3(100.0f, 0f, -100.0f)),
new BezierKnot(new float3(100.0f, 0f, 100.0f)),
new BezierKnot(new float3(-100.0f, 0f, 100.0f)),
};

defaultSpline.Knots = knots;
defaultSpline.Closed = true;
defaultSpline.SetTangentMode(TangentMode.Linear);

splineContainer.AddSpline(defaultSpline);

List<double2> cartographicPoints = polygonComponent.GetCartographicPoints(Matrix4x4.identity);
Assert.AreEqual(cartographicPoints.Count, 4);

// All points are near the georeference origin
Assert.AreEqual(cartographicPoints[0].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[0].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[1].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[1].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[2].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[2].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[3].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[3].y, 23.0, 0.01);
}
#endif
}
11 changes: 11 additions & 0 deletions Tests/TestCesiumCartographicPolygon.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc29f2b

Please sign in to comment.