llviewerjoystick.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @file llviewerjoystick.h
  3. * @brief Viewer joystick / NDOF device functionality.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWERJOYSTICK_H
  33. #define LL_LLVIEWERJOYSTICK_H
  34. #include "ndofdev_external.h"
  35. #include "llcontrol.h"
  36. typedef enum e_joystick_driver_state
  37. {
  38. JDS_UNINITIALIZED,
  39. JDS_INITIALIZED,
  40. JDS_INITIALIZING
  41. } EJoystickDriverState;
  42. class LLViewerJoystick final : public LLSingleton<LLViewerJoystick>
  43. {
  44. friend class LLSingleton<LLViewerJoystick>;
  45. protected:
  46. LOG_CLASS(LLViewerJoystick);
  47. public:
  48. LLViewerJoystick();
  49. ~LLViewerJoystick() override;
  50. void init(bool autoenable);
  51. void terminate();
  52. void updateStatus();
  53. void scanJoystick();
  54. void moveObjects(bool reset = false);
  55. void moveAvatar(bool reset = false);
  56. void moveFlycam(bool reset = false);
  57. std::string getDescription();
  58. F32 getJoystickAxis(S32 axis) const;
  59. bool getJoystickButton(S32 button) const;
  60. LL_INLINE bool isJoystickInitialized() const { return mDriverState == JDS_INITIALIZED; }
  61. bool isLikeSpaceNavigator() const;
  62. LL_INLINE void setNeedsReset(bool reset = true) { mResetFlag = reset; }
  63. LL_INLINE void setCameraNeedsUpdate(bool b) { mCameraUpdated = b; }
  64. LL_INLINE bool getCameraNeedsUpdate() const { return mCameraUpdated; }
  65. LL_INLINE bool getOverrideCamera() { return mOverrideCamera; }
  66. void setOverrideCamera(bool val);
  67. bool toggleFlycam();
  68. void setToDefaults();
  69. void setSNDefaults();
  70. protected:
  71. void updateEnabled(bool autoenable);
  72. void handleRun(F32 inc);
  73. void agentSlide(F32 inc);
  74. void agentPush(F32 inc);
  75. void agentFly(F32 inc);
  76. void agentRotate(F32 pitch_inc, F32 turn_inc);
  77. void agentJump();
  78. void resetDeltas(S32 axis[]);
  79. static NDOF_HotPlugResult hotPlugAddCallback(NDOF_Device* dev);
  80. static void hotPlugRemovalCallback(NDOF_Device* dev);
  81. private:
  82. LLCachedControl<bool> mJoystickEnabled;
  83. LLCachedControl<bool> mJoystickAvatarEnabled;
  84. LLCachedControl<bool> mJoystickFlycamEnabled;
  85. LLCachedControl<bool> mJoystickBuildEnabled;
  86. LLCachedControl<bool> mCursor3D;
  87. LLCachedControl<S32> mJoystickAxis0;
  88. LLCachedControl<S32> mJoystickAxis1;
  89. LLCachedControl<S32> mJoystickAxis2;
  90. LLCachedControl<S32> mJoystickAxis3;
  91. LLCachedControl<S32> mJoystickAxis4;
  92. LLCachedControl<S32> mJoystickAxis5;
  93. LLCachedControl<S32> mJoystickAxis6;
  94. NDOF_Device* mNdofDev;
  95. EJoystickDriverState mDriverState;
  96. F32 mPerfScale;
  97. U32 mJoystickRun;
  98. F32 mAxes[6];
  99. bool mBtn[16];
  100. bool mResetFlag;
  101. bool mCameraUpdated;
  102. bool mOverrideCamera;
  103. static F32 sLastDelta[7];
  104. static F32 sDelta[7];
  105. };
  106. #endif