Select to view content in your preferred language

World position to unity position (from geographical coordinates)

2925
10
Jump to solution
11-02-2022 08:29 AM
ReintJ
by
Occasional Contributor

Hello,

I am trying to get the Unity position from geographical coordinates, I have the following code to get the HPTransform position, but I am not sure how to continue from here, (I'm not sure if this is even possible),

 

 

double3 worldPos = map.View.GeographicToWorld(new ArcGISPoint(x, y, spatialRef));

 

 

map = the ArcGISMapComponent; spatialRef = new ArcGISSpatialReference(4326); x,y = 5.1 & 52.1 (example)

This results in: worldPos = double3(568832.151913682, 0, 6816306.77166522)

I have looked a bit in to the HPTransform code, but I couldn't figure out how it worked.

Some more details about the project: I do not use the rebase component on the ArcGISCamera & and the ArcGISCamera is on a fixed location, and I'm using a local scene.

Thanks for the help,

Kind regards,

Reint.

 

 

 

0 Kudos
1 Solution

Accepted Solutions
ReintJ
by
Occasional Contributor

Hello again,

After some more testing and diving in to the code, I think I got it to work,

I used the following code to transform the worldPos variable to the Unity position, using the HPRoot of the ArcGISMap component:

HPRoot root = map.GetComponent<HPRoot>();
double3 unityPos = root.TransformPoint(worldPos))

I'm not sure if this is a valid method that also works in global scenes for example, but it seems to work for local scenes.

View solution in original post

10 Replies
Matt_Nelson
Esri Alum

Is this value This results in: worldPos = double3(568832.151913682, 0, 6816306.77166522) not correct?

0 Kudos
ReintJ
by
Occasional Contributor

I need the transform.position for a raycast, and the worldPos is the value of the HPTrarnsform.UniversePosition.

0 Kudos
ReintJ
by
Occasional Contributor

Hello again,

After some more testing and diving in to the code, I think I got it to work,

I used the following code to transform the worldPos variable to the Unity position, using the HPRoot of the ArcGISMap component:

HPRoot root = map.GetComponent<HPRoot>();
double3 unityPos = root.TransformPoint(worldPos))

I'm not sure if this is a valid method that also works in global scenes for example, but it seems to work for local scenes.

Matt_Nelson
Esri Alum

Ok, any reason you aren't just using a location component on the object of interest?

0 Kudos
ReintJ
by
Occasional Contributor

Hey Matt, I wanted to create a moderate/large amount of objects after the game has started. I think the code is a bit cleaner and more optimized if you can get the height beforehand (so the object it self does not need a seperate script/function to get the height) (and you need to wait a frame before the transform.position is updated, if I'm corrent).

However, this only works because my project area is kind of small, so everything location is loaded, it would not work with larger areas.

0 Kudos
Matt_Nelson
Esri Alum

Ok sounds good. So the solution you shared should work. 

0 Kudos
BHenke
by
New Contributor

Hello,

I have tried your solution, but my ArcGISView does not have a SpatialReference. Do you know how I can assign one?

0 Kudos
m_d
by
Emerging Contributor

Thank you for posting this! Thanks to this info, I was able, not only to get a Unity-world location for a geographic coordinate, but also to use HPRoot.InverseTransformPoint() to go the other direction and get a WGS coordinate for a Unity object without a location component.

0 Kudos
文言李
Emerging Contributor

Sorry, but where is the variable "map" comes from? Do I need to use FindObjectByTags or something else?

0 Kudos