ControlState Class Reference

A control state is a set of values describing at any moment the state of switches (keys and buttons) and axis. More...

#include <Control.h>

List of all members.

Public Types

enum  ESwitchId {
  NONE = 0, FORWARD, BACKWARD, LEFT,
  RIGHT, STRAFE_LEFT, STRAFE_RIGHT, UP,
  DOWN, ROLL_LEFT, ROLL_RIGHT, JUMP,
  CROUCH, FAST_TOGGLE, ALWAYS_FAST, FASTER,
  SLOWER, FIRE1, FIRE2, FIRE3,
  FIRE4, FIRE5, WEAPON_NEXT, WEAPON_PREV,
  WEAPON_TOGGLE, WEAPON1, WEAPON2, WEAPON3,
  WEAPON4, WEAPON5, WEAPON6, WEAPON7,
  WEAPON8, WEAPON9, WEAPON10, WEAPON11,
  WEAPON12, WEAPON13, WEAPON14, WEAPON15,
  WEAPON16, WEAPON17, WEAPON18, WEAPON19,
  WEAPON20, DROP_WEAPON, DROP_ALTERNATE, TARGET,
  TARGET_NEXT, TARGET_PREV, SHOW_INFO, VIEW_NEXT,
  VIEW_PREV, ZOOM_IN, ZOOM_OUT, VIEW1,
  VIEW2, VIEW3, VIEW4, VIEW5,
  VIEW6, VIEW7, VIEW8, VIEW9,
  VIEW10, VIEW11, VIEW12, VIEW13,
  VIEW14, VIEW15, PAUSE, SCREENSHOT,
  TOGGLE_FULLSCREEN, BRAKE, RESET, MENU,
  SCORE_MENU, OK, CANCEL, MAX_STARNDARD_SWITCH,
  USER_SWITCH_0 = MAX_STARNDARD_SWITCH, MAX_SWITCH = USER_SWITCH_0 + NB_USER_SWITCHES
}
 Switches enum, containing 'standard' switches and room for custom (user's) ones. More...
enum  EAxisId {
  AXIS_X = 0, AXIS_Y, AXIS_Z, AXIS_SCROLL_1,
  AXIS_SCROLL_2, AXIS_SCROLL_3, AXIS_SCROLL_4, MAX_AXIS
}
 Remember to update the textual representation (axisNames in the .cpp) of this enum when modyfing ! More...

Public Member Functions

 ControlState ()
ControlStateoperator+= (ESwitchId switchId)
 Convinience operator, same as set(switchId).
ControlStateoperator-= (ESwitchId switchId)
 Convinience operator, same as reset(switchId).
bool operator[] (ESwitchId switchId) const
 Convinience operator, same as get(switchId).
void set (ESwitchId switchId)
 Sets a switch to be enabled.
void reset (ESwitchId switchId)
 Sets a switch to be disabled.
bool get (ESwitchId switchId) const
 Gets the state of a switch.
void resetAllSwitches ()
 Resets all switches.
void setAxis (EAxisId axis, float val)
 Sets an axis to a value.
void addToAxis (EAxisId axis, float val)
 Adds a value to an axis' current value.
float getAxis (EAxisId axis) const
 Gets an axis value.
void resetAxis (EAxisId axis)
 Same as setAxis(axis, 0).
void resetAllAxis ()
 Same as resetAxis() for all axis.
bool isAxisZero (EAxisId axis, float epsilon=0.0001f)
 Tests an axis for zero equality (with an epsilon).
bool testAnySwitchOn () const
 Very quickly tests (O(1)) if any switch is on (false means all switches are reset).
bool testAnyAxisOn (float epsilon=1e-4f) const
 Tests each axis (O(MAX_AXIS)) to see if anyone is non zero (Thus false means that all axis are reset).
bool testAnyControlOn (float epsilon=0.0001f) const
 Convinience method that returns testAnySwitchOn() || testAnyAxisOn(epsilon).
void setPointer (float pointerX, float pointerY)
 Sets the pointer to be at a given position (does not actually moves the system pointer, but changes the coordinates stored in the class).
void setPointer (const osg::Vec3f &pointer)
osg::Vec3f getPointer () const
 Gets the pointer position.
float getPointerX () const
 Convinience method to get the pointer X position.
float getPointerY () const
 Convinience method to get the pointer Y position.
osg::Vec3f getPickPosition () const
 Gets the pointer pick position.
void setPickPosition (const osg::Vec3f &pickPos)
 Sets the pointer pick position.

Static Public Attributes

static const UINT NB_USER_SWITCHES = 30
 Maximum number of custom (user's) switches. These custom swithces are defined by the application.

Protected Attributes

UINT nbSwitchesOn
std::bitset< MAX_SWITCH > vSwitchs
float pAxis [MAX_AXIS]
osg::Vec3f pointer
osg::Vec3f pickPos


Detailed Description

A control state is a set of values describing at any moment the state of switches (keys and buttons) and axis.

Used by piloting interfaces and IA interfaces, so they only know about controls, not inputs.

Author:
Sukender

Definition at line 42 of file Control.h.


Member Enumeration Documentation

Remember to update the textual representation (axisNames in the .cpp) of this enum when modyfing !

Enumerator:
AXIS_X 
AXIS_Y 
AXIS_Z 
AXIS_SCROLL_1 
AXIS_SCROLL_2 
AXIS_SCROLL_3 
AXIS_SCROLL_4 
MAX_AXIS 

Definition at line 81 of file Control.h.

Switches enum, containing 'standard' switches and room for custom (user's) ones.

This enum declares the switches that are considered to be 'common'. To use your own custom switches, just give textual representation to functions that need it (like loadBindings()). Of course, you may want to create an enum in your application that describes those switches. In that case, be sure to set the fisrt value to USER_SWITCH_0 and not create more than NB_USER_SWITCHES switches. Remember to update the textual representation (switchesNames in the .cpp) of this enum when modyfing !

Enumerator:
NONE  Special switch, wiche means "no switch" or "unmapped switch".
FORWARD 
BACKWARD 
LEFT 
RIGHT 
STRAFE_LEFT 
STRAFE_RIGHT 
UP 
DOWN 
ROLL_LEFT 
ROLL_RIGHT 
JUMP 
CROUCH 
FAST_TOGGLE 
ALWAYS_FAST 
FASTER 
SLOWER 
FIRE1 
FIRE2 
FIRE3 
FIRE4 
FIRE5 
WEAPON_NEXT 
WEAPON_PREV 
WEAPON_TOGGLE 
WEAPON1 
WEAPON2 
WEAPON3 
WEAPON4 
WEAPON5 
WEAPON6 
WEAPON7 
WEAPON8 
WEAPON9 
WEAPON10 
WEAPON11 
WEAPON12 
WEAPON13 
WEAPON14 
WEAPON15 
WEAPON16 
WEAPON17 
WEAPON18 
WEAPON19 
WEAPON20 
DROP_WEAPON 
DROP_ALTERNATE 
TARGET 
TARGET_NEXT 
TARGET_PREV 
SHOW_INFO 
VIEW_NEXT 
VIEW_PREV 
ZOOM_IN 
ZOOM_OUT 
VIEW1 
VIEW2 
VIEW3 
VIEW4 
VIEW5 
VIEW6 
VIEW7 
VIEW8 
VIEW9 
VIEW10 
VIEW11 
VIEW12 
VIEW13 
VIEW14 
VIEW15 
PAUSE 
SCREENSHOT 
TOGGLE_FULLSCREEN 
BRAKE 
RESET 
MENU 
SCORE_MENU 
OK 
CANCEL 
MAX_STARNDARD_SWITCH  Latest+1 'common' switch.
USER_SWITCH_0  First user-defined (= 'custom') switch.
MAX_SWITCH  Last user-defined switch+1 available.

Definition at line 50 of file Control.h.


Constructor & Destructor Documentation

ControlState::ControlState (  ) 

Definition at line 48 of file Control.cpp.

References resetAllAxis(), and resetAllSwitches().


Member Function Documentation

void ControlState::addToAxis ( EAxisId  axis,
float  val 
) [inline]

Adds a value to an axis' current value.

Definition at line 108 of file Control.h.

References ASSERT.

Referenced by Controler::axisMove().

bool ControlState::get ( ESwitchId  switchId  )  const [inline]

Gets the state of a switch.

Definition at line 101 of file Control.h.

float ControlState::getAxis ( EAxisId  axis  )  const [inline]

Gets an axis value.

Definition at line 110 of file Control.h.

References ASSERT.

Referenced by HumanMatrixGetter::handleFrame().

osg::Vec3f ControlState::getPickPosition (  )  const [inline]

Gets the pointer pick position.

The pick position is a 3D point where the mouse "points to"; that is to say the intersection between the half-line [Camera; mouse pointer) and an object.

See also:
setPickPosition()

Definition at line 147 of file Control.h.

osg::Vec3f ControlState::getPointer (  )  const [inline]

Gets the pointer position.

Definition at line 137 of file Control.h.

float ControlState::getPointerX (  )  const [inline]

Convinience method to get the pointer X position.

See also:
getPointer()

Definition at line 140 of file Control.h.

Referenced by ControlMapper::computePickPos().

float ControlState::getPointerY (  )  const [inline]

Convinience method to get the pointer Y position.

See also:
getPointer()

Definition at line 143 of file Control.h.

Referenced by ControlMapper::computePickPos().

bool ControlState::isAxisZero ( EAxisId  axis,
float  epsilon = 0.0001f 
) [inline]

Tests an axis for zero equality (with an epsilon).

Definition at line 116 of file Control.h.

References ASSERT.

ControlState& ControlState::operator+= ( ESwitchId  switchId  )  [inline]

Convinience operator, same as set(switchId).

Definition at line 90 of file Control.h.

ControlState& ControlState::operator-= ( ESwitchId  switchId  )  [inline]

Convinience operator, same as reset(switchId).

Definition at line 92 of file Control.h.

bool ControlState::operator[] ( ESwitchId  switchId  )  const [inline]

Convinience operator, same as get(switchId).

Definition at line 94 of file Control.h.

void ControlState::reset ( ESwitchId  switchId  )  [inline]

Sets a switch to be disabled.

Definition at line 99 of file Control.h.

References ASSERT.

void ControlState::resetAllAxis (  ) 

Same as resetAxis() for all axis.

Definition at line 46 of file Control.cpp.

References MAX_AXIS, and pAxis.

Referenced by Controler::clear(), Controler::clearAxis(), and ControlState().

void ControlState::resetAllSwitches (  )  [inline]

Resets all switches.

Definition at line 103 of file Control.h.

Referenced by ControlState().

void ControlState::resetAxis ( EAxisId  axis  )  [inline]

Same as setAxis(axis, 0).

Definition at line 112 of file Control.h.

References ASSERT.

void ControlState::set ( ESwitchId  switchId  )  [inline]

Sets a switch to be enabled.

Definition at line 97 of file Control.h.

void ControlState::setAxis ( EAxisId  axis,
float  val 
) [inline]

Sets an axis to a value.

Definition at line 106 of file Control.h.

References ASSERT.

void ControlState::setPickPosition ( const osg::Vec3f &  pickPos  )  [inline]

Sets the pointer pick position.

See also:
getPickPosition()

Definition at line 150 of file Control.h.

Referenced by ControlMapper::computePickPos().

void ControlState::setPointer ( const osg::Vec3f &  pointer  )  [inline]

Sets the pointer to be at a given position (does not actually moves the system pointer, but changes the coordinates stored in the class).

Definition at line 135 of file Control.h.

void ControlState::setPointer ( float  pointerX,
float  pointerY 
) [inline]

Sets the pointer to be at a given position (does not actually moves the system pointer, but changes the coordinates stored in the class).

Definition at line 133 of file Control.h.

Referenced by ControlMapper::handle().

bool ControlState::testAnyAxisOn ( float  epsilon = 1e-4f  )  const [inline]

Tests each axis (O(MAX_AXIS)) to see if anyone is non zero (Thus false means that all axis are reset).

Parameters:
epsilon Allowed error

Definition at line 123 of file Control.h.

bool ControlState::testAnyControlOn ( float  epsilon = 0.0001f  )  const [inline]

Convinience method that returns testAnySwitchOn() || testAnyAxisOn(epsilon).

Definition at line 130 of file Control.h.

bool ControlState::testAnySwitchOn (  )  const [inline]

Very quickly tests (O(1)) if any switch is on (false means all switches are reset).

Definition at line 119 of file Control.h.


Member Data Documentation

const UINT ControlState::NB_USER_SWITCHES = 30 [static]

Maximum number of custom (user's) switches. These custom swithces are defined by the application.

Definition at line 44 of file Control.h.

Referenced by loadBindings(), and saveBindings().

Definition at line 153 of file Control.h.

float ControlState::pAxis[MAX_AXIS] [protected]

Definition at line 155 of file Control.h.

Referenced by resetAllAxis().

osg::Vec3f ControlState::pickPos [protected]

Definition at line 157 of file Control.h.

osg::Vec3f ControlState::pointer [protected]

Definition at line 156 of file Control.h.

std::bitset<MAX_SWITCH> ControlState::vSwitchs [protected]

Definition at line 154 of file Control.h.


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

Generated on Sun Jan 17 11:39:27 2010 for PVLE (Pro-Vocation Light Engine) by  doxygen 1.5.9