2.1. Overview

The file SoSubNode.h contains the macros for defining new node classes. The SO_NODE_HEADER() macro declares type identifier and naming variables and methods that all node classes must support. The SO_NODE_SOURCE() macro defines the static variables and methods declared in the SO_NODE_HEADER() macro. Other macros useful in creating new node classes are mentioned in the following sections.

Creating a new node requires these steps:

  1. Select a name for the new node class and determine what class it is derived from.

  2. Define and name each field in the node.

  3. Define an initClass() method to initialize the type information and to ensure that the required elements are enabled in the state (see Section 2.2, “Initializing the Node Class”).

  4. Define a constructor (see Section 2.3, “Defining the Constructor”).

  5. Implement the actions supported by the node (see Section 2.4, “Implementing Actions”).

    a. For a property node, you usually need to implement the GLRender() and callback() methods (see Section 2.5, “Creating a Property Node”). You may also need to implement getBoundingBox(), getMatrix(), and other methods.

    b. For a shape node, you need to implement the generate- Primitives() method for the SoCallbackAction SoCallbackAction SoCallbackAction as well as the getBoundingBox() method. You may want to implement a specific GLRender() or rayPick() method as well (see Section 2.6, “Creating a Shape Node”). For vertex-based shapes, you may need to implement a generateDefaultNormals() method (see Section 2.14, “Generating Default Normals”).

    c. For a group node, you need to implement all actions to ensure that the children are traversed (see Section 2.7, “Creating a Group Node”).

  6. Implement a copy() method if the node contains any non-field instance data (see Section 2.10, “The copy() Method”).

  7. Implement an affectsState() method if it cannot be inherited from the parent class (see Section 2.11, “The affectsState() Method”).