WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Navigation problem (https://forum.worldviz.com/showthread.php?t=2719)

JimC 04-27-2010 01:17 PM

Navigation problem
 
Hi all,

I have a simple CAVE navigator: You point the tracked wand in the direction you want to fly and push the joystick forward. It's implemented by linking the following to the CaveView object:

Code:

class SyzygyNagivator(viz.VizNode,viz.EventClass):
  # __init__ omitted
  def onUpdate(self,e):
    currTime = time.clock()
    elapsed = currTime - self.lastTime
    if elapsed < .25:
      # Get joystick X,Z values and threshold them
      xMove = self.service.getAxis( self.xIndex )
      if abs(xMove) < .25:
        xMove = 0.
      zMove = self.service.getAxis( self.zIndex )
      if abs(zMove) < .25:
        zMove = 0.
      # Get wand orientation matrix
      rotMat = szg.ar_extractRotationMatrix( self.service.getMatrix( self.matIndex ) )
      # Compute rotated X, Z motion vectors
      xVec = rotMat * szg.arVector3(0,0,zMove)
      zVec = rotMat * szg.arVector3(xMove,0,0)
      # Add them
      vec = (xVec + zVec).toTuple()
      # Displace by motion vector
      currPos = gCaveView.getPosition()
      newPos = vizmat.MoveAlongVector( currPos, vec, elapsed*self.speed )
      self.setPosition( newPos )
    self.lastTime = currTime

...which works fine for flying around in empty space. The catch is that in e.g. gallery.py, when I collide with a well the stored position keeps incrementing as long as I hold the joystick forward, even though the collision detection is keeping the viewpoint from moving forward. In other words, the CaveView object's position does not reflect the action of the collision-handling algorithm. Of course, when you reverse direction, nothing happens until the stored position gets back inside the gallery. What's the right way to do this, i.e. where is there a position that reflects the collision detection?

Jeff 04-27-2010 03:19 PM

When viewpoint collision is enabled a collision event will be generated when the viewpoint collides with an object. Information about the collision, including position, is available.
Code:

import viz
viz.go()

gallery = viz.add('gallery.ive')

viz.collision(viz.ON)

def onCollision(info):
    print 'Collided at point',info.point

viz.callback(viz.COLLISION_EVENT, onCollision)


TopazFrost 02-12-2014 10:45 AM

Actually, I am using the CaveView. The problem is the the collision callback even only works 50% of the time. I hit a wall, and sometimes it shows up, then the next time it won't. Changing the step size seems to help a bit, but not enough for a user not to get stuck on a regular basis.

Jeff 02-13-2014 05:44 AM

The collision detection works as expected with a simple vizcave example. Try adding collision detection to the script on the following page and just move the viewpoint with arrow keys:

http://docs.worldviz.com/vizard/#vizcave_powerwall.htm

Perhaps other code in your script is interfering with the viewpoint movement or collision code. Can you post a simple example that reproduces the issue?


All times are GMT -7. The time now is 12:43 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC