PDA

View Full Version : Change position of MainView after COLLISION_EVENT


kay
09-16-2010, 04:48 AM
hi,

I would like to set the MainView to a new position after there was a COLLISION_EVENT. Calling viz.MainView.setPosition(...) leads to a "RuntimeError: maximum recursion depth exceeded".


viz.collision(viz.ON)

def onCollision(info):
viz.MainView.setPosition([0,0,0])

viz.callback(viz.COLLISION_EVENT,onCollision)


Using viz.MainView.reset(viz.HEAD_POS) works. But how do I change the reset position? The default is (0,1.82,0).


viz.collision(viz.ON)

def onCollision(info):
viz.MainView.reset(viz.HEAD_POS)

viz.callback(viz.COLLISION_EVENT,onCollision)


Thank you very much for suggestions.

Jeff
09-16-2010, 11:54 AM
You're getting that error in the first piece of code because the viewpoint is being placed in a location that causes a collision when the collision event occurs.

In the second piece of code the viewpoint is set to [0,1.82,0] unless the eyeheight has been changed. That command will always move the view above the origin.

If you want to move the viewpoint somewhere else use viz.MainView.setPosition() but make sure the position is not at ground level or colliding with another object.

kay
09-17-2010, 03:59 AM
hi jeff,

I tried viz.MainView.setPosition() with other positions (non-colliding!), e.g., simply


viz.collision(viz.ON)

def onCollision(info):
viz.MainView.setPosition([0,1.82,0])

viz.callback(viz.COLLISION_EVENT,onCollision)


I still get the "RuntimeError: maximum recursion depth exceeded". Calling viz.MainView.setPosition(), e.g.,


viz.collision(viz.ON)

def onCollision(info):
viz.MainView.reset(viz.HEAD_POS)
viz.MainView.setPosition([0,1.82,0])

viz.callback(viz.COLLISION_EVENT,onCollision)


also leads to the RuntimeError.

Any other ideas? Isn't possible to change the default of viz.HEAD_POS?

Jeff
09-17-2010, 02:21 PM
What do you have loaded in your scene? Can you post an example script that reproduces the error?

kay
09-23-2010, 05:09 AM
hi,

i tried to find a reproducible example. The maximum recursion depth error doesn't appear allways. Often everything work smoothly now.

However ... use either the intialPos inside the tunnel and go to the outside and collide with it or use the outside initialPos and collide with the inside of the tunnel in the example below. The error should appear then.


import viz
viz.go()


ob=viz.add('playground.wrl')
ob.setScale(1.5,1.5,1.5)

#initialPos=[14.,0.75,13.5] # inside tunnel
initialPos=[6.,0.75,13.5] # outside tunnel

viz.MainView.setPosition(initialPos)
viz.MainView.eyeheight(initialPos[1])
viz.collision(viz.ON)
viz.MainView.setPosition(initialPos)

print viz.MainView.getPosition()



def onCollision(info):
print "collision at ", info.point
viz.MainView.setPosition(initialPos)

viz.callback(viz.COLLISION_EVENT,onCollision)



By the way, here is the full error, maybe this helps to understand what's happening:

Traceback (most recent call last):
File "<string>", line 0, in ?
File "C:\Program Files (x86)\WorldViz\Vizard30/python\viz.py", line 367, in __init__
self.object = _GetNode(data[7])
RuntimeError: maximum recursion depth exceeded

masaki
10-07-2010, 05:06 PM
Hi,

Try turning collision off before changing the view position, then turn it back on.

def onCollision(info):
print "collision at ", info.point
viz.collision(viz.OFF)
viz.MainView.setPosition(initialPos)
viz.collision(viz.ON)

Best,
Masaki