-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaber2.py
143 lines (79 loc) · 2.39 KB
/
saber2.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
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
"""
Spiral animation
by Sam Neurohack
from /team/laser
Based on Wireframe 3D cube simulation.
Developed by Leonel Machava <leonelmachava@gmail.com>
Wipeout style ship
"""
from globalVars import *
import frame
import sys, math, random
SPEED = 4
SIZE = 40
class Saber2(object):
def __init__(self):
self.width = screen_size[0]
self.height = screen_size[1]
# (saberoriginx,saberoriginy,saberendx,saberendy)
self.saber=[(0,0,0),(0,150,0)]
self.centerX = self.width / 2
self.centerY = self.height / 2
self.fov = 256
self.viewer_distance = 50.2
self.angleX = 0
self.angleY = 0
self.angleZ = 0
self.color = 0xFF0000
def Move(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Mode(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Acc(self,accX,accY,accZ):
self.centerX += accX *100
self.centerY += accY *100
#self.centerZ += accZ *50
if self.centerX < 10:
self.centerX = 10
if self.centerX > self.width -10:
self.centerX = self.width -10
if self.centerY < 150:
self.centerY = 150
if self.centerY > self.height -150:
self.centerY = self.height -150
def Change(self,angleX,angleY,angleZ):
self.laspoints = []
for v in self.saber:
# Rotate the point around X axis, then around Y axis, and finally around Z axis.
x = v[0]
y = v[1]
z = v[2]
rad = angleX * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
y2 = y
y = y2 * cosa - z * sina
z = y2 * sina + z * cosa
rad = angleY * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
z2 = z
z = z2 * cosa - x * sina
x = z2 * sina + x * cosa
rad = angleZ * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
x2 = x
x = x2 * cosa - y * sina
y = x2 * sina + y * cosa
""" Transforms this 3D point to 2D using a perspective projection. """
factor = self.fov / (self.viewer_distance + z)
x = x * factor + self.centerX
y = - y * factor + self.centerY
self.laspoints.append((x,y))
def Zoom(self, zoom):
self.viewer_distance = zoom
def Draw(self,f):
f.PolyLineOneColor(self.laspoints, 0x00FF00,True)