1
votes

I try to set a new position and orientation as origin with SetWorldOrigin

I'm using Unity 2018.3.0f2 and ARKit 2.0

My start alignment is: "Unity AR Alignment Gravity And Heading"

In my outdoor test environment I have a known point with a visualized north direction. I can place a Gameobject (newOriginGO) on this point and rotate it towards the visualized north direction. The problem is, the virtual objets are rotated to a wrong position. I tested with only translations, this worked. Here is a code snippet:

GameObject translationToLastPosition = new GameObject();
GameObject rotateToNewRotation = new GameObject();
GameObject translationToNewPosition = new GameObject();

translationToLastPosition.transform.position = -lastOriginP;
rotateToNewRotation.transform.eulerAngles = lastOriginR - newOriginGO.transform.eulerAngles;
translationToNewPosition.transform.position = lastOriginP - newOriginGO.transform.position;

UnityARSessionNativeInterface.GetARSessionNativeInterface().SetWorldOrigin(translationToLastPosition.transform);
UnityARSessionNativeInterface.GetARSessionNativeInterface().SetWorldOrigin(rotateToNewRotation.transform);
UnityARSessionNativeInterface.GetARSessionNativeInterface().SetWorldOrigin(translationToNewPosition.transform);

lastOriginP = newOriginGO.transform.position;
lastOriginR = newOriginGO.transform.eulerAngles;

Because the SetWorldOrigin needs a relative transform and I'm rotating my Gameobject around the last Origin, with transform.RotateAround(lastOriginP, Vector3.up, angle), I tried to translate the WorldOrigin back to the last Origin, rotate the WorldOrigin and then translate back to the actual position. Do I have a thinking error or do I not understand exactly how the method SetWorldOrigin works? How does the ARKit SetWorldOrigin affects the Unity World Space coordinate system?

1

1 Answers

0
votes

Okay, finally I found another solution. Instead of changing the WorldOrigin with ARKit, I made all my 3D objects as child objects of an empty GameObject. Then I changed this GameObject with my correction values (translation and rotation).