forked from drone29a/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
67 lines (53 loc) · 2.42 KB
/
test.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
import direct.directbase.DirectStart
from pandac.PandaModules import TextNode
from direct.gui.DirectGui import *
from direct.gui.OnscreenText import OnscreenText
from direct.showbase import DirectObject
from direct.showbase.DirectObject import DirectObject
from direct.task import Task
import sys, logging
class FobPointUpdateTask(object):
def __init__(self, filePath):
self.filePath = filePath
self.f = open(filePath, 'r')
def __lines(self, num):
result = []
for i in range(num):
result.append(self.f.readline())
return result
def __call__(self, points, task):
newPositions = [[float(val) for val in line.split()[1:4]] for line in self.__lines(3)]
if len(newPositions[0]) is 0:
self.f.close()
return Task.done
for i in range(3):
points[i].setPos(*newPositions[i])
return Task.cont
class World(DirectObject):
def __init__(self):
self.escapeEventText = OnscreenText(text="ESC: Quit",
fg=(1,1,1,1), pos=(-1.3, 0.95),
align=TextNode.ALeft, scale=0.05)
self.accept('escape', sys.exit)
base.disableMouse()
base.setBackgroundColor(0, 0, 0, 0)
base.textureOff()
base.camera.setPos(0, 0, 200)
base.camera.setHpr(0, -90, 0)
self.sensorNodes = [loader.loadModelCopy("models/planet_sphere") for i in range(3)]
for sensorNode in self.sensorNodes:
sensorNode.reparentTo(render)
debugText = OnscreenText(str(camera.getPos()), fg=(1,1,1,1),
pos=(-1.3, 0.85), align=TextNode.ALeft,
scale=0.05, mayChange=True)
debugText = OnscreenText(str(camera.getHpr()), fg=(1,1,1,1),
pos=(-1.3, 0.75), align=TextNode.ALeft,
scale=0.05, mayChange=True)
def trackShoulder(shoulderNode, task):
base.camera.lookAt(shoulderNode)
return Task.cont
taskMgr.add(trackShoulder, 'TrackShoulder', extraArgs=[self.sensorNodes[0]], appendTask=True)
taskMgr.add(FobPointUpdateTask('/Users/mrevelle/src/sparklemotion/data/fob/2008_06_09/001.dat'),
'FobPointUpdate', extraArgs=[self.sensorNodes], appendTask=True)
w = World()
run()