This tutorial shows how to be notified when objects are colliding, as well as the creation of collision shape objects that more closely match their geometry. Vizard informs you of collisions with its event system, and allows you to set up a callback function handling VizPhysicsShape collision. You can make more accurate collision shapes for complex geometry by creating VizPhysicsShapes for child nodes instead of the global node.
This tutorial steps through code found in callbacksAndComplexShapes.py. For the complete example script look in the \tutorials\physics directory.
The code bellow creates VizPhysicsShapes at a smaller granularity than a single call to <node3d>.collideBox().
By supplying the node parameter in the bumper.collideBox() call, the resulting VizPhysicsShape object will only encompass the specified child node. Creating VizPhysicsShapes for all of the child nodes in the table.wrl model avoids creating a collision box that surrounds the entire table.wrl model and allows balls to pass between the legs of the table.
For your program to be aware of physics collisions, you must do two things: call <node3d>.enable( viz.COLLIDE_NOTIFY ) on any nodes that you want to generate a collision events and setup a collision event callback function.
In our for loop that creates the bumpers, we tell Vizard to fire collision related events whenever objects are colliding with our bumpers.
The above code is our collision event handling function followed by the callback registering function. The event function has two attributes we are interested in: obj1, the node that generated the event, in our case the bumpers that have enabled viz.COLLIDE_NOTIFY; and obj2, the node that collided with obj1, in this script obj2 will be the bouncing balls. The call to viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide ) tells Vizard to call the onCollide function when the nodes first collide. If you wanted to call a function when two nodes stop touching you would register a function to handle viz.COLLIDE_END_EVENT. For instance, a viz.COLLIDE_END_EVENT would fire when something was pushed off a table.