-
Notifications
You must be signed in to change notification settings - Fork 2
/
CaveWand.py
225 lines (193 loc) · 5.54 KB
/
CaveWand.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from math import *
from euclid import *
from omega import *
from cyclops import *
from omegaToolkit import *
cam = getDefaultCamera()
cam.setControllerEnabled(False)
#cam.setNearFarZ(1,10)
flagZoomIn = False
flagZoomOut = False
flagRotateUpDown = 0.0
flagRotateLeftRight = 0.0
speed = 100
omegaRate = 2
menuShow = False
################################################
#
# Testing free fly for plane
#
freeFly = False
wandPos = None
wandOrientation = None
anchorPos = None
anchorOrientation = None
scale = 10.0
test = BoxShape.create(4, 4, 4)
test.setEffect("colored -e #ff000044 -t")
box = BoxShape.create(4, 4, 4)
box.setEffect("colored -e #00ff0088 -t")
scene = SceneNode.create("ajdkf")
scene.addChild(test)
scene.addChild(box)
scene.setPosition(Vector3(0,0,-20))
################################################
mm = MenuManager.createAndInitialize()
appMenu = mm.createMenu("contolPanel")
appMenu.addButton("hello world", "print 'hello world!'")
def onUpdate(frame, t, dt):
global speed
global cam
global omegaRate
global scene
global flagRotateUpDown
global flagRotateLeftRight
################################################
#
# Testing free fly for plane
#
global freeFly
global wandPos
global wandOrientation
################################################
if(flagRotateUpDown):
scene.rotate(Vector3(1,0,0), flagRotateUpDown*omegaRate*dt, Space.World)
if(flagRotateLeftRight):
scene.rotate(Vector3(0,1,0), flagRotateLeftRight*omegaRate*dt, Space.World)
def onEvent():
global cam
global appMenu
global flagZoomIn
global flagZoomOut
global flagRotateUpDown
global flagRotateLeftRight
global menuShow
global freeFly
e = getEvent()
type = e.getServiceType()
if(type == ServiceType.Pointer or type == ServiceType.Wand or type == ServiceType.Keyboard):
# Button mappings are different when using wand or mouse
################################################
#
# Testing free fly for plane
#
global freeFly
global wandPos
global wandOrientation
global anchorPos
global anchorOrientation
global scene
global box
global scale
if(type == ServiceType.Pointer):
confirmButton = EventFlags.Button2
quitButton = EventFlags.Button1
if(e.isButtonDown(quitButton)):
freeFly = True
anchorPos = e.getPosition()
if(e.isButtonUp(quitButton)):
freeFly = False
wandPos = None
anchorPos = None
if(freeFly):
wandPos = e.getPosition()
x = wandPos.x - anchorPos.x
y = wandPos.y - anchorPos.y
print x, "X" , y
box.translate( float(x)/100, float(y)/100, 0, Space.World)
print e.getOrientation()
anchorPos = wandPos
################################################
if(type == ServiceType.Keyboard):
confirmButton = EventFlags.Button2
quitButton = EventFlags.Button1
lowHigh = 0
leftRight = 0
forward = ord('w')
down = ord('s')
low = ord('i')
high = ord('k')
turnleft = ord('j')
turnright = ord('l')
climb = ord('a')
descend = ord('d')
flagH = False
flagV = False
if(e.isKeyDown( forward)):
flagZoomIn = True
if(e.isKeyDown( down )):
flagZoomOut = True
if(e.isKeyUp( forward)):
flagZoomIn = False
if(e.isKeyUp( down )):
flagZoomOut = False
if(e.isKeyDown( low)):
lowHigh = 0.5
flagV = True
if(e.isKeyDown( high )):
lowHigh = -0.5
flagV = True
if(e.isKeyDown( turnleft)):
leftRight = 0.5
flagH = True
if(e.isKeyDown( turnright )):
leftRight = -0.5
flagH = True
flagRotateLeftRight = leftRight
flagRotateUpDown = lowHigh
if(type == ServiceType.Wand):
confirmButton = EventFlags.Button2
quitButton = EventFlags.Button3
forward = EventFlags.ButtonUp
down = EventFlags.ButtonDown
climb = EventFlags.ButtonLeft
descend = EventFlags.ButtonRight
pick = EventFlags.Button5
move = EventFlags.Button7
lowHigh = e.getAxis(1)
leftRight = -e.getAxis(0)
if(e.isButtonDown(confirmButton) and not menuShow):
appMenu.getContainer().setPosition(e.getPosition())
appMenu.show()
appMenu.placeOnWand(e)
menuShow = True
if(e.isButtonDown(quitButton) and menuShow):
appMenu.hide()
menuShow = False
if(e.isButtonDown( forward)):
flagZoomIn = True
if(e.isButtonDown( down )):
flagZoomOut = True
if(e.isButtonDown( climb)):
print "up"
if(e.isButtonDown( descend )):
print "down"
if(e.isButtonUp( forward)):
flagZoomIn = False
if(e.isButtonUp( down )):
flagZoomOut = False
flagRotateLeftRight = leftRight
flagRotateUpDown = lowHigh
if(e.isButtonDown(pick)):
freeFly = True
anchorPos = e.getPosition()
anchorOrientation = e.getOrientation()
print anchorPos
print anchorOrientation
if(e.isButtonUp(pick)):
freeFly = False
wandPos = None
anchorPos = None
if(freeFly):
wandPos = e.getPosition()
wandOrientation = e.getOrientation()
x = wandPos.x - anchorPos.x
y = wandPos.y - anchorPos.y
z = wandPos.z - anchorPos.z
box.translate( float(x)*scale, float(y)*scale, float(z)*scale, Space.World)
I box.setOrientation( box.getOrientation() * scene.getOrientation().conjugated() * anchorOrientation.conjugated() * wandOrientation * scene.getOrientation() )
anchorPos = wandPos
anchorOrientation = wandOrientation
e.setProcessed()
setEventFunction(onEvent)
setUpdateFunction(onUpdate)