-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
52 lines (48 loc) · 1.77 KB
/
camera.py
File metadata and controls
52 lines (48 loc) · 1.77 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
import glm
import vector
class Camera:
def __init__(self, xyz=(0.0,0.0,5.0), direction=(0.0,0.0,-1.0)):
self.position = vector.Vec3(xyz)
#FIX THIS
self.direction = vector.Vec4(direction,0)
#self.direction = vector.Vec3(direction)
#self.right = (1.0, 0.0, 0.0)
#self.forward = (0.0, 0.0, -1.0)
self.fov = 45.0
self.near = 0.1
self.far = 100.0
self.aspectRatio = 800.0 / 600.0
self.viewMatrix = (
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
)
self.projectionMatrix = (
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
)
def up(self):
return (0.0,1.0,0.0)
def right(self):
direction = glm.vec3(self.direction.getTuple())#getTupleVec3())
return glm.cross(direction, self.up())
def forward(self):
return self.direction.getTuple()#getTupleVec3()
def update(self):
position = glm.vec3(self.position.getTuple())
direction = glm.vec3(self.direction.getTuple())#getTupleVec3())
self.viewMatrix = self.toTuple(glm.lookAt(position, position + direction, self.up()))
self.projectionMatrix = self.toTuple(glm.perspective(glm.radians(self.fov), self.aspectRatio, self.near, self.far))
def lookAt(self, xyz):
position = glm.vec3(self.position.getTuple())
direction = glm.normalize(glm.vec3(xyz) - glm.vec3(position))
self.direction = vector.Vec4(direction)
def toTuple(self, data):
l = []
for row in data:
for value in row:
l.append(value)
return tuple(l)