WorldViz User Forum

WorldViz User Forum (
-   Plug-in development (
-   -   Collision detection with custom nodes? (

JimC 09-30-2009 02:20 PM

Collision detection with custom nodes?
When I add:


to the end of (example script from the plugin API), I can still drive the viewpoint right through the middle of the polygon. What am I missing?


farshizzo 10-02-2009 10:54 AM

Is your custom node using raw OpenGL command to render? If so, then collisions won't work because OpenSceneGraph will not know anything about the mesh of your object. There are two ways to handle this:

1) Use the built-in osg::Geometry class to render your object

2) Implement the following osg::Drawable methods in your custom drawable class:

virtual bool supports(osg::PrimitiveFunctor&) const;
virtual void accept(osg::PrimitiveFunctor& pf) const;

These methods allow you to pass information about your mesh to OpenSceneGraph, which will allow it to participate in collision/intersection/pick tests. Here is a very simple example showing how to implement this for a simple quad:

virtual bool supports(osg::PrimitiveFunctor&) const { return true; }

virtual void accept(osg::PrimitiveFunctor& pf) const

JimC 10-02-2009 11:49 AM

This is just the custom-node example plugin that comes with the plugin API. It draw a single (deforming) square.

I assumed that the Drawable's computeBound() method, which returns a BoundingBox, was used for collision detection. The overridden computeBound() method in the example plugin appears to be returning reasonable values, and it does get called by winviz. If not for collision detection, what is this method for?


JimC 10-02-2009 12:01 PM

> If not for collision detection, what is this method for?



farshizzo 10-02-2009 12:24 PM

The bounding box of the drawable is used for culling.

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

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