4 namespace droid.Runtime.Utilities.GameObjects.BoundingBoxes.Experimental {
7 public static class Corners {
8 public static Vector3[] ExtractCorners(Vector3 v3_center,
10 Transform reference_transform = null) {
11 var v3_front_top_left =
new Vector3(v3_center.x - v3_extents.x,
12 v3_center.y + v3_extents.y,
13 v3_center.z - v3_extents.z);
14 var v3_front_top_right =
new Vector3(v3_center.x + v3_extents.x,
15 v3_center.y + v3_extents.y,
16 v3_center.z - v3_extents.z);
17 var v3_front_bottom_left =
new Vector3(v3_center.x - v3_extents.x,
18 v3_center.y - v3_extents.y,
19 v3_center.z - v3_extents.z);
20 var v3_front_bottom_right =
new Vector3(v3_center.x + v3_extents.x,
21 v3_center.y - v3_extents.y,
22 v3_center.z - v3_extents.z);
23 var v3_back_top_left =
new Vector3(v3_center.x - v3_extents.x,
24 v3_center.y + v3_extents.y,
25 v3_center.z + v3_extents.z);
26 var v3_back_top_right =
new Vector3(v3_center.x + v3_extents.x,
27 v3_center.y + v3_extents.y,
28 v3_center.z + v3_extents.z);
29 var v3_back_bottom_left =
new Vector3(v3_center.x - v3_extents.x,
30 v3_center.y - v3_extents.y,
31 v3_center.z + v3_extents.z);
32 var v3_back_bottom_right =
new Vector3(v3_center.x + v3_extents.x,
33 v3_center.y - v3_extents.y,
34 v3_center.z + v3_extents.z);
35 if (reference_transform) {
36 v3_front_top_left = reference_transform.TransformPoint(v3_front_top_left);
37 v3_front_top_right = reference_transform.TransformPoint(v3_front_top_right);
38 v3_front_bottom_left = reference_transform.TransformPoint(v3_front_bottom_left);
39 v3_front_bottom_right = reference_transform.TransformPoint(v3_front_bottom_right);
40 v3_back_top_left = reference_transform.TransformPoint(v3_back_top_left);
41 v3_back_top_right = reference_transform.TransformPoint(v3_back_top_right);
42 v3_back_bottom_left = reference_transform.TransformPoint(v3_back_bottom_left);
43 v3_back_bottom_right = reference_transform.TransformPoint(v3_back_bottom_right);
50 v3_front_bottom_right,
69 public static void DrawBox(Vector3 v3_front_top_left,
70 Vector3 v3_front_top_right,
71 Vector3 v3_front_bottom_left,
72 Vector3 v3_front_bottom_right,
73 Vector3 v3_back_top_left,
74 Vector3 v3_back_top_right,
75 Vector3 v3_back_bottom_left,
76 Vector3 v3_back_bottom_right,
78 Debug.DrawLine(v3_front_top_left, v3_front_top_right, color);
79 Debug.DrawLine(v3_front_top_right, v3_front_bottom_right, color);
80 Debug.DrawLine(v3_front_bottom_right, v3_front_bottom_left, color);
81 Debug.DrawLine(v3_front_bottom_left, v3_front_top_left, color);
83 Debug.DrawLine(v3_back_top_left, v3_back_top_right, color);
84 Debug.DrawLine(v3_back_top_right, v3_back_bottom_right, color);
85 Debug.DrawLine(v3_back_bottom_right, v3_back_bottom_left, color);
86 Debug.DrawLine(v3_back_bottom_left, v3_back_top_left, color);
88 Debug.DrawLine(v3_front_top_left, v3_back_top_left, color);
89 Debug.DrawLine(v3_front_top_right, v3_back_top_right, color);
90 Debug.DrawLine(v3_front_bottom_right, v3_back_bottom_right, color);
91 Debug.DrawLine(v3_front_bottom_left, v3_back_bottom_left, color);
102 public static void DrawCircle(Vector2 center,
105 float num_segments = 40,
106 float duration = 0.01f) {
107 var rot_quaternion = Quaternion.AngleAxis(360.0f / num_segments, Vector3.forward);
108 var vertex_start =
new Vector2(radius, 0.0f);
109 for (var i = 0; i < num_segments; i++) {
110 Vector2 rotated_point = rot_quaternion * vertex_start;
113 Debug.DrawLine(center + vertex_start, center + rotated_point, color, duration);
115 vertex_start = rotated_point;
126 public static void DrawBox(Vector2 world_top_left,
127 Vector2 world_bottom_right,
129 float duration = 0.01f) {
130 var world_top_right =
new Vector2(world_bottom_right.x, world_top_left.y);
131 var world_bottom_left =
new Vector2(world_top_left.x, world_bottom_right.y);
133 Debug.DrawLine(world_top_left, world_bottom_left, color, duration);
134 Debug.DrawLine(world_bottom_left, world_bottom_right, color, duration);
135 Debug.DrawLine(world_bottom_right, world_top_right, color, duration);
136 Debug.DrawLine(world_top_right, world_top_left, color, duration);
145 public static void DrawEdges(Vector2[] world_points, Color color,
float duration = 0.01f) {
147 for (var i = 0; i < world_points.Length - 1; i++) {
148 Vector3 next_point = world_points[i + 1];
149 Vector3 current_point = world_points[i];
150 Debug.DrawLine(current_point, next_point, color, duration);
160 public static void DrawPolygon(Vector2[] world_points, Color color,
float duration = 0.01f) {
161 DrawEdges(world_points, color, duration);
164 if (world_points.Length > 1) {
165 Debug.DrawLine(world_points[world_points.Length - 1], world_points[0], color, duration);
176 public static void DrawArrow(Vector2 origin, Vector2 endpoint, Color color,
float duration = 0.01f) {
178 Debug.DrawLine(origin, endpoint, color, 0.01f);
181 var arrow_direction = endpoint - origin;
182 DebugDrawArrowhead(endpoint,
183 arrow_direction.normalized,
184 GetArrowSizeForLine(arrow_direction),
189 static float GetArrowSizeForLine(Vector2 line) {
190 const Single default_arrow_percentage = 0.05f;
191 return (line * default_arrow_percentage).magnitude;
194 static void DebugDrawArrowhead(Vector2 origin,
198 float duration = 0.01f,
199 float theta = 30.0f) {
201 var arrowhead_handle = -direction * size;
203 var arrow_rotation_r = Quaternion.AngleAxis(theta, Vector3.forward);
204 Vector2 arrowhead_r = arrow_rotation_r * arrowhead_handle;
205 Debug.DrawLine(origin, origin + arrowhead_r, color, duration);
207 var arrow_rotation_l = Quaternion.AngleAxis(-theta, Vector3.forward);
208 Vector2 arrowhead_l = arrow_rotation_l * arrowhead_handle;
209 Debug.DrawLine(origin, origin + arrowhead_l, color, duration);