Tanoda
ITransformer.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity.Space {
12
13 public interface ITransformer {
14
16
20 Vector3 TransformPoint(Vector3 localRectPos);
21
25 Vector3 InverseTransformPoint(Vector3 localWarpedSpace);
26
30 Quaternion TransformRotation(Vector3 localRectPos, Quaternion localRectRot);
31
35 Quaternion InverseTransformRotation(Vector3 localWarpedPos, Quaternion localWarpedRot);
36
40 Vector3 TransformDirection(Vector3 localRectPos, Vector3 localRectDirection);
41
45 Vector3 InverseTransformDirection(Vector3 localWarpedSpace, Vector3 localWarpedDirection);
46
51 Matrix4x4 GetTransformationMatrix(Vector3 localRectPos);
52 }
53
55 public static readonly IdentityTransformer single = new IdentityTransformer();
56
58 get {
59 return null;
60 }
61 }
62
63 public Vector3 TransformPoint(Vector3 localRectPos) {
64 return localRectPos;
65 }
66
67 public Vector3 InverseTransformPoint(Vector3 localWarpedSpace) {
68 return localWarpedSpace;
69 }
70
71 public Quaternion TransformRotation(Vector3 localRectPos, Quaternion localRectRot) {
72 return localRectRot;
73 }
74
75 public Quaternion InverseTransformRotation(Vector3 localWarpedPos, Quaternion localWarpedRot) {
76 return localWarpedRot;
77 }
78
79 public Vector3 TransformDirection(Vector3 localRectPos, Vector3 localRectDirection) {
80 return localRectDirection;
81 }
82
83 public Vector3 InverseTransformDirection(Vector3 localWarpedSpace, Vector3 localWarpedDirection) {
84 return localWarpedDirection;
85 }
86
87 public Matrix4x4 GetTransformationMatrix(Vector3 localRectPos) {
88 return Matrix4x4.TRS(localRectPos, Quaternion.identity, Vector3.one);
89 }
90 }
91
92 public static class ITransformerExtensions {
93
100 public static void WorldSpaceUnwarp(this ITransformer transformer,
101 Vector3 worldWarpedPosition, Quaternion worldWarpedRotation,
102 out Vector3 worldRectilinearPosition, out Quaternion worldRectilinearRotation) {
103 Transform spaceTransform = transformer.anchor.space.transform;
104
105 Vector3 anchorLocalWarpedPosition = spaceTransform.InverseTransformPoint(worldWarpedPosition);
106 Quaternion anchorLocalWarpedRotation = spaceTransform.InverseTransformRotation(worldWarpedRotation);
107
108 Vector3 anchorLocalRectPosition = transformer.InverseTransformPoint(anchorLocalWarpedPosition);
109 worldRectilinearPosition = spaceTransform.TransformPoint(anchorLocalRectPosition);
110
111 Quaternion anchorLocalRectRotation = transformer.InverseTransformRotation(anchorLocalWarpedPosition, anchorLocalWarpedRotation);
112 worldRectilinearRotation = spaceTransform.TransformRotation(anchorLocalRectRotation);
113 }
114
115 }
116
117}
Quaternion TransformRotation(Vector3 localRectPos, Quaternion localRectRot)
Transform a rotation from rect space to warped space.
Definition: ITransformer.cs:71
static readonly IdentityTransformer single
Definition: ITransformer.cs:55
Vector3 InverseTransformPoint(Vector3 localWarpedSpace)
Transform a point from warped space to rect space.
Definition: ITransformer.cs:67
Vector3 TransformDirection(Vector3 localRectPos, Vector3 localRectDirection)
Transform a direction from rect space to warped space.
Definition: ITransformer.cs:79
Matrix4x4 GetTransformationMatrix(Vector3 localRectPos)
Get a transformation matrix that maps a position in rect space to a position in warped space.
Definition: ITransformer.cs:87
Vector3 InverseTransformDirection(Vector3 localWarpedSpace, Vector3 localWarpedDirection)
Transform a direction from warped space to rect space.
Definition: ITransformer.cs:83
Vector3 TransformPoint(Vector3 localRectPos)
Transform a point from rect space to warped space.
Definition: ITransformer.cs:63
Quaternion InverseTransformRotation(Vector3 localWarpedPos, Quaternion localWarpedRot)
Transform a rotation from warped space to rect space.
Definition: ITransformer.cs:75
Matrix4x4 GetTransformationMatrix(Vector3 localRectPos)
Get a transformation matrix that maps a position in rect space to a position in warped space.
Quaternion TransformRotation(Vector3 localRectPos, Quaternion localRectRot)
Transform a rotation from rect space to warped space.
Vector3 TransformDirection(Vector3 localRectPos, Vector3 localRectDirection)
Transform a direction from rect space to warped space.
Vector3 InverseTransformDirection(Vector3 localWarpedSpace, Vector3 localWarpedDirection)
Transform a direction from warped space to rect space.
Quaternion InverseTransformRotation(Vector3 localWarpedPos, Quaternion localWarpedRot)
Transform a rotation from warped space to rect space.
Vector3 TransformPoint(Vector3 localRectPos)
Transform a point from rect space to warped space.
Vector3 InverseTransformPoint(Vector3 localWarpedSpace)
Transform a point from warped space to rect space.