-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing 3d.py
95 lines (82 loc) · 3.31 KB
/
testing 3d.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
import math
import pygame as pg
import win32api
from Game import Game
def sc(theta):
return math.sin(theta)*math.cos(theta)
def clamp(val, mini, maxi):
return max(min(maxi, val), mini)
boxX, boxY = 150, 150
boxW, boxH = 100, 100
boxZ, boxD = 100, 100
thetaX = math.radians(45)
thetaY = math.radians(45)
def checkHeld(game: Game):
global thetaY, holding, thetaX
if "up" in game.holding:
thetaY = clamp((thetaY + math.radians(1)), -math.pi/4, math.pi/4)
if "down" in game.holding:
thetaY = clamp((thetaY - math.radians(1)), -math.pi/4, math.pi/4)
if "right" in game.holding:
thetaX = clamp((thetaX + math.radians(1)), -math.pi/4, math.pi/4)
if "left" in game.holding:
thetaX = clamp((thetaX -math.radians(1)), -math.pi/4, math.pi/4)
# thetaX = (thetaX - math.radians(1))%math.pi
if "enter" in game.holding:
print(thetaX, thetaY)
def loop(game: Game):
while game.eventhandler.isRunning():
ptlist = [
(boxX-int(boxW/2), boxY-int(boxH/2)),
(boxX-int(boxW/2)+boxD*sc(thetaX), boxY-int(boxH/2)-boxD*sc(thetaY)),
]
game.eventhandler.updateEvents()
checkHeld(game)
pg.draw.aalines(game.screen,
"white",
False,
[(boxX-int(boxW/2), boxY-int(boxH/2)),
(boxX-int(boxW/2) + boxD*sc(thetaX), boxY-int(boxH/2)-boxD*sc(thetaY)),
(boxX+int(boxW/2) + boxD*sc(thetaX), boxY-int(boxH/2)-boxD*sc(thetaY)),
(boxX+int(boxW/2), boxY-int(boxH/2)),
(boxX-int(boxW/2), boxY-int(boxH/2)),
(boxX-int(boxW/2), boxY+int(boxH/2)),
(boxX+int(boxW/2), boxY+int(boxH/2)),
(boxX+int(boxW/2)+boxD*sc(thetaX), boxY+int(boxH/2)-boxD*sc(thetaY)),
(boxX-int(boxW/2)+boxD*sc(thetaX), boxY+int(boxH/2)-boxD*sc(thetaY)),
(boxX-int(boxW/2), boxY+int(boxH/2))])
pg.draw.aaline(game.screen,
"white",
(boxX-int(boxW/2)+boxD*sc(thetaX), boxY-int(boxH/2)-boxD*sc(thetaY)),
(boxX-int(boxW/2)+boxD*sc(thetaX), boxY+int(boxH/2)-boxD*sc(thetaY)))
pg.draw.aaline(game.screen,
"white",
(boxX+int(boxW/2), boxY-int(boxH/2)),
(boxX+int(boxW/2), boxY+int(boxH/2)))
pg.draw.aaline(
game.screen,
"white",
(boxX+int(boxW/2)+boxD*sc(thetaX), boxY-int(boxH/2)-boxD*sc(thetaY)),
(boxX+int(boxW/2)+boxD*sc(thetaX), boxY+int(boxH/2)-boxD*sc(thetaY))
)
game.tick()
def main():
width, height = 300, 300
refresh_rate = getattr(win32api.EnumDisplaySettings(win32api.EnumDisplayDevices().DeviceName, -1), "DisplayFrequency")
game = Game(width, height, refresh_rate)
vertList = [(2, 3, 1),
(2, 3, -1),
(2, -3, 1),
(2, -3, -1),
(-2, 3, 1),
(-2, 3, -1),
(-2, -3, 1),
(-2, -3, -1)]
connectList = [(0, 1), (1, 3), (3, 2), (2, 0),
(4, 5), (5, 7), (7, 6), (6, 4),
(0, 4), (1, 5), (2, 6), (3, 7)]
clock = pg.time.Clock()
loop(game)
if __name__ == "__main__":
main()
pg.quit()