-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.py
27 lines (22 loc) · 914 Bytes
/
camera.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
from euclid3 import *
class Camera:
def __init__(self, w, h):
self.projection = Matrix4().identity()
self.view = Matrix4().identity()
self.ortho(0.0, w, h, 0.0, 10.0, -10.0)
self.look_at(
Vector3(0.0, 0.0, 1.0),
Vector3(0.0, 0.0, 0.0),
Vector3(0.0, 1.0, 0.0),
)
def ortho(self, left, right, bottom, top, znear, zfar):
self.projection = Matrix4().identity()
self.projection.a = 2.0 / (right - left)
self.projection.f = 2.0 / (top - bottom)
self.projection.k = - 2.0 / (zfar - znear)
self.projection.m = - (right + left) / (right - left)
self.projection.n = - (top + bottom) / (top - bottom)
self.projection.o = - (zfar + znear) / (zfar - znear)
self.projection.transpose()
def look_at(self, eye, at, up):
self.view = Matrix4.new_look_at(eye, at, up)