Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Unobservables.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using UnityEngine;
3 
4 namespace droid.Runtime.Messaging.Messages {
7  public class Unobservables {
8  public Unobservables(ref IList<Rigidbody> rigidbodies, ref IList<Transform> transforms) {
9  if (rigidbodies != null) {
10  this.Bodies = new Body[rigidbodies.Count];
11  for (var i = 0; i < this.Bodies.Length; i++) {
12  /*if (rigidbodies[i] != null) { //TODO: Proper way to construct unobservables in case somethings with destroyed but if this is the case then reinitialisation of a state wont work anyway and lets just crash.
13  this.Bodies[i] = new Body(rigidbodies[i].velocity, rigidbodies[i].angularVelocity);
14  }*/
15  this.Bodies[i] = new Body(rigidbodies[i].velocity, rigidbodies[i].angularVelocity);
16  }
17  }
18 
19  if (transforms != null) {
20  this.Poses = new Pose[transforms.Count];
21  for (var i = 0; i < this.Poses.Length; i++) {
22  /*if (transforms[i] != null) { //TODO: Proper way to construct unobservables in case somethings with destroyed but if this is the case then reinitialisation of a state wont work anyway and lets just crash.
23  this.Poses[i] = new Pose(transforms[i].position, transforms[i].rotation);
24  }*/
25  this.Poses[i] = new Pose(transforms[i].position, transforms[i].rotation);
26  }
27  }
28  }
29 
30  public Unobservables(ref Body[] bodies, ref Pose[] poses) {
31  this.Bodies = bodies;
32  this.Poses = poses;
33  }
34 
35  public Unobservables() { }
36 
37  public Unobservables(ref Rigidbody[] rigidbodies, ref Transform[] transforms) {
38  if (rigidbodies != null) {
39  this.Bodies = new Body[rigidbodies.Length];
40  for (var i = 0; i < this.Bodies.Length; i++) {
41  this.Bodies[i] = new Body(rigidbodies[i].velocity, rigidbodies[i].angularVelocity);
42  }
43  }
44 
45  if (transforms != null) {
46  this.Poses = new Pose[transforms.Length];
47  for (var i = 0; i < this.Poses.Length; i++) {
48  /*if (transforms[i] != null) { //TODO: Proper way to construct unobservables in case somethings with destroyed but if this is the case then reinitialisation of a state wont work anyway and lets just crash.
49  this.Poses[i] = new Pose(transforms[i].position, transforms[i].rotation);
50  }*/
51  this.Poses[i] = new Pose(transforms[i].position, transforms[i].rotation);
52  }
53  }
54  }
55 
58  public Body[] Bodies { get; } = { };
59 
62  public Pose[] Poses { get; } = { };
63 
67  public override string ToString() {
68  var poses_str = "";
69  if (this.Poses != null) {
70  foreach (var pose in this.Poses) {
71  poses_str += pose + "\n";
72  }
73  }
74 
75  var bodies_str = "";
76  if (this.Bodies != null) {
77  foreach (var body in this.Bodies) {
78  bodies_str += body + "\n";
79  }
80  }
81 
82  return $"<Unobservables>\n {poses_str},{bodies_str}\n</Unobservables>\n";
83  }
84  }
85 }
Unobservables(ref IList< Rigidbody > rigidbodies, ref IList< Transform > transforms)
Definition: Unobservables.cs:8
Unobservables(ref Rigidbody[] rigidbodies, ref Transform[] transforms)
Unobservables(ref Body[] bodies, ref Pose[] poses)