renderstack::control Class Reference

value control that can be updated over time

#include <control.hpp>

Public Member Functions

 control ()
void clear ()
void update ()
void adjust (float delta)
void dampen ()
void more (bool apply)
void less (bool apply)
void stop (bool apply)
void inhibit (bool apply)
void set_max_delta (float max_delta)
void set_damp (float damp)
float current_delta () const
float current_value () const

Static Protected Attributes

static const int bit_more = 1
static const int bit_less = 2
static const int bit_stop = 4
static const int bit_active = 8
static const int bit_inhibit = 16
static const int bit_dampen_linear = 32
static const int bit_dampen_multiply = 64
static const int bit_dampen_master = 128
static const int bitmask_clear = bit_more | bit_less | bit_stop | bit_active | bit_inhibit

Detailed Description

Definition at line 38 of file control.hpp.


Constructor & Destructor Documentation

renderstack::control::control (  ) 

Definition at line 193 of file control.cpp.

00194 {
00195     clear();
00196 }


Member Function Documentation

void renderstack::control::clear (  ) 

Definition at line 198 of file control.cpp.

00199 {
00200     m_damp           =  0.950f;
00201     m_max_delta      =  0.004f;
00202     m_max_value      =  1.000f;
00203     m_min_value      = -1.000f;
00204     m_current_delta  = 0;
00205     m_current_value  = 0;
00206     m_options       &= ~bitmask_clear;
00207     m_options       |=  bit_dampen_multiply;
00208 }

void renderstack::control::update (  ) 

Definition at line 32 of file control.cpp.

00033 {
00034     if(
00035         ((m_options & bit_active ) == bit_active) &&
00036         ((m_options & bit_inhibit) == 0         )
00037     )
00038     {
00039         adjust(m_current_delta);
00040     }
00041     dampen();
00042 }

void renderstack::control::adjust ( float  delta  ) 

Definition at line 44 of file control.cpp.

00045 {
00046     m_current_value += delta;
00047 
00048     if(m_current_value > m_max_value)
00049     {
00050         m_current_value = m_max_value;
00051     }
00052     else if(m_current_value < m_min_value)
00053     {
00054         m_current_value = m_min_value;
00055     }
00056 }

void renderstack::control::dampen (  ) 

Definition at line 58 of file control.cpp.

00059 {
00060     if(
00061         (m_options & bit_dampen_multiply) == bit_dampen_multiply
00062     )
00063     {
00064         float old_value = m_current_value;
00065         m_current_value = m_current_value * m_damp;
00066         if(m_current_value == old_value)
00067         {
00068             m_current_value = 0;
00069         }
00070     }
00071     else if(
00072         ((m_options & bit_dampen_linear) == bit_dampen_linear) &&
00073         ((m_options & bit_active       ) == 0                )
00074     )
00075 
00076     {
00077         if(m_current_value > m_max_delta)
00078         {
00079             m_current_value -= m_max_delta;
00080             if(m_current_value < m_max_delta)
00081             {
00082                 m_current_value = 0;
00083             }
00084         }
00085         else if(m_current_value < -m_max_delta)
00086         {
00087             m_current_value += m_max_delta;
00088             if(m_current_value > -m_max_delta)
00089             {
00090                 m_current_value = 0;
00091             }
00092         }
00093         else
00094         {
00095             m_current_value *= m_damp;
00096         }
00097     }
00098 }

void renderstack::control::more ( bool  apply  ) 

Definition at line 100 of file control.cpp.

00101 {
00102     if(apply)
00103     {
00104         m_options       |= bit_more | bit_active;
00105         m_current_delta  = m_max_delta;
00106     }
00107     else
00108     {
00109         m_options &= ~bit_more;
00110         if(
00111             (m_options & bit_less) == bit_less
00112         )
00113         {
00114             m_current_delta = -m_max_delta;
00115         }
00116         else
00117         {
00118             m_options       &= ~bit_active;
00119             m_current_delta  = 0;
00120         }
00121     }
00122 }

void renderstack::control::less ( bool  apply  ) 

Definition at line 124 of file control.cpp.

00125 {
00126     if(apply)
00127     {
00128         m_options       |= bit_less | bit_active;
00129         m_current_delta  = -m_max_delta;
00130     }
00131     else
00132     {
00133         m_options &= ~bit_less;
00134         if(
00135             (m_options & bit_more) == bit_more)
00136         {
00137             m_current_delta = m_max_delta;
00138         }
00139         else
00140         {
00141             m_options       &= ~bit_active;
00142             m_current_delta  = 0;
00143         }
00144     }
00145 }

void renderstack::control::stop ( bool  apply  ) 

Definition at line 159 of file control.cpp.

00160 {
00161     if(apply)
00162     {
00163         m_options |= bit_stop;
00164         if(m_current_value > 0)
00165         {
00166             m_current_delta = -m_max_delta;
00167         }
00168         else if(m_current_value < 0)
00169         {
00170             m_current_delta = m_max_delta;
00171         }
00172     }
00173     else
00174     {
00175         m_options &= ~bit_stop;
00176         if(
00177             ((m_options & bit_less) == bit_less) &&
00178             ((m_options & bit_more) == 0       )
00179         )
00180         {
00181             m_current_delta = -m_max_delta;
00182         }
00183         else if(
00184             ((m_options & bit_less) == 0       ) &&
00185             ((m_options & bit_more) == bit_more)
00186         )
00187         {
00188             m_current_delta = m_max_delta;
00189         }
00190     }
00191 }

void renderstack::control::inhibit ( bool  apply  ) 

Definition at line 147 of file control.cpp.

00148 {
00149     if(apply)
00150     {
00151         m_options |= bit_inhibit;
00152     }
00153     else
00154     {
00155         m_options &= ~bit_inhibit;
00156     }
00157 }

void renderstack::control::set_max_delta ( float  max_delta  )  [inline]

Definition at line 63 of file control.hpp.

00063 { m_max_delta = max_delta; }

void renderstack::control::set_damp ( float  damp  )  [inline]

Definition at line 64 of file control.hpp.

00064 { m_damp = damp; }

float renderstack::control::current_delta (  )  const [inline]

Definition at line 66 of file control.hpp.

00066 { return m_current_delta; }

float renderstack::control::current_value (  )  const [inline]

Definition at line 67 of file control.hpp.

00067 { return m_current_value; }


Field Documentation

const int renderstack::control::bit_more = 1 [static, protected]

Definition at line 41 of file control.hpp.

const int renderstack::control::bit_less = 2 [static, protected]

Definition at line 42 of file control.hpp.

const int renderstack::control::bit_stop = 4 [static, protected]

Definition at line 43 of file control.hpp.

const int renderstack::control::bit_active = 8 [static, protected]

Definition at line 44 of file control.hpp.

const int renderstack::control::bit_inhibit = 16 [static, protected]

Definition at line 45 of file control.hpp.

const int renderstack::control::bit_dampen_linear = 32 [static, protected]

Definition at line 46 of file control.hpp.

const int renderstack::control::bit_dampen_multiply = 64 [static, protected]

Definition at line 47 of file control.hpp.

const int renderstack::control::bit_dampen_master = 128 [static, protected]

Definition at line 48 of file control.hpp.

Definition at line 49 of file control.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:11 2010 for RenderStack by  doxygen 1.6.3