Tanoda
GeometryUtils.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 Leap.Unity.Infix;
11using UnityEngine;
12
13// using Drawer = Leap.Unity.RuntimeGizmos.RuntimeGizmoDrawer;
14
15namespace Leap.Unity.Geometry {
16
17 public static class GeometryUtils {
18
22 public static Vector2 Square2Circle(this Vector2 unitSquarePoint) {
23 var v = unitSquarePoint;
24 return v.Abs().CompMax() *
25 (v.CompMul(Vector2.one * 2.0f + v.Abs())).normalized;
26 }
27
28 #region Runtime Gizmos
29
30 private static Drawer s_drawer;
31
32 #region Render Sphere
33
37 public static void Render(this Sphere sphere) {
38 Drawer drawer;
39 if (TryGetDrawer(out drawer)) {
40 drawer.Sphere(sphere.center, sphere.radius);
41 }
42 }
43
44 public static void Render(this Sphere sphere, Color color) {
45 Drawer drawer;
46 if (TryGetDrawer(out drawer)) {
47 drawer.color = color;
48 drawer.Sphere(sphere.center, sphere.radius);
49 }
50 }
51
52 #endregion
53
54 #region Render Point
55
61 public static void Render(this Point point, Color? color, float scale = 1f) {
62 Drawer drawer;
63 if (TryGetDrawer(out drawer)) {
64
65 float finalScale = 0.01f * scale;
66 var pos = point.position;
67
68 if (color.HasValue) {
69 drawer.color = color.GetValueOrDefault();
70 }
71
72 if (!color.HasValue) {
73 drawer.color = Color.red;
74 }
75 drawer.Line(pos - Vector3.right * finalScale,
76 pos + Vector3.right * finalScale);
77
78 if (!color.HasValue) {
79 drawer.color = Color.green;
80 }
81 drawer.Line(pos - Vector3.up * finalScale,
82 pos + Vector3.up * finalScale);
83
84 if (!color.HasValue) {
85 drawer.color = Color.blue;
86 }
87 drawer.Line(pos - Vector3.forward * finalScale,
88 pos + Vector3.forward * finalScale);
89 }
90 }
95 public static void RenderSphere(this Point point, Color? color, float scale = 1f) {
96 Drawer drawer;
97 if (TryGetDrawer(out drawer)) {
98
99 float finalScale = 0.01f * scale;
100 var pos = point.position;
101
102 if (color.HasValue) {
103 drawer.color = color.GetValueOrDefault();
104 }
105
106 drawer.Sphere(pos, finalScale);
107 }
108 }
109
110 #endregion
111
112 #endregion
113
114 #region Internal
115
116 private static bool TryGetDrawer(out Drawer drawer) {
117 drawer = Drawer.UnityDebugDrawer;
118 return true;
119 }
120
121 #endregion
122
123 }
124
125}
UnityEngine.Color Color
Definition: TestScript.cs:32