Example #1
0
        /// <summary>
        /// Given a transformer and a world-space position and rotation, this method interprets that position
        /// and rotation as being within the transformers "warped" space (e.g. cylindrical space for LeapCylindricalSpace)
        /// and outputs the world-space position and rotation that would result if the space was no longer warped,
        /// i.e., standard Unity rectilinear space.
        /// </summary>
        public static void WorldSpaceUnwarp(this ITransformer transformer,
                                            Vector3 worldWarpedPosition, Quaternion worldWarpedRotation,
                                            out Vector3 worldRectilinearPosition, out Quaternion worldRectilinearRotation)
        {
            Transform spaceTransform = transformer.anchor.space.transform;

            Vector3    anchorLocalWarpedPosition = spaceTransform.InverseTransformPoint(worldWarpedPosition);
            Quaternion anchorLocalWarpedRotation = spaceTransform.InverseTransformRotation(worldWarpedRotation);

            Vector3 anchorLocalRectPosition = transformer.InverseTransformPoint(anchorLocalWarpedPosition);

            worldRectilinearPosition = spaceTransform.TransformPoint(anchorLocalRectPosition);

            Quaternion anchorLocalRectRotation = transformer.InverseTransformRotation(anchorLocalWarpedPosition, anchorLocalWarpedRotation);

            worldRectilinearRotation = spaceTransform.TransformRotation(anchorLocalRectRotation);
        }