This repository was archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
70 lines (56 loc) · 2.47 KB
/
Copy pathcamera.py
File metadata and controls
70 lines (56 loc) · 2.47 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
67
68
69
70
from math import sqrt, atan2
import math
import numpy as np
from OpenGL.GL import *
from OpenGL.GLU import *
__all__ = ["Camera"]
class Camera:
def __init__(self, fov, sensibility, speed, screen_size, nearclip, farclip):
self._speed_move = speed
self._sensibility = sensibility
self._aspect = (screen_size[0]/screen_size[1])
self._screen_size = screen_size
self._fov = fov
self._location = [-839.2773821545411,
-116.64508592611948,
479.71180621362146]
self._center = None
self._rotation = [0,0,0]
self._start = 0
self._nearclip = nearclip
self._farclip = farclip
glMatrixMode(GL_PROJECTION)
gluPerspective(self._fov, self._aspect, self._nearclip, self._farclip)
glMatrixMode(GL_MODELVIEW)
glTranslatef(self._location[0], self._location[1], self._location[2])
self.rotate(-350.02116749999999, 0.4055126249999996)
def rotate(self, mouse_dx, mouse_dy):
_buffer = glGetDoublev(GL_MODELVIEW_MATRIX)
self._center = (-1 * np.mat(_buffer[:3,:3]) * \
np.mat(_buffer[3,:3]).T).reshape(3,1)
glTranslate(self._center[0],self._center[1],self._center[2])
m = _buffer.flatten()
anglex = mouse_dx * self._sensibility
angley = mouse_dy * self._sensibility
glRotatef(anglex, m[1],m[5],m[9])
glRotatef(angley, m[0],m[4],m[8])
self._rotation[0] += anglex
self._rotation[1] += angley
glRotated(-math.atan2(-m[4],m[5]) * \
57.295779513082320876798154814105 ,m[2],m[6],m[10])
glTranslate(-self._center[0],-self._center[1],-self._center[2])
def move(self, front=False, back=False, left=False, right=False,
down=False, up=False):
#Move fron, back, left, right, down,up
fwd = self._speed_move * (front-back)
strafe = self._speed_move * (left-right)
mup = self._speed_move * (down-up)
if abs(fwd) or abs(strafe) or abs(mup):
m = glGetDoublev(GL_MODELVIEW_MATRIX).flatten()
glTranslate(fwd*m[2],fwd*m[6],fwd*m[10])
glTranslate(strafe*m[0],strafe*m[4],strafe*m[8])
glTranslate(0, mup, 0)
#save new position
self._location[0] += fwd*m[2] + strafe*m[0]
self._location[1] += fwd*m[6] + strafe*m[4] + mup
self._location[2] += fwd*m[10] + strafe*m[8]