Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.82 KB | None | 0 0
  1. <Scene base_name="linedrag" name_space="Scene" name_suffix="0" persistency="666"><Objects><Object base_name="Root" name_space="__global__" name_suffix="0" persistency="666" pickable="0" type="Object" visible="1"><Object ambient="0.3 0.3 0.3 1" base_name="light" beacon="Headlight_beacon" diffuse="1 1 1 1" lightType="point" name_space="__global__" name_suffix="0" on="1" persistency="666" pickable="0" shadow="0" shadowColor="0.1 0.1 0.1 1" shadowMapRes="2048" specular="0.1 0.1 0.1 1" type="Light" visible="1"><Object accept_root="1" aspect="1" at="0 0 1" at_dir="0" base_name="Default" far="512" fov="1.0472" from="5.69698 4.41176 0.101096" name_space="__global__" name_suffix="0" near="0.1" orthoSize="100" persistency="666" pickable="0" scale="1 1 1" type="Camera" up="0 1 0" visible="1"><Object at="0 0 -1" at_dir="0" base_name="Headlight_beacon" from="0 0 0" light="light" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="LightBeacon" up="0 1 0" visible="1"><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="0 0 -1" at_dir="0" base_name="TMP_GEO_SETUP_NAME" from="0 0 0" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" sourceparam="" sourcetype="0" type="Geometry" up="0 1 0" visible="1"><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="9.64428 -2.08119 -7.44131" at_dir="0" base_name="TMP_GEO_SETUP_NAME" from="9.01397 -2.27205 -6.68878" name_space="__global__" name_suffix="1" persistency="666" pickable="1" scale="5 5 5" sourceparam="" sourcetype="0" type="Geometry" up="-0.421161 0.898341 -0.124927" visible="1"><Object at="0 0 -1" at_dir="0" base_name="Rigged Hand_dae.dae" from="0 0 0" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="0 1 0" visible="1"><Object base_name="Scene" name_space="__global__" name_suffix="0" persistency="666" pickable="0" type="Object" visible="1"><Object base_name="OpenSG_AmbientLight" name_space="__global__" name_suffix="0" persistency="666" pickable="0" type="ChunkOverrideGroup" visible="1"><Object base_name="Point" name_space="__global__" name_suffix="1" persistency="666" pickable="0" type="PointLight" visible="1"><Object at="0 0.0245625 -1" at_dir="0" base_name="Armature" from="0 0.0245625 0" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="0 1 0" visible="1"><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="0 0 -1" at_dir="0" base_name="Cube_005" from="0 0 0" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="0 1 0" visible="1"><Object base_name="Armature" name_space="__global__" name_suffix="2" persistency="666" pickable="0" type="Object" visible="1"><Object base_name="Armature" name_space="__global__" name_suffix="1" persistency="666" pickable="0" type="SkinnedGeometry" visible="1"/></Object><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="0 0 -1" at_dir="0" base_name="Cube_000" from="0 0 0" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="0 1 0" visible="1"><Object base_name="Armature" name_space="__global__" name_suffix="4" persistency="666" pickable="0" type="Object" visible="1"><Object base_name="Armature" name_space="__global__" name_suffix="3" persistency="666" pickable="0" type="SkinnedGeometry" visible="1"/></Object><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="0.33982 0.278983 1.94723" at_dir="0" base_name="Hemi" from="0.495596 0.785061 2.79554" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="-0.030777 0.860857 -0.507916" visible="1"><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><Object at="0.0827517 0.57086 -0.209598" at_dir="0" base_name="Point" from="0.0827517 0.57086 0.790402" name_space="__global__" name_suffix="0" persistency="666" pickable="0" scale="1 1 1" type="Transform" up="0 1 0" visible="1"><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object></Object></Object></Object><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object><constraint active="1" cR="0 1 0" cR_local="0" cR_mode="0" cT="0 1 0" cT_local="0" cT_mode="0" persistency="666"/></Object></Object><Object base_name="None" name_space="__global__" name_suffix="5" persistency="666" pickable="0" type="Object" visible="1"/></Object></Objects><Rendering deferred_rendering="0" frustum_culling="1" fxaa="0" hmdd="0" marker="0" occlusion_culling="0" persistency="666" ssao="0" ssao_kernel="4" ssao_noise="4" ssao_radius="0.02" two_sided="1"/><Scripts persistency="666"><Script base_name="ControlHandle" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  2. import VR
  3.  
  4. VR.controlHandle = VR.Geometry("controlHandle")
  5. VR.controlHandle.setPrimitive("Sphere .1")
  6. VR.controlHandle.setPickable(1)
  7. VR.controlHandle.setFrom([0,0,0])
  8. VR.scene.addChild(VR.controlHandle)
  9.  
  10. # Method to properly get center position coordinates of the
  11. # handle sphere, as getAt() does not return the sphere center.
  12. def getControlHandleCenter():
  13. return VR.controlHandle.getWorldFrom()
  14. #chandle = VR.controlHandle.getAt()
  15. #return [chandle[0], chandle[1], chandle[2] + 1]
  16.  
  17. VR.getControlHandleCenter = getControlHandleCenter
  18. </core></Script><Script base_name="Hand" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  19. import VR
  20.  
  21. #hand = VR.loadGeometry('/home/administrator/Desktop/RiggedHand_dae.dae')
  22. hand = VR.loadGeometry('hand.dae')
  23. #hand = VR.loadGeometry('/home/administrator/Projects/Cyberglove/usecases/linedrag/RiggedHand_dae.dae', preset = 'COLLADA')
  24. hand.setWorldFrom([15,5,-5])
  25. hand.setWorldUp([1,0,0])
  26. hand.translate([-6, -7, 0])
  27. hand.setPickable(True)
  28. hand.setPersistency(3)
  29. hand.setScale(9,9,9)
  30. hand.setVisible(False)
  31.  
  32. VR.scene.addChild(hand)
  33. VR.hand = hand
  34.  
  35.  
  36. </core></Script><Script base_name="Labels" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  37. import VR
  38.  
  39. plane = VR.Geometry()
  40. plane.setPrimitive("Plane 3 3 1 1")
  41.  
  42. plane.setColor("white")
  43.  
  44. sprite = VR.Sprite()
  45. sprite.setText("Welcome to Linedrag.")
  46. sprite.setSize(2,0.2)
  47.  
  48. cam = VR.find("Default")
  49. textpos = [
  50. cam.getWorldFrom()[0] + 3 * cam.getWorldDir()[0],
  51. cam.getWorldFrom()[1] + 3 * cam.getWorldDir()[1],
  52. cam.getWorldFrom()[2] + 3 * cam.getWorldDir()[2],
  53. ]
  54.  
  55. plane.setFrom(textpos)
  56. plane.setAt([0,0,1])
  57. sprite.setAt(plane.getAt())
  58. sprite.setFrom([plane.getFrom()[0], plane.getFrom()[1], plane.getFrom()[2]])
  59. sprite.setUp(VR.find("Default").getUp())
  60.  
  61. VR.scene.addChild(plane)
  62. VR.scene.addChild(sprite)
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. </core></Script><Script base_name="Line" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  83. import VR
  84.  
  85. lineHandles = [
  86. #[0, 0, 0],
  87. #[2, 0, 0],
  88. #[2, 0, 2],
  89. #[4, 0, 2],
  90. #[5, 0, 3],
  91. #[5, 0, 4],
  92. #[7, 0, 4],
  93. #[8, 0, 5],
  94. #[8, 0, 6.5],
  95. [1,0,1],
  96. [1.2, 0, .8],
  97. [1.2, 0, .8],
  98. [1.2, 0, .6],
  99. [1.0, 0, .5],
  100. [1.1, 0, .3],
  101. [1.3, 0, .3],
  102. [1.5, 0, .4],
  103. [1.5, 0, .6],
  104. [1.5, 0, .8],
  105. [1.3, 0, .9],
  106. [1.2, 0, 1.1],
  107. [1.3, 0, 1.3],
  108. [1.5, 0, 1.4],
  109. [1.7, 0, 1.3],
  110. [1.9, 0, 1.2],
  111. [2.1, 0, 1.3],
  112. [2.0, 0, 1.5],
  113. [1.9, 0, 1.7],
  114. [1.7, 0, 1.8],
  115. [1.5, 0, 1.7],
  116. [1.3, 0, 1.5],
  117. [1.1, 0, 1.4],
  118. [.9, 0, 1.4],
  119. [.7, 0, 1.5],
  120. [.7, 0, 1.1],
  121. [.8, 0, .5],
  122. [.7, 0, .4],
  123. [.5, 0, .4],
  124. [.5, 0, .3],
  125. [.4, 0, .2],
  126. [.2, 0, .2],
  127. [.2, 0, .0],
  128. [.0, 0, .0]
  129. ]
  130.  
  131. lineCount = (len(lineHandles) / 2)
  132.  
  133. VR.ptool = VR.Pathtool()
  134. VR.paths = [None] * lineCount
  135.  
  136. for i,N in enumerate(VR.paths):
  137. VR.paths[i] = VR.ptool.newPath(None, VR.scene)
  138. VR.ptool.extrude(None, VR.paths[i])
  139. VR.ptool.setVisuals(False, True)
  140. handles = VR.ptool.getHandles(VR.paths[i])
  141. handles[0].setFrom(lineHandles[i*2 + 0])
  142. handles[1].setFrom(lineHandles[i*2 + 1])
  143. if i != lineCount - 1:
  144. handles[2].setFrom(lineHandles[i*2 + 2])
  145. VR.ptool.update()
  146.  
  147. # Print debugging circles on the line.
  148. for linePath in VR.paths:
  149. VR.testCircles(linePath.getPositions())
  150. </core></Script><Script base_name="Plane" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  151. import VR
  152.  
  153. planes = [
  154. {
  155. "x":.9,
  156. "y": 0,
  157. "z": 1.4,
  158. "angle": 5,
  159. "config": [
  160. {
  161. "key1": 0,
  162. "key2": 1,
  163. "key3": 0,
  164. "key4": 0,
  165. "slider1": False,
  166. "slider2": 0,
  167. "slider3": 0,
  168. "slider4": 0,
  169. "sliderX": 0,
  170. "sliderY": 0
  171. },
  172. {
  173. "key1": 0,
  174. "key2": 0,
  175. "key3": 0,
  176. "key4": 1,
  177. "slider1": False,
  178. "slider2": 0,
  179. "slider3": 0,
  180. "slider4": 0,
  181. "sliderX": 0,
  182. "sliderY": 0
  183. },
  184. {
  185. "key1": 1,
  186. "key2": 1,
  187. "key3": 0,
  188. "key4": 0,
  189. "slider1": False,
  190. "slider2": 0,
  191. "slider3": 0,
  192. "slider4": 0,
  193. "sliderX": 0,
  194. "sliderY": 0
  195. }
  196. ]
  197. },
  198. {
  199. "x": 2.1,
  200. "y": 0,
  201. "z": 1.3,
  202. "angle": 5,
  203. "config": [
  204. {
  205. "key1": 0,
  206. "key2": 1,
  207. "key3": 0,
  208. "key4": 0,
  209. "slider1": False,
  210. "slider2": 0,
  211. "slider3": 0,
  212. "slider4": 0,
  213. "sliderX": 0,
  214. "sliderY": 0
  215. },
  216. {
  217. "key1": 0,
  218. "key2": 0,
  219. "key3": 0,
  220. "key4": 1,
  221. "slider1": False,
  222. "slider2": 0,
  223. "slider3": 0,
  224. "slider4": 0,
  225. "sliderX": 0,
  226. "sliderY": 0
  227. },
  228. {
  229. "key1": 1,
  230. "key2": 1,
  231. "key3": 0,
  232. "key4": 0,
  233. "slider1": False,
  234. "slider2": 0,
  235. "slider3": 0,
  236. "slider4": 0,
  237. "sliderX": 0,
  238. "sliderY": 0
  239. }
  240. ]
  241. },
  242. {
  243. "x": .8,
  244. "y": 0,
  245. "z": .5,
  246. "angle": 5,
  247. "config": [
  248. {
  249. "key1": 0,
  250. "key2": 1,
  251. "key3": 0,
  252. "key4": 0,
  253. "slider1": False,
  254. "slider2": 0,
  255. "slider3": 0,
  256. "slider4": 0,
  257. "sliderX": 0,
  258. "sliderY": 0
  259. },
  260. {
  261. "key1": 0,
  262. "key2": 0,
  263. "key3": 0,
  264. "key4": 1,
  265. "slider1": False,
  266. "slider2": 0,
  267. "slider3": 0,
  268. "slider4": 0,
  269. "sliderX": 0,
  270. "sliderY": 0
  271. },
  272. {
  273. "key1": 1,
  274. "key2": 1,
  275. "key3": 0,
  276. "key4": 0,
  277. "slider1": False,
  278. "slider2": 0,
  279. "slider3": 0,
  280. "slider4": 0,
  281. "sliderX": 0,
  282. "sliderY": 0
  283. }
  284. ]
  285. }
  286. ]
  287.  
  288. VR.planes = []
  289. VR.challenges = []
  290.  
  291. for plane in planes:
  292. planeGeo = VR.Geometry("plane" + str(plane["x"]) + str(plane["y"]) + str(plane["z"]))
  293. planeGeo.setPrimitive("Plane .1 .1 12")
  294. planeGeo.setFrom([plane["x"], plane["y"], plane["z"]])
  295. planeGeo.setColor("blue")
  296. #planeGeo.setPose(5, 5, 5) #pos, dir, up
  297. #def getPlaneCenter(): return [plane["x"], plane["y"], plane["z"]]
  298. #planeGeo.getPlaneCenter = getPlaneCenter
  299. VR.scene.addChild(planeGeo)
  300.  
  301. VR.challenges.append({
  302. "done": False,
  303. "plane": planeGeo,
  304. "configuration": plane["config"]
  305. })
  306.  
  307.  
  308.  
  309.  
  310. # def planeIntersection():
  311. # return VR.getIntersected()
  312. #
  313. # VR.planeIntersection = planeIntersection
  314. </core></Script><Script base_name="ShowTime" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  315. import VR
  316.  
  317. print VR.timeCounter
  318.  
  319. if not VR.touchedHandle:
  320. return
  321.  
  322. if not hasattr(VR, 'spriteTime'):
  323. VR.spriteTime = VR.Sprite()
  324. VR.spriteTime.setSize(10,1)
  325. VR.scene.addChild(spriteTime)
  326. plane = VR.Geometry()
  327. plane.setPrimitive("Plane 0.5 0 1 1")
  328. plane.setVisible(False)
  329. VR.scene.addChild(plane)
  330.  
  331. VR.timeCounter += 50
  332.  
  333. VR.spriteTime.setText(str(VR.timeCounter / 1000.0) + " seconds")
  334. cam = VR.find("Default")
  335. textpos = [
  336. cam.getWorldFrom()[0] + 10 * cam.getWorldDir()[0]-1,
  337. cam.getWorldFrom()[1] + 10 * cam.getWorldDir()[1],
  338. cam.getWorldFrom()[2] + 10 * cam.getWorldDir()[2]+5,
  339. ]
  340.  
  341. plane.setFrom(textpos)
  342. plane.setAt([0,0,1])
  343. VR.spriteTime.setAt([0,0,1])
  344. #sprite.setFrom([textpos[0],textpos[1]+7, textpos[2]])
  345. VR.spriteTime.setFrom(plane.getFrom())
  346. #sprite.setUp(VR.find("Default").getUp())
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. </core></Script><Script base_name="TESTING" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  359. import VR
  360.  
  361. #for challenge in VR.challenges:
  362. # challenge["done"] = False
  363. # challenge["plane"].setColor("blue")
  364.  
  365. annotation = VR.AnnotationEngine()
  366. #annotation.setBackground([1, 1, 1, 1])
  367. #annotation.setColor([0, 0, 0, 1])
  368. #annotation.setSize(100)
  369.  
  370. plane = VR.Geometry()
  371. plane.setPrimitive("Plane 3 3 1 1")
  372. VR.scene.addChild(plane)
  373.  
  374. #plane.setFrom([0,2,0])
  375. #plane.setAt([0,0,1])
  376. plane.setColor("white")
  377.  
  378. sprite = VR.Sprite()
  379. sprite.setText("test tet sdasldldl")
  380. sprite.setSize(1,0.1)
  381.  
  382. #sprite.setLabel("test text", 1.0)
  383. VR.scene.addChild(sprite)
  384. cam = VR.find("Default")
  385. textpos = [
  386. cam.getWorldFrom()[0] + 3 * cam.getWorldDir()[0],
  387. cam.getWorldFrom()[1] + 3 * cam.getWorldDir()[1],
  388. cam.getWorldFrom()[2] + 3 * cam.getWorldDir()[2],
  389. ]
  390. an = annotation.set(0, textpos ,"Test text blaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddfaaaaaaaaaaaaaa")
  391. plane.setFrom(textpos)
  392. plane.setAt([0,0,1])
  393. sprite.setFrom([plane.getFrom()[0], plane.getFrom()[1], plane.getFrom()[2]-0.01])
  394. sprite.setAt(plane.getAt())
  395.  
  396. print an
  397. annotation.setFrom(textpos)
  398. #annotation.setScreensize(True)
  399. #annotation.setVisible(True)
  400. #VR.scene.addChild(annotation)
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415. </core></Script><Script base_name="challenge" group="gamelogic" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  416. import VR
  417. import time
  418. from random import randint
  419. import sys
  420.  
  421.  
  422. #VR.hand.setVisible(True)
  423.  
  424. configuration = {}
  425.  
  426. configuration["key1"] = 1
  427. configuration["key2"] = 1
  428. configuration["key3"] = 0
  429. configuration["key4"] = 0
  430. configuration["slider1"] = False
  431. configuration["slider2"] = 0
  432. configuration["slider3"] = 0
  433. configuration["slider4"] = 0
  434. configuration["sliderX"] = 0
  435. configuration["sliderY"] = 0
  436.  
  437. #configuration = [0] * 10
  438. givenConfig = [
  439. configuration["key1"],
  440. configuration["key2"],
  441. configuration["key3"],
  442. configuration["key4"],
  443. configuration["slider1"],
  444. configuration["slider2"],
  445. configuration["slider3"],
  446. configuration["slider4"],
  447. configuration["sliderX"],
  448. configuration["sliderY"]
  449. ]
  450.  
  451. print "time" + str(time.time())
  452.  
  453.  
  454.  
  455. #VR.hand.setVisible(True)
  456. VR.isChallenge = False
  457.  
  458.  
  459. </core></Script><Script base_name="checkControlHandle" group="gamelogic" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  460. import VR
  461. import math
  462.  
  463. if not hasattr(VR, 'hasInitialized'): return
  464.  
  465. if not VR.controlHandle.getFrom() == [0,0,0]:
  466. VR.touchedHandle = True
  467.  
  468. def euclideanDistance(vec1, vec2, dimension=3):
  469. sum = 0
  470. for i in range(0, dimension):
  471. sum += math.pow(vec1[i] - vec2[i], 2)
  472. return math.sqrt(sum)
  473.  
  474. VR.euclideanDistance = euclideanDistance
  475.  
  476. # Bring handle into line plane
  477. #pos = VR.controlHandle.getWorldFrom()
  478. #VR.controlHandle.setWorldFrom(pos[0], 0, pos[2])
  479.  
  480. # Position of handle (draggable sphere).
  481. chandle = VR.getControlHandleCenter()
  482.  
  483. # After the for loop, this will contain the
  484. # minimal distance between line and handle.
  485. minDist = 10000
  486.  
  487. # Maximum distance between handle and line for
  488. # for the handle to touch the line.
  489. eps = .1
  490.  
  491. for linePath in VR.paths:
  492. for idx, node in enumerate(linePath.getPositions()):
  493. dist = euclideanDistance(node, chandle)
  494. minDist = dist if dist < minDist else minDist
  495.  
  496. # Set handle color to green if touching the line,
  497. # red otherwise.
  498. if (minDist < eps and not VR.isChallenge):
  499. VR.controlHandle.setColor("green")
  500.  
  501. elif not VR.isChallenge:
  502. if (VR.counter == 0):
  503. #VR.controlHandle.setColor("yellow")
  504. print "looser"
  505. VR.counter = 100
  506. else:
  507. VR.controlHandle.setColor("red")
  508. VR.counter = VR.counter - 1
  509. else:
  510. # When challenge is running, change the handles color according to the
  511. # remaining time
  512. m = VR.Material('challengeMaterial')
  513. m.setDiffuse([
  514. (VR.timeInChallenge / (VR.maxChallengeTime * 1.0)),
  515. (1 - VR.timeInChallenge / (VR.maxChallengeTime * 1.0)),
  516. 0
  517. ])
  518. VR.controlHandle.setMaterial(m)
  519.  
  520. oldPos = VR.controlHandle.getWorldFrom()
  521. VR.controlHandle.setWorldFrom([oldPos[0], 0, oldPos[2]])
  522. </core><trig type="on_timeout" dev="" state="Pressed" param="10" key="0" base_name="trigger" name_space="__global__" name_suffix="0" persistency="666"/></Script><Script base_name="checkPlane" group="gamelogic" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  523. import VR
  524. import time
  525. from random import randint
  526. import sys
  527.  
  528.  
  529.  
  530. if not hasattr(VR, 'hasInitialized'): return
  531.  
  532. def wait_until(checkHand, configuration, timeout = randint(5,10), period=0.1):
  533. mustend = time.time() + timeout
  534. while time.time() < mustend:
  535. print str(time.time()) + ", " + str(mustend)
  536. if checkHand(configuration):
  537. VR.plane.setColor("green")
  538. print "you won!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  539. VR.hasWon = True
  540. return True
  541. print "waiting"
  542. time.sleep(period)
  543. print "nothing found"
  544. VR.plane.setColor("red")
  545. return False
  546.  
  547. def checkHand(configuration):
  548. #if not hasattr(configuration, "key1"): return False
  549.  
  550. if configuration["key1"] and configuration["key1"] != getConfiguration(glove)[0]:
  551. return False
  552. if configuration["key2"] and configuration["key2"] != getConfiguration(glove)[1]:
  553. return False
  554. if configuration["key3"] and configuration["key3"] != getConfiguration(glove)[2]:
  555. return False
  556. if configuration["key4"] and configuration["key4"] != getConfiguration(glove)[3]:
  557. return False
  558. if configuration["slider1"] and configuration["slider1"] != getConfiguration(glove)[4]:
  559. return False
  560. if configuration["slider2"] and configuration["slider2"] != getConfiguration(glove)[5]:
  561. return False
  562. if configuration["slider3"] and configuration["slider3"] != getConfiguration(glove)[6]:
  563. return False
  564. if configuration["slider4"] and configuration["slider4"] != getConfiguration(glove)[7]:
  565. return False
  566. if configuration["sliderX"] and configuration["sliderX"] != getConfiguration(glove)[8]:
  567. return False
  568. if configuration["sliderY"] and configuration["sliderY"] != getConfiguration(glove)[9]:
  569. return False
  570. print True
  571. return True
  572.  
  573. def getConfiguration(glove):
  574. #if not hasattr(glove, 'getKeyState'): return {}
  575.  
  576. obj = {}
  577. obj["key1"] = glove.getKeyState(key1)
  578. obj["key2"] = glove.getKeyState(key2)
  579. obj["key3"] = glove.getKeyState(key3)
  580. obj["key4"] = glove.getKeyState(key4)
  581.  
  582. obj["slider1"] = glove.getSlider(slider1)
  583. obj["slider2"] = glove.getSlider(slider2)
  584. obj["slider3"] = glove.getSlider(slider3)
  585. obj["slider4"] = glove.getSlider(slider4)
  586.  
  587. obj["sliderX"] = glove.getSlider(sliderX)
  588. obj["sliderY"] = glove.getSlider(sliderY)
  589. config = [obj["key1"], obj["key2"], obj["key3"], obj["key4"], obj["slider1"],
  590. obj["slider2"], obj["slider3"], obj["slider4"]]
  591. #return [0] * 10
  592. return config
  593.  
  594. #if VR.hasWon: # or VR.isChallenge:
  595. # return
  596.  
  597. epsilon = .15
  598.  
  599. glove = VR.find('vrpn_device')
  600.  
  601.  
  602. key1 = 0 #index finger
  603. key2 = 1 #middle finger
  604. key3 = 2 #ring finger
  605. key4 = 3 #little finger
  606.  
  607. slider1 = 100 #index finger
  608. slider2 = 200 #middle finger
  609. slider3 = 300 #ring finger
  610. slider4 = 400 #small finger
  611.  
  612. sliderX = 104 #cursor x direction
  613. sliderY = 105 #cursor y direction
  614.  
  615. print getConfiguration(glove)
  616.  
  617. for challenge in VR.challenges:
  618. if challenge["done"]:
  619. continue
  620. #print VR.timeInChallenge
  621.  
  622. posHandle = VR.getControlHandleCenter()
  623. posPlane = challenge["plane"].getWorldFrom()
  624.  
  625. distance = VR.euclideanDistance(posHandle, posPlane)
  626.  
  627. if (distance < epsilon) and (not VR.isChallenge):
  628. # First iteration, starting challenge
  629. VR.isChallenge = True
  630. VR.timeInChallenge = 0
  631. print "plane"
  632. VR.controlHandle.setColor("black")
  633. VR.controlHandle.setPickable(-1)
  634. VR.challengePos = VR.controlHandle.getAt()
  635.  
  636. # Show hand
  637. cam = VR.find("Default")
  638. handpos = [
  639. cam.getWorldFrom()[0] + 6 * cam.getWorldDir()[0],
  640. cam.getWorldFrom()[1] + 6 * cam.getWorldDir()[1],
  641. cam.getWorldFrom()[2] + 6 * cam.getWorldDir()[2],
  642. ]
  643. VR.hand.setVisible(True)
  644. VR.hand.setFrom(handpos)
  645. VR.hand.setAt(cam.getWorldFrom())
  646.  
  647. #VR.find('Default').setAt(posPlane)
  648.  
  649. elif distance < epsilon and VR.isChallenge:
  650. # challenge is already started, check
  651. VR.timeInChallenge += 20
  652. VR.controlHandle.setAt(VR.challengePos)
  653.  
  654. print VR.challengePart
  655. print "of"
  656. print len(challenge["configuration"])
  657.  
  658. if VR.timeInChallenge > VR.maxChallengeTime:
  659. challenge["plane"].setColor("red")
  660. print "you suck"
  661. challenge["done"] = True
  662. VR.isChallenge = False
  663. VR.controlHandle.setPickable(1)
  664. VR.hand.setVisible(False)
  665. return True
  666.  
  667.  
  668. #elif VR.challengePart < len(challenge["configuration"] and checkHand(challenge["configuration"][VR.challengePart]):
  669. elif checkHand(challenge["configuration"][VR.challengePart]):
  670. VR.challengePart += 1
  671. if VR.challengePart >= len(challenge["configuration"]):
  672. # challenge won, no more challenge part available
  673. VR.challengePart = 0
  674. challenge["plane"].setColor("green")
  675. print "you won!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  676. challenge["done"] = True
  677. VR.isChallenge = False
  678. VR.hasWon = True
  679. VR.controlHandle.setPickable(1)
  680. VR.hand.setVisible(False)
  681. return True
  682. else:
  683. # challenge won, more parts to come
  684. VR.timeInChallenge = 0
  685. print "next challenge"
  686. # TODO next hand
  687.  
  688.  
  689.  
  690. #else:
  691. # VR.isChallenge = False
  692.  
  693.  
  694.  
  695.  
  696. #wait_until(checkHand, 5)
  697. </core><trig type="on_timeout" dev="" state="Pressed" param="20000" key="0" base_name="trigger" name_space="__global__" name_suffix="0" persistency="666"/></Script><Script base_name="controlHandleDrag" group="gamelogic" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  698. import VR
  699.  
  700. if not hasattr(VR, 'hasInitialized'): return
  701.  
  702. glove = VR.find('vrpn_device')
  703.  
  704. b = VR.find('ART_tracker.1')
  705. glove.setBeacon(b)
  706. b.findAll('av_ray')[0].show()
  707.  
  708. #for i in range(0, 255):
  709. # key = glove.getKeyState(i)
  710. # if key != -1:
  711. # print "" + str(i) + " is " + str(key)
  712.  
  713. def startDrag():
  714. if glove.intersect(VR.getRoot()):
  715. VR.isDragging = True
  716. print "Attempting to start dragging, found intersecting object(s)."
  717. obj = glove.getIntersected()
  718. print "Intersecting Object:" + str(obj)
  719. glove.drag(obj)
  720. else:
  721. print "Attempting to start dragging, but no intersecting object."
  722.  
  723. def stopDrag():
  724. VR.isDragging = False
  725. glove.drop()
  726.  
  727. #print glove.getSlider(100)
  728.  
  729.  
  730. if hasattr(glove, 'getSlider') and hasattr(glove, 'setBeacon'):
  731. num = glove.getSlider(100) # bend sensor data
  732. glove.setBeacon(VR.find('ART_tracker.1'))
  733. else:
  734. num = 0
  735.  
  736.  
  737. # If gripping while not dragging the handle, start dragging it.
  738. if num >= 20 and not VR.isDragging:
  739. VR.fGlove = 0
  740. VR.touchedHandle = True
  741. startDrag()
  742.  
  743. # If loosening the grip while dragging the handle, stop dragging it.
  744. # Also stio dragging if a challenge is running
  745. if (num < 20 and VR.isDragging) or VR.isChallenge:
  746. VR.fGlove = 1
  747. stopDrag()
  748.  
  749.  
  750. # OLD METHOD
  751. #def drag():
  752. # if glove.intersect(VR.getRoot()):
  753. # print "in"
  754. # obj = glove.getIntersected()
  755. # #key = dev.getKey()
  756. # #state = dev.getState()
  757. # print 'drag', obj.getName()
  758. # if not VR.fGlove :
  759. # glove.drag(obj)
  760. # print "drag"
  761. # else: glove.drop()
  762.  
  763. </core><trig type="on_timeout" dev="" state="Pressed" param="20000" key="0" base_name="trigger" name_space="__global__" name_suffix="0" persistency="666"/></Script><Script base_name="debugging" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  764. import VR
  765.  
  766. # Create small debugging spheres on all coordinates stored in the
  767. # array nodes. nodes has to be an array of three dimensional arrays,
  768. # each containing the coordinates of the spheres.
  769. # The spheres will be created as children of VR.scene
  770. def testCircles(nodes):
  771. for idx, node in enumerate(nodes):
  772. circ = VR.Geometry("debug" + str(node[0])+str(node[1])+str(node[2]))
  773. circ.setPrimitive("Sphere 0.01")
  774. circ.setFrom(node)
  775. VR.scene.addChild(circ)
  776. VR.testCircles = testCircles
  777. </core></Script><Script base_name="init" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  778. import VR
  779. import os
  780. #Only activate following line if real or virtual glove available!!
  781. #os.system("cd /home/glovevm/Rechner/Rechner/build && ./server")
  782. #if hasattr(VR, 'scene')
  783. vrpnd = VR.find("vrpn_device")
  784.  
  785. if hasattr(VR, 'scene') and VR.scene: VR.scene.destroy()
  786. VR.scene = VR.Object('scene')
  787. VR.getRoot().find('light').addChild(VR.scene)
  788. VR.counter = 100;
  789. #VR.find('Default').setFrom([0,3,1])
  790. #VR.find("Default").setAt([0,0,1])
  791.  
  792. VR.dots = VR.Object('debugcircles')
  793. VR.scene.addChild(VR.dots)
  794. VR.touchedHandle = False
  795. VR.timeCounter = 0
  796. VR.isDragging = False
  797.  
  798. VR.isChallenge = False
  799. VR.timeInChallenge = 0
  800. VR.challengePos = []
  801. VR.challengePart = 0
  802.  
  803. VR.maxChallengeTime = 2000
  804. VR.hasWon = False
  805.  
  806. # Create game objects
  807. VR.triggerScript("debugging")
  808. VR.triggerScript("Line")
  809. VR.triggerScript("ControlHandle")
  810. VR.triggerScript("Plane")
  811. VR.triggerScript("Hand")
  812.  
  813. # Debugging spheres for line
  814. #VR.testCircles([getControlHandleCenter()])
  815.  
  816. VR.hasInitialized = True
  817. print 'done init'
  818.  
  819.  
  820. #print(vrpnd)
  821.  
  822. #digi1 = vrpnd.getKeyState(3)
  823. #digi2 = vrpnd.getKeyState(2)
  824.  
  825. #if digi1 == 1:
  826. # print ("digi1")
  827. #if digi2 == 1:
  828. # print ("digi2")
  829. </core><trig type="on_scene_load" dev="" state="Pressed" param="" key="0" base_name="trigger" name_space="__global__" name_suffix="0" persistency="666"/></Script><Script base_name="moveCam" group="no group" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  830. import VR
  831.  
  832. cam = VR.find('Default')
  833. cam.translate([0,1,0])
  834. </core></Script><Script base_name="setPlaneDirections" group="gamelogic" name_space="__script__" name_suffix="0" persistency="666" server="server1" type="Python"><core>
  835. import VR
  836.  
  837. for challenge in VR.challenges:
  838. plane = challenge["plane"]
  839.  
  840. # Make plane look at cam
  841. plane.setAt(VR.find("Default").getWorldFrom())
  842.  
  843. # (Alternative) Make plane look at control handle
  844. #plane.setAt(VR.controlHandle.getWorldFrom())
  845. </core><trig type="on_timeout" dev="" state="Pressed" param="50" key="0" base_name="trigger" name_space="__global__" name_suffix="13" persistency="666"/></Script></Scripts><Sockets persistency="666"/><Background color="0.6 0.6 0.6" format=".png" path="" persistency="666" type="0"/><Navigation active="Orbit" persistency="666"/><Materials persistency="666"/><Semantics persistency="666"/></Scene>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement