Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

How to Derive an NVSG Object

The NVSGSDK comes with an extensive set of NVSG objects that we also refer to as NVSG Core Classes. However, some situations might require the creation of one or more new NVSG objects in order to extend the set of available core classes. This section discusses the key points in inventing and customizing NVSG objects.

The Base Class for NVSG Objects

Objects that are intended to become a part of the scenegraph - that is, an NVSG object - must inherit from Object or an object-derived class.

Example of a custom defined GeoNode:

// MyGeoNode.h
#include "nvsg/GeoNode.h" // base class definition

class MyGeoNode : public nvsg::GeoNode
{
public:
  MyGeoNode(); 
  //...
};

NVSG Object Type Identification

For a custom traverser (see How to Derive a Traverser) it is essential to identify all actual scenegraph components (Nodes and Node Components) while traversing the scenegraph, and to call the corresponding handler routine for a particular object. For this reason, all concrete NVSG object types must be assigned to a unique object code. Secure object codes for custom defined NVSG objects start at nvsg::OC_CUSTOMOBJECT.

Choosing an object code lower than nvsg::OC_CUSTOMOBJECT for a custom-defined NVSG object results in undefined runtime behavior!

Example of custom object code definitions:

// MyObjectCodes.h
#include "nvsg/Object.h" // object code defines

enum
{
  OC_MYGEONODE = OC_CUSTOMOBJECT 
, OC_MYGEOSET   // = OC_CUSTOMOBJECT+1
, OC_MYMATERIAL // = OC_CUSTOMOBJECT+2
};

// ...

It is best to assign the unique object code at the object's construction time:

// MyGeoNode.cpp
#include "MyGeoNode.h" // MyGeoNode definition
#include "MyObjectCodes.h" // custom object codes

using namespace nvsg;

MyGeoNode::MyGeoNode()
{ // assign the unique object code
  m_objectCode = OC_MYGEONODE;
}

Back to


Generated on Tue Mar 1 13:20:21 2005 for NVSGSDK by NVIDIA