SPIN Framework
Public Types | Public Member Functions

spin::ConstraintsNode Class Reference

A node with constrained motion. More...

#include <ConstraintsNode.h>

Inheritance diagram for spin::ConstraintsNode:
spin::GroupNode spin::ReferencedNode spin::UserNode

List of all members.

Public Types

enum  ConstraintMode {
  BASIC, DROP, COLLIDE, BOUNCE,
  STICK, COLLIDE_THRU
}
enum  CollisionMode { POINT, BOUNDING_SPHERE, MESH }

Public Member Functions

 ConstraintsNode (SceneManager *sceneManager, const char *initID)
virtual void callbackUpdate (osg::NodeVisitor *nv)
void setTarget (const char *id)
const char * getTarget () const
void setConstraintMode (ConstraintMode m)
int getConstraintMode () const
void setCubeSize (float xScale, float yScale, float zScale)
void setCubeOffset (float x, float y, float z)
osg::Vec3 getCubeSize () const
osg::Vec3 getCubeOffset () const
virtual void setTranslation (float x, float y, float z)
virtual void translate (float x, float y, float z)
virtual void move (float x, float y, float z)
void applyConstrainedTranslation (osg::Vec3 v)
virtual std::vector< lo_message > getState () const

Detailed Description

A node with constrained motion.

This node operates much like GroupNode, allowing children to be attached, but motion is constrained in a certain way.

Foremost, there is one BASIC form of constraint where motion of the node is bound within a cubic volume.

Additionally, there are several ConstraintModes, where properties of a target node are used to limit movement of this node. For example, the node will only move along the surface of the target, or bounce off.

One needs to specify the target node for some of these special modes to work.


Member Enumeration Documentation

Enumerator:
POINT 

When computing collisions with other surfaces, only the origin point (local 0,0,0) of is considered. This is by far the most efficient method.

BOUNDING_SPHERE 

When computing collisions with other surfaces, we use the local bounding sphere of this node to check the collision.

MESH 

The most expensive method of computing collisions, the entire mesh is traversed to check if any parts of the mesh has collided with others in the scene.

Enumerator containing all of the constraint modes available

Enumerator:
BASIC 

The node is just constrained within a cubic volume. Important note: the BASIC constraint is always maintained, even if another mode is chosen.

DROP 

The node sits on the surface of the target subgraph (ie, follows local Z-axis down until it finds an intersection with the target surface)

COLLIDE 

A form of collision detection, where the node is blocked (and slides along) the target's surface. Note: sliding only works when the target is locally convex. Concavities are not checked, and may position the node on the other side of the target's surface. Use STICK instead for non-convex geometries.

BOUNCE 

A form of collision detection, where the node reflects off the parent's surface, and travels in the reflected direction (ie, the orientation of the node is changed). Note: this only works when node is moved using the "translate" command.

STICK 

Equivalent to COLLIDE, but without sliding.

COLLIDE_THRU 

A fake constraint, which can be used to simply report when a collision occurs. The event reported is the same as that for COLLIDE.


Member Function Documentation

void spin::ConstraintsNode::applyConstrainedTranslation ( osg::Vec3  v)

A pseudo-recursive function that checks if a translation results in one or more intersections with the target node. If no intersection, this method defaults to just a setTranslation call. Otherwise, it will do a setTranslation for the collision point, and call itself again until there are no collisions left.

void spin::ConstraintsNode::callbackUpdate ( osg::NodeVisitor *  nv) [virtual]

For nodes that require regular programmatic control, there is a callback that is evaluated with every refresh. This function can thus be used for animations, or any other periodic updates.

Note that changes to the scene graph structure (eg, moving/deleting nodes should NOT be done within this callback because traversals stacks will become corrupted. The technique is rather to enable a flag and then do the actual change in the SceneManager::updateGraph() method.

Reimplemented from spin::GroupNode.

Reimplemented in spin::UserNode.

int spin::ConstraintsNode::getConstraintMode ( ) const [inline]
Returns:
int which is converted to the type of constraint currently set on the node (drawn from constraintMode enum)
osg::Vec3 spin::ConstraintsNode::getCubeOffset ( ) const [inline]
Returns:
Vec indicating the offset of the cubic BASIC constraint from its local coordinate system.
osg::Vec3 spin::ConstraintsNode::getCubeSize ( ) const [inline]
Returns:
Vec3 indicating the size of the cubic BASIC constraint
std::vector< lo_message > spin::ConstraintsNode::getState ( ) const [virtual]

For each subclass of ReferencedNode, we override the getState() method to fill the vector with the correct set of methods for this particular node

Reimplemented from spin::GroupNode.

Reimplemented in spin::UserNode.

const char* spin::ConstraintsNode::getTarget ( ) const [inline]
Returns:
t_symbol which indicates the target ID on which the constraints are based (Note: The target could also be a group node).
void spin::ConstraintsNode::move ( float  x,
float  y,
float  z 
) [virtual]

The move command adds a relative translation with respect to the node's current orientation. That is, the node will translate along it's direction vector by the supplied number of units.

Reimplemented from spin::GroupNode.

void spin::ConstraintsNode::setConstraintMode ( ConstraintMode  m)

Sets the node's constraint mode, based on the types in constrainMode enum (see enum for details)

void spin::ConstraintsNode::setCubeOffset ( float  x,
float  y,
float  z 
)

Sets the center of the BASIC constraint cube with respect to the local coordinate system (either the parent object or the world grid).

void spin::ConstraintsNode::setCubeSize ( float  xScale,
float  yScale,
float  zScale 
)

Sets the size of the imaginary cube beyond which the constrained node cannot pass, when constraint type BASIC is set.

void spin::ConstraintsNode::setTarget ( const char *  id)

Sets a target whose properties can be used to limit movement of this node, depending on the type on constraint selected. (this should be a model node or shape node, or a group node ideally not too complex, because large amounts of triangles will lead to excessive calculations)

void spin::ConstraintsNode::setTranslation ( float  x,
float  y,
float  z 
) [virtual]

The local translation offset for this node with respect to it's parent

Reimplemented from spin::GroupNode.

void spin::ConstraintsNode::translate ( float  x,
float  y,
float  z 
) [virtual]

The translate command increments the node's current translation values (ie, it's position in the scene with respect to it's parent)

Reimplemented from spin::GroupNode.


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