from LinearAlgebra.Spherical import Spherical from LinearAlgebra.Quaternion import Quaternion ## A thing is the basic building block # ## A thing is the basic building block class Thing: """ A thing is the basic building block""" class Type: Undetermined = 0x00 Switch = 0x01 DistanceSensor = 0x02 DirectionalSensor = 0x03 Animator = 0x40 Position = 0x01 Orientation = 0x02 LinearVelocity = 0x04 AngularVelocity = 0x08 def __init__(self, type=Type.Undetermined, parent=None, name=None): self.networkId = 0 self.id = 0 self.type = type if parent is None: self.parent_id = 0 else: self.parent_id = parent.id self.name = name self.model_url = None self.position = Spherical.zero self.orientation = Quaternion.identity self.linearVelocity = Spherical.zero self.angularVelocity = Spherical.zero self.pose_updated = 0x00 # the bits indicate which fields have been updated Thing.Add(self) def update(self, currentTime): pass def ProcessBinary(self, data): pass allThings = set({ None }) @staticmethod def Add(thing): thing.id = len(Thing.allThings) Thing.allThings.add(thing) @staticmethod def Get(networkId, thingId): for thing in Thing.allThings: if thing is not None: if thing.networkId == networkId and thing.id == thingId: return thing return None ## Update all things @staticmethod def UpdateAll(currentTime): for thing in Thing.allThings: if thing is not None: thing.update(currentTime)