8 namespace droid.Runtime.Prototyping.Configurables {
12 [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
13 +
"TransformConfigurable1Dof" 14 + ConfigurableComponentMenuPath._Postfix)]
20 public override string PrototypingTypeName {
21 get {
return "Transform" + this._axis_of_configuration +
"Configurable"; }
24 public float ObservationValue {
25 get {
return this._observation_value; }
26 private set { this._observation_value = value; }
33 get {
return this._single_value_space; }
34 set { this._single_value_space = value; }
42 var transform1 = this.transform;
43 var pos = transform1.position;
44 var dir = transform1.forward;
45 var rot = transform1.up;
46 if (this._use_environments_space) {
47 if (this.ParentEnvironment != null) {
48 pos = this.ParentEnvironment.TransformPoint(pos);
49 dir = this.ParentEnvironment.TransformDirection(dir);
50 rot = this.ParentEnvironment.TransformDirection(rot);
52 Debug.LogWarning(
"ParentEnvironment not found!");
56 switch (this._axis_of_configuration) {
58 this._observation_value = pos.x;
61 this._observation_value = pos.y;
64 this._observation_value = pos.z;
67 this._observation_value = dir.x;
70 this._observation_value = dir.y;
73 this._observation_value = dir.z;
76 this._observation_value = rot.x;
79 this._observation_value = rot.y;
82 this._observation_value = rot.z;
85 throw new ArgumentOutOfRangeException();
92 if (this._use_bounding_box_for_range) {
93 if (this._bounding_box != null) {
94 var valid_input =
new Space1 {
96 Math.Min(this._bounding_box.Bounds.size.x,
97 Math.Min(
this._bounding_box.Bounds.size.y,
98 this._bounding_box.Bounds.size.z))
100 valid_input.
_Min_Value = -valid_input._Max_Value;
101 this.SingleSpace = valid_input;
106 public override ISpace ConfigurableValueSpace {
get {
return this.SingleSpace; } }
116 Debug.Log($
"It does not accept input, outside allowed range {this.SingleSpace._Min_Value} to {this.SingleSpace._Max_Value}");
123 if (this.Debugging) {
124 Debug.Log(
"Applying " + simulator_configuration +
" To " + this.Identifier);
128 var transform1 = this.transform;
129 var pos = transform1.position;
130 var dir = transform1.forward;
131 var rot = transform1.up;
132 if (this._use_environments_space) {
133 if (this.ParentEnvironment != null) {
134 this.ParentEnvironment.TransformPoint(ref pos);
135 this.ParentEnvironment.TransformDirection(ref dir);
136 this.ParentEnvironment.TransformDirection(ref rot);
138 Debug.LogWarning(
"ParentEnvironment not found!");
142 switch (this._axis_of_configuration) {
144 if (this.RelativeToExistingValue) {
145 pos.Set(cv - pos.x, pos.y, pos.z);
147 pos.Set(cv, pos.y, pos.z);
152 if (this.RelativeToExistingValue) {
153 pos.Set(pos.x, cv - pos.y, pos.z);
155 pos.Set(pos.x, cv, pos.z);
160 if (this.RelativeToExistingValue) {
161 pos.Set(pos.x, pos.y, cv - pos.z);
163 pos.Set(pos.x, pos.y, cv);
168 if (this.RelativeToExistingValue) {
169 dir.Set(cv - dir.x, dir.y, dir.z);
171 dir.Set(cv, dir.y, dir.z);
176 if (this.RelativeToExistingValue) {
177 dir.Set(dir.x, cv - dir.y, dir.z);
179 dir.Set(dir.x, cv, dir.z);
184 if (this.RelativeToExistingValue) {
185 dir.Set(dir.x, dir.y, cv - dir.z);
187 dir.Set(dir.x, dir.y, cv);
192 if (this.RelativeToExistingValue) {
193 rot.Set(cv - rot.x, rot.y, rot.z);
195 rot.Set(cv, rot.y, rot.z);
200 if (this.RelativeToExistingValue) {
201 rot.Set(rot.x, cv - rot.y, rot.z);
203 rot.Set(rot.x, cv, rot.z);
208 if (this.RelativeToExistingValue) {
209 rot.Set(rot.x, rot.y, cv - rot.z);
211 rot.Set(rot.x, rot.y, cv);
216 throw new ArgumentOutOfRangeException();
222 if (this._use_environments_space) {
223 if (this.ParentEnvironment != null) {
224 this.ParentEnvironment.InverseTransformPoint(ref inv_pos);
225 this.ParentEnvironment.InverseTransformDirection(ref inv_dir);
226 this.ParentEnvironment.InverseTransformDirection(ref inv_rot);
228 Debug.LogWarning(
"ParentEnvironment not found!");
232 this.transform.position = inv_pos;
233 this.transform.rotation = Quaternion.identity;
234 this.transform.rotation = Quaternion.LookRotation(inv_dir, inv_rot);
239 [SerializeField]
Axis _axis_of_configuration =
Axis.X_;
241 [SerializeField]
bool _use_bounding_box_for_range =
false;
242 [SerializeField]
float _observation_value = 0;
243 [SerializeField]
bool _use_environments_space =
false;