-
Notifications
You must be signed in to change notification settings - Fork 2
/
BasicElements.py
131 lines (101 loc) · 3.33 KB
/
BasicElements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
from datetime import datetime
from math import degrees, sqrt, atan2
class Bookmark:
def __init__(self, grid, text, duration=0):
self.grid = grid
self.text = text
self.duration = duration
def __str__(self) -> str:
return (f'{self.grid}:{self.text} dur:{self.duration}')
class VisibleObject:
def __init__(self):
self.state = {
'avatar': True,
'ui': True,
'wall': True,
'wallFrame': True,
'saber': True,
'notes': True,
'debris': True,
}
def __str__(self) -> str:
return(str(self.state))
class Pos:
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def unpack(self):
return (self.x, self.y, self.z)
def __str__(self) -> str:
return(f'({self.x:.2f},{self.y:.2f},{self.z:.2f})')
def __eq__(self, obj):
if obj is None or type(self) != type(obj):
return False
return self.x == obj.x and self.y == obj.y and self.z == obj.z
class Rot:
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def unpack(self):
return (self.x, self.y, self.z)
def __str__(self) -> str:
return(f'({self.x:.2f},{self.y:.2f},{self.z:.2f})')
def __eq__(self, obj):
if obj is None or type(self) != type(obj):
return False
return self.x == obj.x and self.y == obj.y and self.z == obj.z
class Transform:
def __init__(self, pos=Pos(), rot=Rot(), fov=60):
self.pos = pos
self.rot = rot
self.fov = fov
def set(self, transform):
self.pos = transform.pos
self.rot = transform.rot
self.fov = transform.fov
def lookat(self, height, lastTransform):
theta = atan2(self.pos.z, self.pos.x)
theta = -int(degrees(theta))+270
r = sqrt(self.pos.x**2+self.pos.z**2)
angle = int(degrees(atan2(self.pos.y-height, r)))
self.rot.x = angle
self.rot.y = theta
self.rot.z = 0
def __str__(self) -> str:
return(f'POS:{self.pos}, ROT:{self.rot}, FOV:{self.fov}')
def __eq__(self, obj):
if obj is None or type(self) != type(obj):
return False
return self.pos == obj.pos and self.rot == obj.rot and self.fov == obj.fov
class Line:
def __init__(self, duration):
self.start = Transform()
self.end = Transform()
self.duration = duration
self.turnToHead = False
self.turnToHeadHorizontal = False
self.startHeadOffset = Pos()
self.endHeadOffset = Pos()
self.visibleDict = None
self.isNext = False
self.ease = ''
self.rot = ''
self.vib = ''
def __str__(self) -> str:
return (f'{self.duration:6.2f} {self.start} {self.end}')
class Logger:
def __init__(self, path_dir):
now = str(datetime.now()).replace(':', '_')[:19]
log_path = os.path.join(path_dir, 'log_latest.txt')
self.log_path = log_path
f = open(log_path, 'w', encoding='utf-8')
f.write(f"logfile at {now}\n\n")
def log(self, *args):
str_args = [str(a) for a in args]
text = ' '.join(str_args)
print(text)
f = open(self.log_path, 'a', encoding='utf-8')
f.write(text+'\n')