I use LineRenderer to render polygon curves.The data is multipolygon in the wgs84 coordinate system (srid=4326).
(1)
I use a multipolygon data a to create a gameobject and add a LineRenderer component.
Use the following two lines of code to convert latitude and longitude coordinates into unity world coordinates, and the rendering result is located correctly;
double3 db3 = new double3();
db3.x = longitude;
db3.y = latitude;
db3.z = 5000;
double3 ecef = CesiumWgs84Ellipsoid.LongitudeLatitudeHeightToEarthCenteredEarthFixed(db3);
double3 xyz = m_CesiumRoot.TransformEarthCenteredEarthFixedPositionToUnity(ecef);
Vector3 v3 = new Vector3((float)(xyz.x), (float)(xyz.y), (float)(xyz.z));
(2)
I used multiple multipalygon data for rendering, created multiple gameobjects, and multiple LineRenderer components.
One of the data was consistent with the first debugging data a, and the same coordinate conversion code was used.
However, the world coordinates of Unity after latitude and longitude conversion changed, and the position of Unity’s rendering results also shifted.
What is the reason and how should I solve it
Does your camera have a CesiumOriginShift
component attached? If so, the Unity origin will shift every time the camera moves. You may want to remove or disable this for your purposes.
First of all, thank you for your help.In this project, I added a dynamic camera to view polygons from any perspective.
To ensure that the rendered object moves synchronously with the camera’s zoom in, zoom out, and pan operations,
I added a component CesiumOriginShift to each newly created GameObject,code like this:
GameObject line_ = new GameObject(“Line”);
line_.transform.parent = m_CesiumRoot.transform;
line_.transform.position = vertices[0];
line_.AddComponent();
line_.AddComponent();
line_.AddComponent();
if i do not add CesiumOriginShift,the rendered polygon curves are not moving with the dynamic camera.
I want to place the polygonal curve at a fixed world coordinate position,and move it with the dynamic camera,
but the position of a polygon is correct in unity, but the positions of multiple polygons are offset,Like the following two pictures,
two identical polygons with different positions in LineRenderer rendering debugging,what’s the problem?
You don’t want to add a CesiumOriginShift
to multiple stationary objects. The CesiumOriginShift
component should be attached to a GameObject that moves – for example, a camera or character. When that GameObject
moves, the origin will be shifted with it.
It sounds like you should use CesiumGlobeAnchor
components instead. When attached to a GameObject
, the component will “anchor” it to that precise location on the Earth. This will automatically account for origin shifting.
Thank you for you help.
This problem has been solved when i add a component CesiumOriginShift to the dynamic camera,and remove the component CesiumOriginShift of the newly created gameObject and add a component CesiumGlobeAnchor to the the newly created gameObject.
Thank you very much again.