Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
TwoDimensionalScreenSpaceSensor.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Sensors.BoundingBox {
8  IHasDouble {
9  [SerializeField] Vector2 _observation_value = Vector2.zero;
10  [SerializeField] Space2 _observation_space2_d = Space2.ZeroOne;
11 
12  [SerializeField] UnityEngine.Camera _reference_camera = null;
13 
14  [SerializeField] bool _use_viewport = true; // Already normalised between 0 and 1
15 
16  // Update is called once per frame
17  public override IEnumerable<float> FloatEnumerable {
18  get { return new[] {this._observation_value.x, this.ObservationValue.y}; }
19  }
20 
21  public override void UpdateObservation() {
22  if (this._reference_camera) {
23  Vector3 point;
24  if (this._use_viewport) {
25  point = this._reference_camera.WorldToViewportPoint(this.transform.position);
26  } else {
27  point = this._reference_camera.WorldToScreenPoint(this.transform.position);
28  }
29 
30  this._observation_value = point;
31  }
32  }
33 
37  public Vector2 ObservationValue { get { return this._observation_value; } }
38 
42  public Space2 DoubleSpace { get { return this._observation_space2_d; } }
43  }
44 }