Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
NeodroidDrawingUtilities.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace droid.Runtime.Utilities.Misc.Drawing {
6  public static partial class NeodroidDrawingUtilities {
14  public static void ForGizmo(Vector3 pos,
15  Vector3 direction,
16  Color color,
17  float arrow_head_length = 0.25f,
18  float arrow_head_angle = 20.0f) {
19  Gizmos.DrawRay(pos, direction);
20  NeodroidDrawingUtilitiesEnd(true, pos, direction, color, arrow_head_length, arrow_head_angle);
21  }
22 
31  public static void ForDebug(Vector3 pos,
32  Vector3 direction,
33  Color color,
34  float arrow_head_length = 0.25f,
35  float arrow_head_angle = 20.0f,
36  float ray_duration = 0f) {
37  if (ray_duration > 0) {
38  Debug.DrawRay(pos, direction, color, ray_duration);
39  } else {
40  Debug.DrawRay(pos, direction, color);
41  }
42 
43  NeodroidDrawingUtilitiesEnd(false,
44  pos,
45  direction,
46  color,
47  arrow_head_length,
48  arrow_head_angle,
49  ray_duration);
50  }
51 
52  static void NeodroidDrawingUtilitiesEnd(bool gizmos,
53  Vector3 pos,
54  Vector3 direction,
55  Color color,
56  float arrow_head_length = 0.25f,
57  float arrow_head_angle = 20.0f,
58  float ray_duration = 0f) {
59  var right = Quaternion.LookRotation(direction)
60  * Quaternion.Euler(arrow_head_angle, 0, 0)
61  * Vector3.back;
62  var left = Quaternion.LookRotation(direction)
63  * Quaternion.Euler(-arrow_head_angle, 0, 0)
64  * Vector3.back;
65  var up = Quaternion.LookRotation(direction) * Quaternion.Euler(0, arrow_head_angle, 0) * Vector3.back;
66  var down = Quaternion.LookRotation(direction)
67  * Quaternion.Euler(0, -arrow_head_angle, 0)
68  * Vector3.back;
69  if (gizmos) {
70  Gizmos.color = color;
71  Gizmos.DrawRay(pos + direction, right * arrow_head_length);
72  Gizmos.DrawRay(pos + direction, left * arrow_head_length);
73  Gizmos.DrawRay(pos + direction, up * arrow_head_length);
74  Gizmos.DrawRay(pos + direction, down * arrow_head_length);
75  } else {
76  if (ray_duration > 0) {
77  Debug.DrawRay(pos + direction, right * arrow_head_length, color, ray_duration);
78  Debug.DrawRay(pos + direction, left * arrow_head_length, color, ray_duration);
79  Debug.DrawRay(pos + direction, up * arrow_head_length, color, ray_duration);
80  Debug.DrawRay(pos + direction, down * arrow_head_length, color, ray_duration);
81  } else {
82  Debug.DrawRay(pos + direction, right * arrow_head_length, color);
83  Debug.DrawRay(pos + direction, left * arrow_head_length, color);
84  Debug.DrawRay(pos + direction, up * arrow_head_length, color);
85  Debug.DrawRay(pos + direction, down * arrow_head_length, color);
86  }
87  }
88 
89 /*
90  var arrow_size = 2;
91  Handles.color = Handles.xAxisColor;
92  Handles.ArrowHandleCap( 0, pos, Quaternion.Euler(direction), arrow_size,EventType.Repaint );
93  */
94  }
95  }
96 }