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

sglAnimation Class Reference

#include <sglAnimation.hpp>

Inheritance diagram for sglAnimation::

sglGroup sglNode sglObject sglKeyFrameAnimation sglTimedAnimation List of all members.

Public Types

enum  ModeEnum {
  eCYCLE,
  eSWING
}
enum  StateEnum {
  eSTART,
  ePAUSE,
  eRESUME,
  eSTOP
}

Public Methods

 sglAnimation ()
virtual ~sglAnimation ()
void setMode (ModeEnum mode)
ModeEnum getMode () const
bool setState (StateEnum state)
StateEnum getState () const
void setRange (int first_node=0, int last_node=-1)
void getRange (unsigned int &first_node, unsigned int &last_node) const
void setSpeed (float speed)
float getSpeed () const
void setNumCycles (unsigned int num_cycles)
unsigned int getNumCycles () const
virtual void printInfo (ostream &ostrm, const char *indent_string) const

Protected Methods

virtual void computeValues ()=0
void copyTo (sglAnimation *dst, unsigned int mode) const

Protected Attributes

ModeEnum m_mode
StateEnum m_state
bool m_state_dirty_flag
bool m_range_flag
unsigned int m_first
unsigned int m_last
bool m_reverse_flag
float m_speed
unsigned int m_num_cycles

Detailed Description

Abstract base class for sglTimedAnimation and sglKeyFrameAnimation nodes that will select the child to be traversed based on frame time (real time) or frame count and whether or not the animation is active or not. This node is a subclass of sglGroup but the order (index) of the children is important and determines the order that they are displayed in the animation. Functions in the subclasses determine the duration that each child is displayed.

The speed of the animation can be changed with a call to setSpeed(..) where negative values reverse the animation. Speeds with magnitude between zero and one slow the animation down (0.5 corresponds to half speed), and magnitudes greater than one speed the animation up (2.0 corresponds to double speed). Specifying a speed of zero disables the animation.

The subset of the children can be animated by specifying the indices of the first and last child in a call to setRange(..). Passing no arguments to this function reverts the animation to using all the children. The number of times the animation is performed can also be set by calling setNumCycles(..). Passing a zero to this function causes the animation to repeat endlessly when activated.

The animation can be set to cycle (mode = eCYCLE) in ascending order or cycle (mode = eSWING) back and forth by calling the setMode(..) member function. A complete cycle in eCYCLE mode consists of animation from the first to last child (either from the complete set of child or the limits specified by a call to setRange()). A complete cycle in eSWING mode consists of a cycle up and back. Note that the last child is not displayed twice, nor is the first if the number of cycles is specified as greater than 1.

The state (control mode) of the system can be one of four: eSTOP (the initial state, and discontinues any current animation), eSTART (begins the animation), ePAUSE (pauses the animation), and eRESUME (continues the animation after a pause). While the state is eSTOP, nothing is shown. Likewise, when the prescribed number of cycles is finished no children will be selected for display. While the animation is running or when the animation ends (provided the number of cycles is not set to zero), it is still in the eSTART state the animation can be restarted by calling setState(sglAnimation::eSTART).

The subclasses of this node depend on either the current frame count or frame time that is stored in the sglScene node at the root of the scene graph containing this node. The frame count is incremented and the current frame time is determined each time sglScene::preDraw() is called. The different traversals use these values to realize the correct behaviour for these nodes so that it is necessary for the traversals to start at the sglScene node. If the state of this node has changed, it will be marked as dirty and the preDraw() traversal will set some member variables internal to this node. If this node is a member of more than one scene graph then proper behaviour is not guaranteed.

Special behaviour for intersect and pick traversals

The default behaviour of the intersect and pick traversals of the subclasses of this node is to test against the current child to be displayed based on the current frame count stored in the sglScene node at the root of the scene graph containing this node. The behaviour of the intersect and pick traversals of these nodes can be modified by adding sglProbe::eANIMATION_ALL or sglProbe::eANIMATION_NONE to the sglProbe mode. The former behaves as a normal sglGroup node testing against all the children, while the latter returns without testing against any children.

Definition at line 98 of file sglAnimation.hpp.


Member Enumeration Documentation

enum sglAnimation::ModeEnum
 

Controls the behaviour of the animation

Enumeration values:
eCYCLE   forward repeatedly.
eSWING   back and forth.

Definition at line 102 of file sglAnimation.hpp.

enum sglAnimation::StateEnum
 

The current state of the animation

Enumeration values:
eSTART   begin at child 0.
ePAUSE   stop at current child.
eRESUME   continue at current child.
eSTOP   stop and reset to child 0.

Definition at line 111 of file sglAnimation.hpp.


Constructor & Destructor Documentation

sglAnimation::sglAnimation ( )
 

default constructor.

sglAnimation::~sglAnimation ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglAnimation::setMode ( ModeEnum mode ) [inline]
 

Set the animation mode for this node to either eCYCLE (the default) or eSWING. When in eCYCLE mode, the children will be displayed in order from lowest index to highest, and repeat (if required) from lowest to highest. When in eSWING mode, the children will be displayed in order from lowest to highest and then reverse from highest to lowest (this entire cycle will be repeated if so configured. In swing mode the highest will only be displayed for its allotted time once before reversing direction.

Parameters:
mode   Either eCYCLE or eSWING.

Definition at line 139 of file sglAnimation.hpp.

ModeEnum sglAnimation::getMode ( ) const [inline]
 

Return the current animation mode.

Returns:
ModeEnum the current mode: either eCYCLE or eSWING.

Definition at line 144 of file sglAnimation.hpp.

bool sglAnimation::setState ( StateEnum state )
 

Change the state of the animation node. Any valid change here causes sets the ANIMATION dirty bit so that preDraw will do something to set up the animation. The current valid state changes are as follows: eSTART->eSTOP/ePAUSE, ePAUSE->eRESUME/eSTOP, eRESUME->eSTOP/ePAUSE, eSTOP->eSTART, and eSTART->eSTART. Note that is eRESUME is specified it will be changed to eSTART automatically during the preDraw traversal.

Parameters:
state   One of eSTART, ePAUSE, eRESUME, eSTOP
Returns:
true if the state change was valid; otherwise, false.

StateEnum sglAnimation::getState ( ) const [inline]
 

Get the current state of the node.

Returns:
state One of eSTART, ePAUSE, eRESUME, eSTOP.

Definition at line 160 of file sglAnimation.hpp.

void sglAnimation::setRange ( int first_node = 0,
int last_node = -1 )
 

This sets the range of nodes to display (by child index number). By passing no arguments, then the system reverts to the default of showing all children. If last_node is less than first_node, then they will be exchanged (reverse animations should be specified with a negative speed. Note that if the number of children of this node changes after a range is set and causes one or both of the range values to be invalid, it may lead to unspecified behaviour.

Parameters:
first_node   Index of first child to be displayed. If a number less than zero or greater then the highest child index (getNumChildren-1) is specified, then it will be set to the last child.
last_node   Index of last child to be displayed. If a number less than zero or greater than the highest child index is specified, then it will be set to the last child.

void sglAnimation::getRange ( unsigned int & first_node,
unsigned int & last_node ) const
 

Get the current range of children to be displayed. If the child list is empty then first_node will be set to zero and last_node will be set to MAX_UINT.

Parameters:
first_node   Index of first child to be displayed.
last_node   Index of last child to be displayed.

void sglAnimation::setSpeed ( float speed )
 

Set the speed of the animation relative to the durations set by the subclasses (the time that each child is shown, its duration, is divided by this value). A speed of zero disables the animation, a positive speed corresponds to a forward animation, and a negative speed reverses the animation. A speed with magnitude less than 1.0 will slow the animation down, while a magnitude greater than 1.0 will increase the speed.

Parameters:
speed   Speed of the animation (default is 1.0f).

float sglAnimation::getSpeed ( ) const
 

Get the current speed.

Returns:
current speed.

void sglAnimation::setNumCycles ( unsigned int num_cycles )
 

Set the number cycles this animations is supposed to perform. For the eCYCLE mode, a period consists of (child 0 ... child n-1). For the eSWING mode, a period consists of (child 0 ... child n-1 ... child 1). If the number cycles is set to zero, then the animation node will cycle continuously. After the specified number of cycles, the state will remain in eSTART/eRESUME (whichever it was in). And the user will have to change the state to eSTOP before typing start again.

Parameters:
num_cycles   Number of cycles to perform.

unsigned int sglAnimation::getNumCycles ( ) const [inline]
 

Get the current number of cycles.

Returns:
number of cycles.

Definition at line 217 of file sglAnimation.hpp.

virtual void sglAnimation::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglGroup.

Reimplemented in sglKeyFrameAnimation, and sglTimedAnimation.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001