-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
146 lines (124 loc) · 4.36 KB
/
update.py
File metadata and controls
146 lines (124 loc) · 4.36 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import glm
import math
import vector
from gamecontroller import GameController
from camera import Camera
#mat4 rotate_x(float theta)
#{
# return mat4(
# vec4(1.0, 0.0, 0.0, 0.0),
# vec4(0.0, cos(theta), sin(theta), 0.0),
# vec4(0.0, -sin(theta), cos(theta), 0.0),
# vec4(0.0, 0.0, 0.0, 1.0)
# );
#}
#mat4 rotate_y(float theta)
#{
# return mat4(
# vec4( cos(theta), 0.0, sin(theta), 0.0),
# vec4( 0.0, 1.0, 0.0, 0.0),
# vec4(-sin(theta), 0.0, cos(theta), 0.0),
# vec4( 0.0, 0.0, 0.0, 1.0)
# );
#}
#mat4 rotate_z(float theta)
#{
# return mat4(
# vec4(cos(theta), -sin(theta), 0.0, 0.0),
# vec4(sin(theta), cos(theta), 0.0, 0.0),
# vec4( 0.0, 0.0, 1.0, 0.0),
# vec4( 0.0, 0.0, 0.0, 1.0)
# );
#}
def rotate_x(angle):
radians = math.radians(angle)
a = math.cos(radians)
b = math.sin(radians)
c = -(math.sin(radians))
d = math.cos(radians)
mat = glm.mat4(
[1,0,0,0],
[0,a,b,0],
[0,c,d,0],
[0,0,0,1]
)
return mat
def rotate_y(angle):
radians = math.radians(angle)
a = math.cos(radians)
b = math.sin(radians)
c = -(math.sin(radians))
d = math.cos(radians)
mat = glm.mat4(
[a,0,b,0],
[0,1,0,0],
[c,0,d,0],
[0,0,0,1]
)
return mat
def rotate_z(angle):
radians = math.radians(angle)
a = math.cos(radians)
b = -(math.sin(radians))
c = math.sin(radians)
d = math.cos(radians)
mat = glm.mat4(
[a,b,0,0],
[c,d,0,0],
[0,0,1,0],
[0,0,0,1]
)
return mat
def rotate(x,y,z):
matX = rotate_x(x)
matY = rotate_y(y)
matZ = rotate_z(z)
return (matZ * matY * matX)
def mat_x_vec(mat, vec):
vector = glm.vec4(vec,0)
print(vector)
vector = mat * vector
return vector
class UpdateLogic():
def __init__(self):
self.gameController = GameController()
self.camera = Camera((0.0, 0.0, 5.0))
#self.cameraPosition = {'x': 0.0, 'y': 0.0, 'z': 5.0}
#self.cameraDirection = {'x':0.0, 'y': 0.0, 'z': -1.0}
self.cameraMovementSpeed = 3.0
self.cameraRotationSpeed = 1
self._renderData = {}
def update(self, dt):
tmpz = self.camera.direction.z
if self.gameController.getValue('BTN_SOUTH','pressed') > 0:
tmpz = tmpz *-1
direction = glm.vec3(self.gameController.getValue('ABS_RX'),self.gameController.getValue('ABS_RY'),tmpz)
direction = glm.normalize(direction)
self.camera.direction.x = direction[0]
self.camera.direction.y = direction[1]
self.camera.direction.z = direction[2]
self.camera.direction.w = 0
m = rotate(15,30,0)
tmp = m * glm.vec4(self.camera.direction.getTuple())
self.camera.direction = vector.Vec4((tmp.x,tmp.y,tmp.z),tmp.w)
#Move forward/backward
self.camera.position = vector.Vec3(
glm.vec3(self.camera.position.getTuple())
+ (self.cameraMovementSpeed * self.gameController.getValue('ABS_Y') * dt)
* glm.vec3(self.camera.forward()))
#Move left/right
right = glm.vec3(self.camera.right())
self.camera.position = vector.Vec3(
glm.vec3(self.camera.position.getTuple())
+ (self.cameraMovementSpeed * self.gameController.getValue('ABS_X') * dt)
* right)
#self.camera.position.y = self.camera.position.y# + (self.cameraMovementSpeed['y'] * self.gameController.getValue('ABS_RY') * dt)
#self.camera.position.z = self.camera.position.z - (self.cameraMovementSpeed * self.gameController.getValue('ABS_Y') * dt)
#self.camera.position.x = self.camera.position.x + (self.cameraMovementSpeed['x'] * self.gameController.getValue('ABS_X') * dt)
#self.camera.position.y = self.camera.position.y# + (self.cameraMovementSpeed['y'] * self.gameController.getValue('ABS_RY') * dt)
#self.camera.position.z = self.camera.position.z - (self.cameraMovementSpeed['z'] * self.gameController.getValue('ABS_Y') * dt)
def getRenderData(self):
self._renderData = {}
self._renderData['cameraPosition'] = self.camera.position
self._renderData['cameraDirection'] = self.camera.direction
return self._renderData