1 using System.Collections.Generic;
6 namespace droid.Runtime.Prototyping.Sensors.Rays {
10 [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
11 +
"InstantUniformLidar" 12 + SensorComponentMenuPath._Postfix)]
15 [SerializeField] RaycastHit _hit;
17 [SerializeField]
bool _is_2_d =
false;
19 [Header(
"Observation", order = 103)]
23 [SerializeField]
Space1 _space =
new Space1 {_Min_Value = 0, _Max_Value = 5f};
27 public override string PrototypingTypeName {
get {
return "Adjacency"; } }
31 public RaycastHit Hit {
get {
return this._hit; }
set { this._hit = value; } }
33 public override IEnumerable<float> FloatEnumerable {
get {
return this.ObservationArray; } }
37 public float[] ObservationArray {
38 get {
return this._obs_array; }
39 private set { this._obs_array = value; }
48 this.ObservationArray =
new float[8];
50 this.ObservationArray =
new float[27];
58 var vals =
new float[8];
59 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.forward,
62 this._space._Max_Value)) {
68 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.left,
71 this._space._Max_Value)) {
77 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.right,
80 this._space._Max_Value)) {
86 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.back,
89 this._space._Max_Value)) {
95 if (Physics.Raycast(
this.transform.position
96 +
this._space._Min_Value * (Vector3.forward + Vector3.left).normalized,
97 (Vector3.forward + Vector3.left).normalized,
99 this._space._Max_Value)) {
105 if (Physics.Raycast(
this.transform.position
106 +
this._space._Min_Value * (Vector3.forward + Vector3.right).normalized,
107 (Vector3.forward + Vector3.right).normalized,
109 this._space._Max_Value)) {
115 if (Physics.Raycast(
this.transform.position
116 +
this._space._Min_Value * (Vector3.back + Vector3.left).normalized,
117 (Vector3.back + Vector3.left).normalized,
119 this._space._Max_Value)) {
125 if (Physics.Raycast(
this.transform.position
126 +
this._space._Min_Value * (Vector3.back + Vector3.right).normalized,
127 (Vector3.back + Vector3.right).normalized,
129 this._space._Max_Value)) {
135 this.ObservationArray = vals;
137 var vals =
new float[27];
138 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.forward,
141 this._space._Max_Value)) {
147 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.left,
150 this._space._Max_Value)) {
156 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.right,
159 this._space._Max_Value)) {
165 if (Physics.Raycast(
this.transform.position +
this._space._Min_Value * Vector3.back,
168 this._space._Max_Value)) {
174 if (Physics.Raycast(
this.transform.position
175 +
this._space._Min_Value * (Vector3.forward + Vector3.left).normalized,
176 (Vector3.forward + Vector3.left).normalized,
178 this._space._Max_Value)) {
184 if (Physics.Raycast(
this.transform.position
185 +
this._space._Min_Value * (Vector3.forward + Vector3.right).normalized,
186 (Vector3.forward + Vector3.right).normalized,
188 this._space._Max_Value)) {
194 if (Physics.Raycast(
this.transform.position
195 +
this._space._Min_Value * (Vector3.back + Vector3.left).normalized,
196 (Vector3.back + Vector3.left).normalized,
198 this._space._Max_Value)) {
204 if (Physics.Raycast(
this.transform.position
205 +
this._space._Min_Value * (Vector3.back + Vector3.right).normalized,
206 (Vector3.back + Vector3.right).normalized,
208 this._space._Max_Value)) {
216 this.ObservationArray = vals;
221 [SerializeField] Color _color = Color.green;
223 void OnDrawGizmosSelected() {
225 var position = this.transform.position;
226 Debug.DrawLine(position, position - Vector3.forward *
this._space._Max_Value,
this._color);
227 Debug.DrawLine(position, position - Vector3.left *
this._space._Max_Value,
this._color);
228 Debug.DrawLine(position, position - Vector3.right *
this._space._Max_Value,
this._color);
229 Debug.DrawLine(position, position - Vector3.back *
this._space._Max_Value,
this._color);
230 Debug.DrawLine(position,
231 position - (Vector3.forward + Vector3.left).normalized *
this._space._Max_Value,
233 Debug.DrawLine(position,
234 position - (Vector3.forward + Vector3.right).normalized *
this._space._Max_Value,
236 Debug.DrawLine(position,
237 position - (Vector3.back + Vector3.left).normalized *
this._space._Max_Value,
239 Debug.DrawLine(position,
240 position - (Vector3.back + Vector3.right).normalized *
this._space._Max_Value,
243 var position1 = this.transform.position;
244 Debug.DrawLine(position1, position1 - Vector3.up *
this._space._Max_Value,
this._color);
245 Debug.DrawLine(position1, position1 - Vector3.down *
this._space._Max_Value,
this._color);
247 Debug.DrawLine(position1,
248 position1 - (Vector3.up + Vector3.left).normalized *
this._space._Max_Value,
250 Debug.DrawLine(position1,
251 position1 - (Vector3.up + Vector3.right).normalized *
this._space._Max_Value,
253 Debug.DrawLine(position1,
254 position1 - (Vector3.up + Vector3.forward).normalized *
this._space._Max_Value,
256 Debug.DrawLine(position1,
257 position1 - (Vector3.up + Vector3.back).normalized *
this._space._Max_Value,
260 Debug.DrawLine(position1,
261 position1 - (Vector3.down + Vector3.left).normalized *
this._space._Max_Value,
264 Debug.DrawLine(position1,
265 position1 - (Vector3.down + Vector3.right).normalized *
this._space._Max_Value,
268 Debug.DrawLine(position1,
269 position1 - (Vector3.down + Vector3.forward).normalized *
this._space._Max_Value,
272 Debug.DrawLine(position1,
273 position1 - (Vector3.down + Vector3.back).normalized *
this._space._Max_Value,
276 Debug.DrawLine(position1,
278 - (Vector3.down + Vector3.forward + Vector3.left).normalized
279 *
this._space._Max_Value,
282 Debug.DrawLine(position1,
284 - (Vector3.down + Vector3.forward + Vector3.right).normalized
285 *
this._space._Max_Value,
287 Debug.DrawLine(position1,
289 - (Vector3.down + Vector3.back + Vector3.left).normalized *
this._space._Max_Value,
292 Debug.DrawLine(position1,
294 - (Vector3.down + Vector3.back + Vector3.right).normalized *
this._space._Max_Value,
297 Debug.DrawLine(position1,
299 - (Vector3.up + Vector3.forward + Vector3.left).normalized *
this._space._Max_Value,
302 Debug.DrawLine(position1,
304 - (Vector3.up + Vector3.forward + Vector3.right).normalized *
this._space._Max_Value,
306 Debug.DrawLine(position1,
308 - (Vector3.up + Vector3.back + Vector3.left).normalized *
this._space._Max_Value,
311 Debug.DrawLine(position1,
313 - (Vector3.up + Vector3.back + Vector3.right).normalized *
this._space._Max_Value,
float ClipNormaliseRound(float v)