2019-12-11 19:25:31 +01:00
|
|
|
from ctypes import *
|
2022-01-26 04:41:09 +01:00
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
|
|
|
|
class Color(Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('r', c_ubyte),
|
|
|
|
('g', c_ubyte),
|
|
|
|
('b', c_ubyte),
|
|
|
|
('a', c_ubyte),
|
|
|
|
]
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
yield self.r
|
|
|
|
yield self.g
|
|
|
|
yield self.b
|
|
|
|
yield self.a
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return all(map(lambda x: x[0] == x[1], zip(self, other)))
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return repr(tuple(self))
|
|
|
|
|
|
|
|
def normalized(self) -> Tuple:
|
|
|
|
return tuple(map(lambda x: x / 255.0, iter(self)))
|
|
|
|
|
|
|
|
|
|
|
|
class Vector2(Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('x', c_float),
|
|
|
|
('y', c_float),
|
|
|
|
]
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
yield self.x
|
|
|
|
yield self.y
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return repr(tuple(self))
|
2019-12-11 19:25:31 +01:00
|
|
|
|
2019-12-13 20:29:12 +01:00
|
|
|
|
2019-12-11 19:25:31 +01:00
|
|
|
class Vector3(Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('x', c_float),
|
|
|
|
('y', c_float),
|
|
|
|
('z', c_float),
|
|
|
|
]
|
|
|
|
|
2022-01-14 21:26:35 +01:00
|
|
|
def __iter__(self):
|
|
|
|
yield self.x
|
|
|
|
yield self.y
|
|
|
|
yield self.z
|
|
|
|
|
2022-01-15 06:04:18 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return repr(tuple(self))
|
|
|
|
|
2022-04-04 09:32:12 +02:00
|
|
|
@classmethod
|
|
|
|
def zero(cls):
|
|
|
|
return Vector3(0, 0, 0)
|
|
|
|
|
2019-12-11 19:25:31 +01:00
|
|
|
|
|
|
|
class Quaternion(Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('x', c_float),
|
|
|
|
('y', c_float),
|
|
|
|
('z', c_float),
|
|
|
|
('w', c_float),
|
|
|
|
]
|
|
|
|
|
2021-09-07 09:02:59 +02:00
|
|
|
def __iter__(self):
|
2022-01-14 21:26:35 +01:00
|
|
|
yield self.w
|
2021-09-07 09:02:59 +02:00
|
|
|
yield self.x
|
|
|
|
yield self.y
|
|
|
|
yield self.z
|
|
|
|
|
2022-01-15 06:04:18 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return repr(tuple(self))
|
|
|
|
|
2022-04-04 09:32:12 +02:00
|
|
|
@classmethod
|
|
|
|
def identity(cls):
|
|
|
|
return Quaternion(0, 0, 0, 1)
|
|
|
|
|
2019-12-11 19:25:31 +01:00
|
|
|
|
|
|
|
class Section(Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('name', c_char * 20),
|
|
|
|
('type_flags', c_int32),
|
|
|
|
('data_size', c_int32),
|
|
|
|
('data_count', c_int32)
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, *args, **kw):
|
|
|
|
super().__init__(*args, **kw)
|
|
|
|
self.type_flags = 1999801
|