forked from fogleman/Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameras.py
46 lines (35 loc) · 1.05 KB
/
cameras.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
# Imports, sorted alphabetically.
# Python packages
from math import cos, sin, radians
# Third-party packages
from pyglet.gl import *
# Modules from this project
# Nothing for now...
__all__ = (
'Camera3D',
)
class Camera3D(object):
def __init__(self, target=None):
self.target = target
self.x = 0.0
self.y = 0.0
self.z = 0.0
self.x_rotation = 0.0
self.y_rotation = 0.0
def rotate(self, x, y):
self.x_rotation = x
self.y_rotation = y
def update(self, dt):
if self.target:
self.x, self.y, self.z = self.target.position
def transform(self):
glRotatef(self.x_rotation, 0, 1, 0)
x_r = radians(self.x_rotation)
glRotatef(-self.y_rotation, cos(x_r), 0, sin(x_r))
glTranslatef(-self.x, -self.y, -self.z)
def look(self):
glRotatef(self.x_rotation, 0, 1, 0)
x_r = radians(self.x_rotation)
glRotatef(-self.y_rotation, cos(x_r), 0, sin(x_r))
glTranslatef(0, -40.0, 0)
glRotatef(-90.0, 1, 0, 0)