Public Member Functions | Static Public Member Functions | Properties

CC3NodeBoundingVolume Class Reference

Bounding volumes are used by CC3Nodes to determine whether a node interset the camera's frustum, or to determine boundaries for collision detection during physics simulation. More...

#import <CC3BoundingVolumes.h>

Inheritance diagram for CC3NodeBoundingVolume:
Inheritance graph
[legend]

List of all members.

Public Member Functions

(BOOL) - doesIntersectFrustum:
(void) - markDirty
(void) - markDirtyAndUpdate
(void) - update

Static Public Member Functions

(id) + boundingVolume

Properties

GLfloat cameraDistanceProduct
CC3Vector centerOfGeometry
CC3Vector globalCenterOfGeometry
CC3Nodenode
BOOL shouldMaximize

Detailed Description

Bounding volumes are used by CC3Nodes to determine whether a node interset the camera's frustum, or to determine boundaries for collision detection during physics simulation.

Many different shapes of boundaries are available, including points, spheres, bounding boxes, etc, permitting tradeoffs between accuracy and computational processing time.

This base bounding volume is simply a single point. When applied to a node, it indicates that the node intersects the frustum if the node's center of geometry is within the frustum.

For meshes, the center of geometry is calculated from the vertex locations, via specialized subclasses of CC3NodeBoundingVolume. For other nodes, it can be set directly within the bounding volume via the centerOfGeometry property.


Member Function Documentation

+ (id) boundingVolume

Allocates and initializes an autoreleased instance.

- (BOOL) doesIntersectFrustum: (CC3Frustum *)  aFrustum

Returns whether this bounding volume intersects the specfied frustum.

This default implementation always returns YES. Subclasses will override appropriately.

This method is invoked automatically by the node whenever it needs to determine whether or not it should be drawn.

- (void) markDirty

Marks the volume as dirty and in need of rebuilding from the associated mesh vertices the next time that the update method is invoked.

- (void) markDirtyAndUpdate

Marks the volume as dirty and in need of rebuilding from the associated mesh vertices, and forces an update and transform of the bounding volume.

This method should be invoked whenever changes are made to the underlying mesh vertices. It is invoked automatically when the rebuildBoundingVolume is invoked on a node.

This is a convenience method that simply invokes the markDirty and update methods in order.

- (void) update

Transforms this bounding volume to match the transformation of the node.

If this bounding volume has been marked dirty via the markDirty method, this bounding volume will first be rebuilt from teh associated mesh vertices.

This method is invoked automatically by the node whenever it recalculates its transformMatrix. Usually, the application never needs to invoke this method directly.


Property Documentation

- (GLfloat) cameraDistanceProduct [read, write, assign]

A measure of the distance from the camera to the centre of geometry of the node.

This is used to test the Z-order of this node to determine rendering order.

For nodes whose rendering order depends on distance to the camera (translucent nodes), this property is set automatically once the global location of the node and the camera are determined. The application will generally make no use of this property.

Do not use the value of this property as the true distance from the node to the camera. This measure is not the actual distance from the camera to the node, but it is related to that distance.

Different node sequencers may measure distance differently. If the node sequencer uses the true distance from the camera to the node, this property will be set to the square of that distance to avoid making the computationally expensive and unnecessary square-root calculation. In addition, some node sequencers may compare distance in one direction only, such as only in the forwardDirection of the camera, or only the Z-axis component of the distance.

- (CC3Vector) centerOfGeometry [read, write, assign]

The center of geometry for the node in the node's local coordinate system.

For mesh nodes, the value of this property is automatically calculated from the vertex locations, via specialized subclasses of CC3NodeBoundingVolume used for meshes. For other nodes, this property can be set directly, if needed.

You can also set this property directly for mesh nodes as well. Doing so will override the value that was calculated automatically. This can be useful when the vertices will be changing frequently, and therefore the bounding volume will need to be recalculated frequently. By setting this property to a value that suits all possible vertex configurations, you can avoid expensive recalculations of the bounding volume as the vertices change.

When setting the value of this property on a mesh node directly, be sure to also set the shouldUseFixedBoundingVolume property of the node to YES, to stop automatic recalculation of this bounding volume whenever the underlying mesh vertices change.

The initial value of this property is kCC3VectorZero.

- (CC3Vector) globalCenterOfGeometry [read, assign]

The center of geometry for the node in the global coordinate system.

This is updated automatically by the transformVolume method of this bounding volume.

- (CC3Node *) node [read, write, assign]

The node whose boundary this instance is keeping track of.

- (BOOL) shouldMaximize [read, write, assign]

If the value of this property is set to YES, the boundary of this volume will only ever expand when this bounding volume is repeatedly rebuilt from the underlying mesh vertex data.

The shape of the boundary depends on the subclass. Whenever this bounding volume is rebuilt, the resulting boundary is compared to the previous boundary, and replaces the previous boundary only if it is larger.

Rebuilding occurs whenever the update method is invoked and this bounding volume has previously been marked as dirty via the markDirty method. Rebuilding also occurs directly when the markDirtyAndUpdate method is invoked.

Rebuilding occurs under control of the node, when the rebuildBoundingVolume method of the node is invoked and the shouldUseFixedBoundingVolume of the node is set to NO. Typically, the node invokes the rebuildBoundingVolume method whenever the vertex location data in the underlying mesh has changed.

Setting this property to YES and the shouldUseFixedBoundingVolume of the node to NO can be useful when pre-computing an appropriate fixed boundary for a node whose vertex location data frequently changes, such as a particle generator, and is often used at development time.

Once the resulting maximized boundary is determined, it can then be explicitly set into this bounding volume at run time, and the shouldUseFixedBoundingVolume of the node can be set to YES so that the processing cost of constantly rebuilding this bounding volume will not be incurred.

If a dynamic boundary is required at runtime, set both the shouldUseFixedBoundingVolume of the node and this property to NO. With a dynamic boundary, setting this property to YES has no advantage. The performance cost will be the same, and the resulting boundary will be less accurate.

The initial value of this property is NO.


The documentation for this class was generated from the following file: