Viewpoint with collision buffer issue
Hi. I'm having a problem with a viewpoint offset implemented with <viz>.collisionbuffer. I'm using this to detect when a hand fixed to the viewpoint touches a ball on a pole. If the ball is approached so that the view is moving straight ahead, collision will be detected, but if the ball is approached from the side, collison is only being detected at a point behind the viewpoint, as if the offset set by collisionbuffer had flipped 180 degrees around the viewpoint. The code Im referring to is below - any help would be much appreciated.
import viz
import hand
viewHeight = 1.82
handViewOffset = [0.0, -0.2, 0.5]
class startProgram:
def __init__ (self, handViewOffset, viewHeight):
self.handViewOffset = handViewOffset
self.viewHeight = viewHeight
self.environmentFile = 'court.ive'
self.xScale = 1.0
self.yScale = 0.6
self.environment_handle = viz.add (self.environmentFile) # load environment
self.environment_handle.setScale (self.xScale * 1.5, 1.0, self.yScale * 0.75) # width, height, length
self.glove = hand.add (None)
self.glove.setGesture (hand.GESTURE_FLAT_HAND, False, 1.0)
self.closeHand ()
self.viewHandle = viz.MainView.setEuler (180.0, 0.0, 0.0)
viz.MainView.setPosition (0.0, self.viewHeight, 5.0)
viz.MainView.collisionbuffer (float (self.handViewOffset [2]) + 0.2)
viewLink = viz.link (viz.MainView, self.glove, enabled=True)
viewLink.setMask (viz.LINK_POS | viz.LINK_ORI)
viewLink.preTrans (handViewOffset)
viewLink.preEuler ([0.0, -45.0, 0.0])
viz.collision (viz.ON)
viz.callback (viz.COLLISION_EVENT, self.collisionCallback)
self.poleconfig = 'G' # TEMPORARY
self.addPoles ()
def collisionCallback (self, event):
print 'Collision Occurred'
def closeHand (self):
self.glove.getJointBone (hand.THUMB_1).setEuler (0.0, 0.0, -20.0)
self.glove.getJointBone (hand.THUMB_2).setEuler (0.0, 50.0, -40.0)
self.glove.getJointBone (hand.THUMB_3).setEuler (0.0, -20.0, -20.0)
self.glove.getJointBone (hand.PINKY_1).setEuler (0.0, -10.0, 20.0)
self.glove.getJointBone (hand.PINKY_2).setEuler (0.0, 0.0, 0.0)
self.glove.getJointBone (hand.RING_1).setEuler (0.0, 0.0, 10.0)
self.glove.getJointBone (hand.RING_2).setEuler (0.0, 0.0, 0.0)
self.glove.getJointBone (hand.INDEX_1).setEuler (0.0, 0.0, -20.0)
self.glove.getJointBone (hand.INDEX_2).setEuler (0.0, 0.0, 0.0)
def addPoles (self):
pole = viz.add ('pole.wrl')
poleDims = pole.getBoundingBox ()
poleScaleFactor = (self.viewHeight + float (self.handViewOffset [1])) / poleDims [1]
ballScaleFactor = poleDims [1] / self.viewHeight
pole.setScale (3 * [poleScaleFactor])
ballOnPole = viz.addChild ('white_ball.wrl', parent = pole)
ballOnPole.setScale (3 * [ballScaleFactor])
ballOnPole.setPosition (0, ballScaleFactor * viewHeight, 0)
viz.go ()
x = startProgram (handViewOffset, viewHeight)
|