-
Notifications
You must be signed in to change notification settings - Fork 0
/
ship.py
126 lines (72 loc) · 2.24 KB
/
ship.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
"""
3D Cube laser 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 Ship(object):
def __init__(self):
self.width = screen_size[0]
self.height = screen_size[1]
self.vertices = [
( 0.1945572 , 0.3603683 , 0.7174169 ),
( 0.1945572 , -4.39773 , 0.09228338 ),
( 0.6054428 , 0.3603683 , 0.3174169 ),
( 0.1945572 , 0.3603683 , 0.7174169 ),
( -0.2854428 , 0.3603683 , 0.7174169 ),
( -0.2854428 , -4.39773 , 0.09228338 ),
( -0.614193 , 0.4115218 , 0.1858825 ),
( -0.2854428 , 0.3603683 , 0.7174169 )
]
self.fov = 256
self.viewer_distance = 3.2
self.centerX = self.width / 2
self.centerY = self.height / 2
def Change(self,angleX,angleY,angleZ):
self.laspoints = []
for v in self.vertices:
# Rotate the point around X axis, then around Y axis, and finally around Z axis.
x = v[0]
y = v[1]
z = v[2]
#print "(", (x+0.5), ",", y, "," ,z,"),"
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 Move(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Mode(self,centerX,centerY):
self.centerX = centerX
self.centerY = centerY
def Zoom(self, zoom):
self.viewer_distance = zoom
def Draw(self,f):
f.PolyLineOneColor(self.laspoints, 0xFFFF00,True)