WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Detecting collision with on-the-fly object (https://forum.worldviz.com/showthread.php?t=5159)

Notch 09-01-2014 03:31 PM

Detecting collision with on-the-fly object
 
I have generated on-the-fly cylinders using vizshape.addCylinder(). I would like to detect collisions with a specific cylinder.

I am able to detect collisions with objects using viz.callback(viz.COLLISION_EVENT,onCollision). I can get the name of the object collided with by using the following code:

Code:

def onCollision(info):
        print('Collided with object',info.object)

Although this returns something like "Collided with object viz.VizPrimitive(9)", but I have way knowing what 'VizPrimitive(9)' is. I have several objects in the scene, and ideally would like to add names to the objects at the time they are created, so that I can then work out what I'm colliding with later on.

How do I name on-the-fly objects, and how do I then get the name of the object when a collision occurs?

Jeff 09-08-2014 02:51 PM

You can check to see if info.object matches the name assigned to the cylinder:

Code:

import viz
import vizshape
viz.go()

viz.collision(viz.ON)

dojo = viz.addChild('dojo.osgb')
cylinder = vizshape.addCylinder(pos=[0,1.8,4])

def onCollision(info):
       
        if info.object == cylinder:
                print 'Collided with cylinder'

viz.callback(viz.COLLISION_EVENT,onCollision)


Notch 09-09-2014 04:41 AM

Thanks very much. It looks like what I hadn't appreciated is that it is not possible to explicitly name objects (with a string), but instead I needed to follow the handle to the object.

Got it all working now :)


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

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