86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
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.parent = parent
|
|
|
|
## 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
|
|
## The new orientation in local space
|
|
self.orientation: Quaternion = Quaternion.identity
|
|
## The linear velocity of the thing in local space, in meters per second
|
|
self.linear_velocity: Spherical = Spherical.zero
|
|
## The angular velocity of the thing in local space, in degrees per second
|
|
self.angular_velocity: Spherical = Spherical.zero
|
|
|
|
self.pose_updated = 0x00 # the bits indicate which fields have been updated
|
|
self.owner.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)
|