-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
130 lines (99 loc) · 3.37 KB
/
main.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
import tdmath
import math
from tkinter import *
rotateObjZ = 0
rotateObjY = 0
rotateObjX = 0
rotateCamZ = math.pi/2
rotateCamY = 0
rotateCamX = 0
shape = [(0,-20,0,1),(20,-20,0,1),(10,-10,0,1),(0,-20,0,1),(0,-10,0,1),(20,-10,0,1)
,(0,0,0,1),(20,0,0,1),(0,0,0,1),(20,10,0,1),(0,20,0,1)]
def RotObjX():
global rotateObjX
rotateObjX = rotateObjX + (math.pi/40)
if rotateObjX > (math.pi * 2):
rotateObjX = rotateObjX - (math.pi * 2)
Draw3D()
def RotObjY():
global rotateObjY
rotateObjY = rotateObjY + (math.pi/40)
if rotateObjY > (math.pi * 2):
rotateObjY = rotateObjY - (math.pi * 2)
Draw3D()
def RotObjZ():
global rotateObjZ
rotateObjZ = rotateObjZ + (math.pi/40)
if rotateObjZ > (math.pi * 2):
rotateObjZ = rotateObjZ - (math.pi * 2)
Draw3D()
def RotCamX():
global rotateCamX
rotateCamX = rotateCamX + (math.pi/40)
if rotateCamX > (math.pi * 2):
rotateCamX = rotateCamX - (math.pi * 2)
Draw3D()
def RotCamY():
global rotateCamY
rotateCamY = rotateCamY + (math.pi/40)
if rotateCamY > (math.pi * 2):
rotateCamY = rotateCamY - (math.pi * 2)
Draw3D()
def RotCamZ():
global rotateCamZ
rotateCamZ = rotateCamZ + (math.pi/40)
if rotateCamZ > (math.pi * 2):
rotateCamZ = rotateCamZ - (math.pi * 2)
Draw3D()
def Refresher():
RotObjX()
RotCamZ()
root.after(100, Refresher)
def Draw3D():
global rotateObjX
global rotateObjY
global rotateObjZ
global rotateCamX
global rotateCamY
global rotateCamZ
draw.delete(ALL)
draw.configure(background='white')
# Transform objects
matrix = tdmath.axisRotation(shape,rotateObjX,rotateObjY,rotateObjZ) # Rotate Shape
# Objects to world
matrix = tdmath.translationMatrix(matrix,200,200,50) # Put in world
# Camera view perspective
matrix = tdmath.projectionMatrix(50,200,200,0,rotateCamX,rotateCamY,rotateCamZ,matrix) # Camera angle xyz xyzrotation world
# Adapt to screen
matrix = tdmath.translationMatrix(matrix,200,200,0)
if len(matrix) > 0:
polyg = []
for point in matrix:
polyg.append(point[0])
polyg.append(point[1])
draw.create_polygon(polyg,fill='',outline='black')
else:
pass
matrix = []
root = Tk()
root.title("3D_Test")
var1 = StringVar()
label2 = Label(root, text="3D", bg="black", fg="white")
draw = Canvas(root, width=400, height=400)
button1 = Button(root, text="ObjX", command=RotObjX)
button2 = Button(root, text="ObjY", command=RotObjY)
button3 = Button(root, text="ObjZ", command=RotObjZ)
button4 = Button(root, text="CamX", command=RotCamX)
button5 = Button(root, text="CamY", command=RotCamY)
button6 = Button(root, text="CamZ", command=RotCamZ)
label2.grid(row=0, column=0, columnspan=2, sticky=W+E)
draw.grid(row=1, column=0, columnspan=2, sticky=W+E)
button1.grid(row=2, column=0, columnspan=1, sticky=W+E)
button2.grid(row=3, column=0, columnspan=1, sticky=W+E)
button3.grid(row=4, column=0, columnspan=1, sticky=W+E)
button4.grid(row=2, column=1, columnspan=2, sticky=W+E)
button5.grid(row=3, column=1, columnspan=2, sticky=W+E)
button6.grid(row=4, column=1, columnspan=2, sticky=W+E)
Draw3D()
Refresher()
root.mainloop()