-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.py
More file actions
66 lines (58 loc) · 1.7 KB
/
matrix.py
File metadata and controls
66 lines (58 loc) · 1.7 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
import numpy as np
from math import sin, cos, tan, pi
class Matrix(object):
@staticmethod
def makeIdentity():
return np.identity(4, dtype=np.float32)
@staticmethod
def makeTranslation(x, y, z):
return np.array([
[1, 0, 0, x],
[0, 1, 0, y],
[0, 0, 1, z],
[0, 0, 0, 1]]).astype(np.float32)
@staticmethod
def makeRotationX(angle):
c = cos(angle)
s = sin(angle)
return np.array([
[1, 0, 0, 0],
[0, c, -s, 0],
[0, s, c, 0],
[0, 0, 0, 1]]).astype(np.float32)
@staticmethod
def makeRotationY(angle):
c = cos(angle)
s = sin(angle)
return np.array([
[c, 0, s, 0],
[0, 1, 0, 0],
[-s, 0, c, 0],
[0, 0, 0, 1]]).astype(np.float32)
@staticmethod
def makeRotationZ(angle):
c = cos(angle)
s = sin(angle)
return np.array([
[c, -s, 0, 0],
[s, c, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]).astype(np.float32)
@staticmethod
def makeScale(s):
return np.array([
[s, 0, 0, 0],
[0, s, 0, 0],
[0, 0, s, 0],
[0, 0, 0, 1]]).astype(np.float32)
@staticmethod
def makePerspective(angleOfView=60, aspectRatio=1, near=0.1, far=1000):
a = angleOfView * pi/180.0
d = 1.0 / tan(a/2)
r = aspectRatio
b = (far + near) / (near - far)
c = 2*far*near / (near - far)
return np.array([[d/r, 0, 0, 0],
[0, d, 0, 0],
[0, 0, b, c],
[0, 0, -1, 0]]).astype(np.float32)