Tanoda
TransformUtil.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 {
12
13 public static class TransformUtil {
14
15 public static Quaternion TransformRotation(this Transform transform, Quaternion rotation) {
16 return transform.rotation * rotation;
17 }
18
19 public static Quaternion InverseTransformRotation(this Transform transform, Quaternion rotation) {
20 return Quaternion.Inverse(transform.rotation) * rotation;
21 }
22
23 public static void SetLocalX(this Transform transform, float localX) {
24 transform.setLocalAxis(localX, 0);
25 }
26
27 public static void SetLocalY(this Transform transform, float localY) {
28 transform.setLocalAxis(localY, 1);
29 }
30
31 public static void SetLocalZ(this Transform transform, float localZ) {
32 transform.setLocalAxis(localZ, 2);
33 }
34
35 private static void setLocalAxis(this Transform transform, float value, int axis) {
36 Vector3 local = transform.localPosition;
37 local[axis] = value;
38 transform.localPosition = local;
39 }
40 }
41
42}