Pascal Serrarens e218e0ea51 Event handling
2025-01-20 19:26:30 +01:00

70 lines
1.8 KiB
Python

from .Spherical import Spherical
from .Quaternion import Quaternion
## A thing is the basic building block
#
## A thing is the basic building block
class Thing:
class Type:
Undetermined = 0x00
Switch = 0x01
DistanceSensor = 0x02
DirectionalSensor = 0x03
TemperatureSensor = 0x04
Animator = 0x40
Position = 0x01
Orientation = 0x02
LinearVelocity = 0x04
AngularVelocity = 0x08
def __init__(self, network_id = 0, thing_id = 0, type=Type.Undetermined, parent=None, name=None):
self.network_id = network_id
self.id = thing_id
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):
print('default binary processor')
pass
allThings = set({ None })
@staticmethod
def Add(thing):
thing.id = len(Thing.allThings)
Thing.allThings.add(thing)
@staticmethod
def Get(network_id, thing_id):
for thing in Thing.allThings:
if thing is not None:
if thing.network_id == network_id and thing.id == thing_id:
return thing
return None
## Update all things
@staticmethod
def UpdateAll(currentTime):
for thing in list(Thing.allThings):
if thing is not None:
thing.update(currentTime)