Conversion of world coordinates and relative coordinates relative to an object in Unity

Recently in the development of XR conference, some attitude information will be reported on multiple terminals for synchronization. Since the positioning positions on different terminals are different, if you upload the world coordinates, in fact, you are on the other side at all. cannot be located.

Therefore, when we report attitude information, it is relative coordinates relative to an object, and then converts it into relative coordinates on the end side.

Set roomObject to the relative object you want to change,

The world coordinates are converted to relative coordinates relative to the roomObject:

 Vector3 headLocalPosition = roomObject.transform.InverseTransformPoint(headWorldPosition);
 Quaternion headLocalRotation = Quaternion.Inverse(roomObject.transform.rotation) * headWorldRotation;

The relative coordinates of the object relative to the roomObject are converted into world coordinates:

 Vector3 headWorldPosition= roomObject.transform.TransformPoint(headLocalPosition);
 Quaternion headWorldRotation= roomObject.transform.rotation * headLocalRotation;

In this way, when our attitude information is circulated on multiple end-sides, we uniformly convert it into coordinates relative to a certain object, and then send it to other end-sides, and other end-sides are converted into world coordinates according to relative objects.

references:

What is the rotation equivalent of InverseTransformPoint? - Unity Answers

What's the math behind transform.TransformPoint()? - Unity Forum

Guess you like

Origin blog.csdn.net/grace_yi/article/details/123360689