Scene Graph Classes (Advanced Methods in Computer Graphics)

This section gives an outline of the methods in the scene graph classes. A description of these classes can be found in Sect. 3.5. The static relationships between the classes are shown in Fig. B.1.

Relationships between scene graph classes

Fig. B.1 Relationships between scene graph classes

GroupNode Class

tmpf9b3-248_thumb

Description:

The list variable .children stores references to the children of the current group node, in an STL list structure. The access level for this variable is declared as private since all subclasses are leaf nodes that do not have children. Each group node also stores a reference to its parent node in the variable .parent. It has a value NULL for the root node. Every group node also stores the translation parameters _tx, _ty, _tz and rotation angles _angleX, _angleY, _angleZ which define the transformation of the current node to the coordinate frame of the parent node.


tmpf9b3-249_thumb

Description:

The class contains only one no-argument constructor that initializes the parent node to NULL and the transformation parameters to zeros.

tmpf9b3-250_thumb

Description:

The method addChild includes the specified node as a child node of the current node. The method removeChild removes the specified node, if it exists, from the list of children of the current node.

tmpf9b3-251_thumb

Description:

The above methods set the transformation parameters of the current node. The node transformation is always assumed to be of the form TR.

tmpf9b3-252_thumb

Description:

This method uses OpenGL functions to push the matrices for the inverse transformation (TR)“1 = R“1 T“1 of the current node to the transformation stack. Note that this function does not explicitly generate the inverse transformation matrix.

tmpf9b3-253_thumb

Description:

This method gets the singleton object of the CameraNode, sets up the view transformation matrix and calls the method draw. A scene is rendered by invoking this method on the root node.The draw method is not directly invoked by the application. It is indirectly invoked on a group node via the method render. The draw method uses OpenGL functions to push the current node’s transformation matrix to the transformation stack, and recursively calls itself on all child nodes. This polymorphic method causes objects to be drawn when invoked on leaf nodes.

tmpf9b3-254_thumb

Description:

This getter method returns the reference to the parent of the current node.

ObjectNode Class

The ObjectNode class is a subclass of GroupNode.

tmpf9b3-255_thumb

Description:

The enumerated type ObjType defines a collection of GLUT objects which users can specify in the constructor to display an object. At the time of construction, the user can specify its scale factors _scaleX, _scaleY, _scaleZ, and also its material colour using the normalized values in the range [0, 1] for _colorR, colorG, colorB.

tmpf9b3-256_thumb

Description:

The constructor initializes the object type to CUBE, the scale factors to 1, and the object material colour to white.

tmpf9b3-257_thumb

Description:

The method setObject is used to change the parameters of the current object, including its type and scale factors. The setColor method modifies the material colour of the current object.

CameraNode Class

The CameraNode class is a subclass of GroupNode.

tmpf9b3-258_thumb

Description:

The data members _fov, .aspect, _near, _far define the perspective view frustum of the camera in terms of the field of view, aspect ratio, near plane distance and the far plane distance. The Boolean variable flag ensures that at most one instance of the class is created.

tmpf9b3-259_thumb

Description:

The CameraNode class is a singleton class with a private constructor. The only instance of the class is available through the static method getInstance(). By default, the camera view frustum has 60° field of view, aspect ratio 1, near plane distance 1, and far plane distance 1,000.

tmpf9b3-260_thumb

Description:

This setter method allows you to change the default frustum parameters of the camera object.

tmpf9b3-261_thumb

Description:

The viewTransform method traverses the scene graph from the camera node towards the root node, and pushes the inverse transformation matrices of each node onto the transformation stack using OpenGL functions. The method calls the inverseTransform method of the GroupNode class for this operation.

The method projection sets up the projection matrix using OpenGL functions. Both the above methods are not usually invoked directly by the user. The render method of the GroupNode class invokes both the methods to set up the view and projective transformations for the rendering pipeline.

LightNode Class

The LightNode class is a subclass of GroupNode.

tmpf9b3-262_thumb

Description:

This integer field can be assigned a value between 0 and 7. A value i corresponds to the named light source GL_LIGHTi defined in OpenGL.

tmpf9b3-263_thumb

Description:

The constructor specifies the index of the OpenGL light source to be used for the current object of the LightNode class. The default position of the light node is (0, 0, 0). The position can be changed by specifying transformation parameters for the node using the translate method. Note that all other light source parameters will have to be defined separately by the user with the help of OpenGL functions.

tmpf9b3-264_thumb

Description:

This setter method allows the user to change the current light source used by the object.

Next post:

Previous post: