forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix4x4.py
More file actions
266 lines (222 loc) · 5.39 KB
/
Copy pathMatrix4x4.py
File metadata and controls
266 lines (222 loc) · 5.39 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from .Vector3 import Vector3
class Matrix4x4:
M: list
def __init__(self, values):
if len(values) != 16:
raise ValueError(
"There must be sixteen and only sixteen input values for Matrix."
)
self.M = values
def __getitem__(self, index):
if isinstance(index, tuple):
index = index[0] + index[1] * 4
return self.M[index]
def __setitem__(self, index, value):
if isinstance(index, tuple):
# row, column
index = index[0] + index[1] * 4
self.M[index] = value
def __eq__(self, other):
if not isinstance(other, Matrix4x4):
return False
print()
def __mul__(lhs, rhs):
res = Matrix4x4([0] * 16)
res.M00 = (
lhs.M00 * rhs.M00
+ lhs.M01 * rhs.M10
+ lhs.M02 * rhs.M20
+ lhs.M03 * rhs.M30
)
res.M01 = (
lhs.M00 * rhs.M01
+ lhs.M01 * rhs.M11
+ lhs.M02 * rhs.M21
+ lhs.M03 * rhs.M31
)
res.M02 = (
lhs.M00 * rhs.M02
+ lhs.M01 * rhs.M12
+ lhs.M02 * rhs.M22
+ lhs.M03 * rhs.M32
)
res.M03 = (
lhs.M00 * rhs.M03
+ lhs.M01 * rhs.M13
+ lhs.M02 * rhs.M23
+ lhs.M03 * rhs.M33
)
res.M10 = (
lhs.M10 * rhs.M00
+ lhs.M11 * rhs.M10
+ lhs.M12 * rhs.M20
+ lhs.M13 * rhs.M30
)
res.M11 = (
lhs.M10 * rhs.M01
+ lhs.M11 * rhs.M11
+ lhs.M12 * rhs.M21
+ lhs.M13 * rhs.M31
)
res.M12 = (
lhs.M10 * rhs.M02
+ lhs.M11 * rhs.M12
+ lhs.M12 * rhs.M22
+ lhs.M13 * rhs.M32
)
res.M13 = (
lhs.M10 * rhs.M03
+ lhs.M11 * rhs.M13
+ lhs.M12 * rhs.M23
+ lhs.M13 * rhs.M33
)
res.M20 = (
lhs.M20 * rhs.M00
+ lhs.M21 * rhs.M10
+ lhs.M22 * rhs.M20
+ lhs.M23 * rhs.M30
)
res.M21 = (
lhs.M20 * rhs.M01
+ lhs.M21 * rhs.M11
+ lhs.M22 * rhs.M21
+ lhs.M23 * rhs.M31
)
res.M22 = (
lhs.M20 * rhs.M02
+ lhs.M21 * rhs.M12
+ lhs.M22 * rhs.M22
+ lhs.M23 * rhs.M32
)
res.M23 = (
lhs.M20 * rhs.M03
+ lhs.M21 * rhs.M13
+ lhs.M22 * rhs.M23
+ lhs.M23 * rhs.M33
)
res.M30 = (
lhs.M30 * rhs.M00
+ lhs.M31 * rhs.M10
+ lhs.M32 * rhs.M20
+ lhs.M33 * rhs.M30
)
res.M31 = (
lhs.M30 * rhs.M01
+ lhs.M31 * rhs.M11
+ lhs.M32 * rhs.M21
+ lhs.M33 * rhs.M31
)
res.M32 = (
lhs.M30 * rhs.M02
+ lhs.M31 * rhs.M12
+ lhs.M32 * rhs.M22
+ lhs.M33 * rhs.M32
)
res.M33 = (
lhs.M30 * rhs.M03
+ lhs.M31 * rhs.M13
+ lhs.M32 * rhs.M23
+ lhs.M33 * rhs.M33
)
return res
@staticmethod
def Scale(vector: Vector3):
return Matrix4x4(
[vector.X, 0, 0, 0, 0, vector.Y, 0, 0, 0, 0, vector.Z, 0, 0, 0, 0, 1]
)
@property
def M00(self):
return self.M[0]
@M00.setter
def M00(self, value):
self.M[0] = value
@property
def M10(self):
return self.M[1]
@M10.setter
def M10(self, value):
self.M[1] = value
@property
def M20(self):
return self.M[2]
@M20.setter
def M20(self, value):
self.M[2] = value
@property
def M30(self):
return self.M[3]
@M30.setter
def M30(self, value):
self.M[3] = value
@property
def M01(self):
return self.M[4]
@M01.setter
def M01(self, value):
self.M[4] = value
@property
def M11(self):
return self.M[5]
@M11.setter
def M11(self, value):
self.M[5] = value
@property
def M21(self):
return self.M[6]
@M21.setter
def M21(self, value):
self.M[6] = value
@property
def M31(self):
return self.M[7]
@M31.setter
def M31(self, value):
self.M[7] = value
@property
def M02(self):
return self.M[8]
@M02.setter
def M02(self, value):
self.M[8] = value
@property
def M12(self):
return self.M[9]
@M12.setter
def M12(self, value):
self.M[9] = value
@property
def M22(self):
return self.M[10]
@M22.setter
def M22(self, value):
self.M[10] = value
@property
def M32(self):
return self.M[11]
@M32.setter
def M32(self, value):
self.M[11] = value
@property
def M03(self):
return self.M[12]
@M03.setter
def M03(self, value):
self.M[12] = value
@property
def M13(self):
return self.M[13]
@M13.setter
def M13(self, value):
self.M[13] = value
@property
def M23(self):
return self.M[14]
@M23.setter
def M23(self, value):
self.M[14] = value
@property
def M33(self):
return self.M[15]
@M33.setter
def M33(self, value):
self.M[15] = value