from LinearAlgebra.Spherical import Spherical from LinearAlgebra.Quaternion import Quaternion class Thing: """! A thing is the basic building block""" class Type: """! Predefined thing types """ Undetermined = 0x00 # Sensor Switch = 0x01 DistanceSensor = 0x02 DirectionalSensor = 0x03 TemperatureSensor = 0x04 Animator = 0x40 Position = 0x01 Orientation = 0x02 LinearVelocity = 0x04 AngularVelocity = 0x08 def __init__(self, owner = None, network_id = 0, thing_id = 0, type = Type.Undetermined, parent = None, name = None): """! Create a new thing """ ## The parent thing self.parent = None if parent is not None: owner = parent.owner self.SetParent(parent) self.children = [] ## The participant owning this thing self.owner = owner ## The network ID of this thing ## @note This field will likely disappear in future versions self.network_id = network_id ## The ID of the thing self.id = thing_id ## The type of the thing self.type = type ## The name of the thing self.name = name ## An URL pointing to the location where a model of the thing can be found self.model_url = None ## The position of the thing in local space, in meters self.position: Spherical = Spherical.zero self.position_updated: bool = False ## The new orientation in local space self.orientation: Quaternion = Quaternion.identity self.orientation_updated: bool = False ## The linear velocity of the thing in local space, in meters per second self.linear_velocity: Spherical = Spherical.zero self.linear_velocity_updated: bool = False ## The angular velocity of the thing in local space, in degrees per second self.angular_velocity: Spherical = Spherical.zero self.angular_velocity_updated: bool = False self.pose_updated = 0x00 # the bits indicate which fields have been updated self.owner.Add(self) def SetPosition(self, position): self.position = position self.position_updated = True def SetLinearVelocity(self, linear_velocity): self.linear_velocity = linear_velocity self.linear_velocity_updated = True def SetAngularVelocity(self, angular_velocity): self.angular_velocity = angular_velocity self.angular_velocity_updated = True def Update(self, currentTime): pass def ProcessBinary(self, data): print('default binary processor') pass def SetParent(self, parent): if parent is None: parentThing = self.parent if parentThing is not None: parentThing.RemoveChild(self) self.parent = None else: parent.AddChild(self) def AddChild(self, child): if child in self.children: return child.parent = self self.children.append(child) def RemoveChild(self, child): self.children.remove(child)