Getting Terrain Topology Normal in ENU Coordinates

Recommended Posts


I am using Unigine 2.8. I want to get terrain normal with respect to ENU coordinate system but I have some problems.

Let's start with first problem.

I have a GeodeticPivot where its pivot is located on the Earth at (39.1201340430776554, 35.1688556961649041, 0). I think this is the origin of my play area in geo coordiantes, anyway.

Now by using getENUWorldRotation method of the Ellipsoid class I did the following:

Unigine::GeodeticPivot pivot = Unigine::GeodeticPivot::cast( Unigine::Editor::get()->getNodeByName("GeodeticPivot") );

Unigine::Math::quat originQuat = pivot ->getEllipsoid()->getENUWorldRotation(Unigine::Math::Vec3(0,0,0));

Here, Unigine::Math::Vec3(0,0,0) is the origin of GeodeticPivot in ellipsoid coordinates, right? What is the definition of the ellipsoid coordinates? Are the ellipsoid coordinates not the coordinates I see in the editor?

Now what I expect is that originQuat is the identity quaternion. But it is not.  originQuat is (0.5, 0.5, 0.5, 0.5). This is confusing. What am I doing wrong?

Next I tried following for getting terrain normal at the world position of a node with respect to ENU coordinate system whose origin is the world position of this node. For example if the terrain is completely flat at this position, I expect that the normal is (0,0,1) wrt to ENU coordinate system whose origin is the world position of the node.

Anyway, here is the my solution.


Unigine::Math::Vec3 flat, dummy;

pivot->mapEllipsoidToFlat(node->getWorldPosition(), flat, dummy);

Unigine::Math::vec3 normalF;

Unigine::Math::vec3 upF;

terrain->fetchTopologyData(flat.x, flat.y, flat, normalF, upF, 1);

Now I must tansform normalF to ENU coordinates whose origin is at node->getWorldPosition().

Unigine::Math::quat quat = pivot->getEllipsoid()->getENUWorldRotation(node->getWorldPosition());

normalF = Unigine::Math::inverse(quat) * normalF;

This code should transform normalF to ENU coordinates. But it doesn't work. I am getting weird results.

Thank you for your help in advance.

Share this post

Link to post