WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-16-2012, 06:13 AM
Kevin1270 Kevin1270 is offline
Member
 
Join Date: Sep 2012
Posts: 3
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)
Reply With Quote
  #2  
Old 09-18-2012, 11:12 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
  #3  
Old 09-20-2012, 03:53 AM
Kevin1270 Kevin1270 is offline
Member
 
Join Date: Sep 2012
Posts: 3
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.
Reply With Quote
  #4  
Old 09-20-2012, 11:48 AM
Kevin1270 Kevin1270 is offline
Member
 
Join Date: Sep 2012
Posts: 3
I forgot to add that I don't have Vizard 4, so can't make use of the library mentioned. Thanks again.

Cheers, Kevin
Reply With Quote
Reply

Tags
collision

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue Getting Quad Buffer Working nabrahamson Vizard 2 08-30-2012 09:43 AM
Vizard Collision (ON) issue kovitch Vizard 2 08-09-2011 01:40 AM
Collision problem Dave Vizard 2 09-16-2010 04:25 AM
Collision with child nodes rubberpimple Vizard 4 09-17-2008 04:27 PM
Avatar w/ hat cannot look at viewpoint TrashcanPatrol Vizard 5 08-19-2008 08:26 AM


All times are GMT -7. The time now is 06:06 AM.


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