I want move an object using keyboard input, but it is not working. It sticks with the initial position and does not change to the position returned by getX()
. How can I get the object to change positions?
from direct.showbase.ShowBase import ShowBase
from direct.task.TaskManagerGlobal import taskMgr
from panda3d.core import *
from panda3d.vision import WebcamVideo, ARToolKit
# the webcam feed can not be made into a power of two texture
loadPrcFileData("", "textures-power-2 none")
# usualy the drawn texture lags a bit behind the calculted positions.
# this is a trying to reduce the lag.
loadPrcFileData("","auto-flip 0")
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# self.disableMouse()
self.physics = False
option = WebcamVideo.getOption(0)
self.tex = MovieTexture(option)
# self.tex.setKeepRamImage(True)
cm = CardMaker("card")
cm.setUvRange(Point2(0, 0), Point2(1, 1))
cm.setFrame(-1, 1, -1, 1)
card = self.render2d.attachNewNode(cm.generate())
card.setTexture(self.tex)
# Starting ARToolkit
self.cam.node().getDisplayRegion(0).setSort(20)
self.ar2 = ARToolKit.make(self.cam, "./camera_para.dat", 1)
self.prep = False
self.changeObject()
taskMgr.add(self.updatePatterns, 'updatePatterns')
self.accept('arrow_up', self.moveup)
# Changing selected object on secondary pattern
def changeObject(self):
self.pandaActor = self.loader.loadModel("models/teapot")
self.pandaActor.reparent_to(self.render)
self.ar2.attachPattern("./aa.pat", self.pandaActor)
def updatePatterns(self, task):
self.ar2.analyze(self.tex)
return task.cont
def moveup(self):
self.pandaActor.setX(self.pandaActor.getX()+1)
print self.pandaActor.getX()
app = MyApp()
app.run()