-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsomemath.py
66 lines (50 loc) · 1.52 KB
/
somemath.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
from settings import *
from numpy import sin, cos, pi
import json
inf = 10 ** 15
def tile(P):
return ((P[0] - WIDTH // 2), -(P[1] - HEIGHT // 2))
def coord(P):
return ((P[0] + WIDTH // 2), -P[1] + HEIGHT // 2)
def antiV(V):
return (-V[0], -V[1], -V[2])
def toViewport(P):
return (P[0] * (viewport_size / WIDTH), P[1] * (viewport_size / HEIGHT), Z_PROJECTION)
def subDot(P1, P2):
return (P1[0] - P2[0], P1[1] - P2[1], P1[2] - P2[2])
def dot(P1, P2):
return P1[0] * P2[0] + P1[1] * P2[1] + P1[2] * P2[2]
def multi(t, P):
return (t * P[0], t * P[1], t * P[2])
def sumPV(P, V):
return (P[0] + V[0], P[1] + V[1], P[2] + V[2])
def rotMatrix(z, y, x):
return ((cos(y), sin(y) * sin(z), -sin(y) * cos(z)),
(sin(x) * sin(y), cos(x) * cos(z) - sin(x) * cos(y) * sin(z), cos(x) * sin(z) + sin(x) * cos(y) * cos(z)),
(cos(x) * sin(y), -sin(x) * cos(z) - cos(x) * cos(y) * sin(z), -sin(x) * sin(z) + cos(x) * cos(y) * cos(z))
)
def degToRad(rot):
x, y, z = rot
x *= pi / 180
y *= pi / 180
z *= pi / 180
return x, y, z
def rotateCam(pos):
rot = camera.matrix
res = [0] * 3
for i in range(3):
for j in range(3):
res[i] += pos[j] * rot[i][j]
return tuple(res)
def normalizeRGB(RGB):
RGB = list(RGB)
for i in range(3):
if RGB[i] > 255:
RGB[i] = 255
return tuple(RGB)
def loadScene(path):
with open(path) as f:
data = json.load(f)
print(data)
def sqrt(x):
return x ** (1/2)