SetControlConstraintsAction.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: setcontrolconstraintsaction.cpp
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Implementation of the training library "setcontrolconstraintsaction" interface.
  10. **
  11. ** History:
  12. */
  13. #include "pch.h"
  14. #include "SetControlConstraintsAction.h"
  15. namespace Training
  16. {
  17. //------------------------------------------------------------------------------
  18. // global variabes
  19. //------------------------------------------------------------------------------
  20. extern ControlData g_allowableControlScalars; // yaw, pitch, roll, throttle
  21. extern int g_iAllowableActionMask;
  22. //------------------------------------------------------------------------------
  23. // class methods
  24. //------------------------------------------------------------------------------
  25. /* void */ SetControlConstraintsAction::SetControlConstraintsAction (void)
  26. {
  27. // assign default values to the control masks
  28. m_inputControls.jsValues[c_axisYaw] = NA;
  29. m_inputControls.jsValues[c_axisPitch] = NA;
  30. m_inputControls.jsValues[c_axisRoll] = NA;
  31. m_inputControls.jsValues[c_axisThrottle] = NA;
  32. m_iEnableActionsMask = 0;
  33. m_iDisableActionsMask = 0;
  34. }
  35. //------------------------------------------------------------------------------
  36. /* void */ SetControlConstraintsAction::~SetControlConstraintsAction (void)
  37. {
  38. }
  39. //------------------------------------------------------------------------------
  40. void SetControlConstraintsAction::Execute (void)
  41. {
  42. // Set the control values
  43. if (m_inputControls.jsValues[c_axisYaw] != NA)
  44. g_allowableControlScalars.jsValues[c_axisYaw] = m_inputControls.jsValues[c_axisYaw];
  45. if (m_inputControls.jsValues[c_axisPitch] != NA)
  46. g_allowableControlScalars.jsValues[c_axisPitch] = m_inputControls.jsValues[c_axisPitch];
  47. if (m_inputControls.jsValues[c_axisRoll] != NA)
  48. g_allowableControlScalars.jsValues[c_axisRoll] = m_inputControls.jsValues[c_axisRoll];
  49. if (m_inputControls.jsValues[c_axisThrottle] != NA)
  50. g_allowableControlScalars.jsValues[c_axisThrottle] = m_inputControls.jsValues[c_axisThrottle];
  51. // Set the disabled control masks
  52. for (int i = 0; i < 32; i++)
  53. {
  54. int action = m_iDisableActionsMask & (1 << i);
  55. if (g_iAllowableActionMask & action)
  56. g_iAllowableActionMask ^= action;
  57. }
  58. // Set the enabled control masks
  59. g_iAllowableActionMask |= m_iEnableActionsMask;
  60. }
  61. //------------------------------------------------------------------------------
  62. void SetControlConstraintsAction::EnableInputAction (int iInputAction)
  63. {
  64. m_iEnableActionsMask |= iInputAction;
  65. for (int i = 0; i < 32; i++)
  66. {
  67. int action = m_iDisableActionsMask & (1 << i);
  68. if (iInputAction & action)
  69. m_iDisableActionsMask ^= action;
  70. }
  71. }
  72. //------------------------------------------------------------------------------
  73. void SetControlConstraintsAction::DisableInputAction (int iInputAction)
  74. {
  75. m_iDisableActionsMask |= iInputAction;
  76. for (int i = 0; i < 32; i++)
  77. {
  78. int action = m_iEnableActionsMask & (1 << i);
  79. if (iInputAction & action)
  80. m_iEnableActionsMask ^= action;
  81. }
  82. }
  83. //------------------------------------------------------------------------------
  84. void SetControlConstraintsAction::ScaleInputControl (Axis axis, float fScalar)
  85. {
  86. m_inputControls.jsValues[axis] = fScalar;
  87. }
  88. //------------------------------------------------------------------------------
  89. }