Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
EulerTransformSensor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
7 using UnityEngine;
8 
9 namespace droid.Runtime.Prototyping.Sensors.Transform {
12  public enum ObservationSpace {
15  Local_,
16 
19  Global_,
20 
24  }
25 
29  [AddComponentMenu(SensorComponentMenuPath._ComponentMenuPath
30  + "EulerTransform"
31  + SensorComponentMenuPath._Postfix)]
32  [ExecuteInEditMode]
33  [Serializable]
34  public class EulerTransformSensor : Sensor,
36  [SerializeField] Vector3 _direction;
37  [SerializeField] Space3 _direction_space = new Space3(new DistributionSampler(), 10);
38 
39  [Header("Observation", order = 103)]
40  [SerializeField]
41  Vector3 _position;
42 
43  [SerializeField] Space3 _position_space = new Space3(new DistributionSampler(), 10);
44 
45  [SerializeField] Vector3 _rotation;
46  [SerializeField] Space3 _rotation_space = new Space3(new DistributionSampler(), 10);
47 
48  [Header("Specific", order = 102)]
49  [SerializeField]
50  [SearchableEnum]
51  ObservationSpace _space = ObservationSpace.Environment_;
52 
56  public override string PrototypingTypeName { get { return "EulerTransform"; } }
57 
61  public Vector3 Position {
62  get { return this._position; }
63  set {
64  this._position = this._position_space.IsNormalised
65  ? this._position_space.ClipNormaliseRound(value)
66  : value;
67  }
68  }
69 
73  public Vector3 Rotation {
74  get { return this._rotation; }
75  set {
76  this._rotation = this._rotation_space.IsNormalised
77  ? this._rotation_space.ClipNormaliseRound(value)
78  : value;
79  }
80  }
81 
85  public Space3 PositionSpace { get; } = new Space3();
86 
90  public Space3 DirectionSpace { get; } = new Space3();
91 
95  public Space3 RotationSpace { get; } = new Space3();
96 
100  public Vector3 Direction {
101  get { return this._direction; }
102  set {
103  this._direction = this._direction_space.IsNormalised
104  ? this._direction_space.ClipNormaliseRound(value)
105  : value;
106  }
107  }
108 
112  public override IEnumerable<float> FloatEnumerable {
113  get {
114  return new[] {
115  this.Position.x,
116  this.Position.y,
117  this.Position.z,
118  this.Direction.x,
119  this.Direction.y,
120  this.Direction.z,
121  this.Rotation.x,
122  this.Rotation.y,
123  this.Rotation.z
124  };
125  }
126  }
127 
130  public override void UpdateObservation() {
131  var transform1 = this.transform;
132  if (this.ParentEnvironment != null && this._space == ObservationSpace.Environment_) {
133  this.Position = this.ParentEnvironment.TransformPoint(transform1.position);
134  this.Direction = this.ParentEnvironment.TransformDirection(transform1.forward);
135  this.Rotation = this.ParentEnvironment.TransformDirection(transform1.up);
136  } else if (this._space == ObservationSpace.Local_) {
137  this.Position = transform1.localPosition;
138  this.Direction = transform1.forward;
139  this.Rotation = transform1.up;
140  } else {
141  this.Position = transform1.position;
142  this.Direction = transform1.forward;
143  this.Rotation = transform1.up;
144  }
145  }
146 
150  protected override void PreSetup() { }
151  }
152 }
Vector3 ClipNormaliseRound(Vector3 v)
Definition: Space3.cs:55