PDA

View Full Version : Viewpoint with collision buffer issue


Kevin1270
09-16-2012, 06:13 AM
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)

Jeff
09-18-2012, 11:12 AM
Instead of using viz.collisionbuffer, calculate the distance between hand and ball every frame using vizmat.Distance to detect the touch. If you have Vizard 4, I would recommend using the vizproximity library.

Kevin1270
09-20-2012, 03:53 AM
Hi Jeff. Thanks for you reply. Actually, I have already done this and it works, but not as smoothly as the built-in API - when you collide with the ball using the built-in collision detection, it slides smoothly around the object. Besides, surely this kind of thing is why users would want to use a development environment like Vizard; to have an armoury of useful pre-written functions to do jobs just like this to save development time. I'm trying a number of different approaches to solve this, but my main goal is to do this with the API. If anyone as some possible solutions using Vizard functions, that would be really useful. In the meantime, I'll keep bashing away.

Thanks again for your help.

Kevin1270
09-20-2012, 11:48 AM
I forgot to add that I don't have Vizard 4, so can't make use of the library mentioned. Thanks again.

Cheers, Kevin