llheadrotmotion.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * @file llheadrotmotion.h
  3. * @brief Implementation of LLHeadRotMotion class.
  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_LLHEADROTMOTION_H
  33. #define LL_LLHEADROTMOTION_H
  34. #include "llframetimer.h"
  35. #include "llmotion.h"
  36. #define MIN_REQUIRED_PIXEL_AREA_HEAD_ROT 500.f;
  37. #define MIN_REQUIRED_PIXEL_AREA_EYE 25000.f;
  38. class LLHeadRotMotion final : public LLMotion
  39. {
  40. protected:
  41. LOG_CLASS(LLHeadRotMotion);
  42. public:
  43. LLHeadRotMotion(const LLUUID& id);
  44. LL_INLINE static LLMotion* create(const LLUUID& id) { return new LLHeadRotMotion(id); }
  45. // Motions must specify whether or not they loop
  46. LL_INLINE bool getLoop() override { return true; }
  47. // Motions must report their total duration
  48. LL_INLINE F32 getDuration() override { return 0.f; }
  49. // Motions must report their "ease in" duration
  50. LL_INLINE F32 getEaseInDuration() override { return 1.f; }
  51. // Motions must report their "ease out" duration.
  52. LL_INLINE F32 getEaseOutDuration() override { return 1.f; }
  53. // Called to determine when a motion should be activated/deactivated based
  54. // on avatar pixel coverage
  55. LL_INLINE F32 getMinPixelArea() override { return MIN_REQUIRED_PIXEL_AREA_HEAD_ROT; }
  56. // Motions must report their priority
  57. LL_INLINE LLJoint::JointPriority getPriority() override { return LLJoint::MEDIUM_PRIORITY; }
  58. LL_INLINE LLMotionBlendType getBlendType() override { return NORMAL_BLEND; }
  59. // Run-time (post constructor) initialization, called after parameters have
  60. // been set. Must return true to indicate success and be available for
  61. // activation.
  62. LLMotionInitStatus onInitialize(LLCharacter* character) override;
  63. // Called when a motion is activated. Must return true to indicate success,
  64. // or else it will be deactivated.
  65. LL_INLINE bool onActivate() override { return true; }
  66. // Called per time step. Must return true while it is active, and must
  67. // return false when the motion is completed.
  68. bool onUpdate(F32 time, U8* joint_mask) override;
  69. // Called when a motion is deactivated
  70. LL_INLINE void onDeactivate() override {}
  71. // Expose enabled status so the effects of this motion can be turned on/off
  72. // independently of its active state.
  73. LL_INLINE void enable() override { mEnabled = true; }
  74. LL_INLINE void disable() override { mEnabled = false; }
  75. LL_INLINE bool isEnabled() const override { return mEnabled; }
  76. public:
  77. LLCharacter* mCharacter;
  78. LLJoint* mTorsoJoint;
  79. LLJoint* mHeadJoint;
  80. LLJoint* mRootJoint;
  81. LLJoint* mPelvisJoint;
  82. // Joint states to be animated
  83. LLPointer<LLJointState> mTorsoState;
  84. LLPointer<LLJointState> mNeckState;
  85. LLPointer<LLJointState> mHeadState;
  86. LLQuaternion mLastHeadRot;
  87. bool mEnabled;
  88. };
  89. class LLEyeMotion final : public LLMotion
  90. {
  91. protected:
  92. LOG_CLASS(LLEyeMotion);
  93. public:
  94. LLEyeMotion(const LLUUID& id);
  95. LL_INLINE static LLMotion* create(const LLUUID& id) { return new LLEyeMotion(id); }
  96. // Motions must specify whether or not they loop
  97. LL_INLINE bool getLoop() override { return true; }
  98. // Motions must report their total duration
  99. LL_INLINE F32 getDuration() override { return 0.f; }
  100. // Motions must report their "ease in" duration
  101. LL_INLINE F32 getEaseInDuration() override { return 0.5f; }
  102. // Motions must report their "ease out" duration.
  103. LL_INLINE F32 getEaseOutDuration() override { return 0.5f; }
  104. // Called to determine when a motion should be activated/deactivated based
  105. // on avatar pixel coverage
  106. LL_INLINE F32 getMinPixelArea() override { return MIN_REQUIRED_PIXEL_AREA_EYE; }
  107. // Motions must report their priority
  108. LL_INLINE LLJoint::JointPriority getPriority() override { return LLJoint::MEDIUM_PRIORITY; }
  109. LL_INLINE LLMotionBlendType getBlendType() override { return NORMAL_BLEND; }
  110. // Run-time (post constructor) initialization, called after parameters have
  111. // been set. Must return true to indicate success and be available for
  112. // activation.
  113. LLMotionInitStatus onInitialize(LLCharacter* character) override;
  114. // Called when a motion is activated. Must return true to indicate success,
  115. // or else it will be deactivated.
  116. LL_INLINE bool onActivate() override { return true; }
  117. void adjustEyeTarget(LLVector3* target_pos, LLJointState& left_eye_state,
  118. LLJointState& right_eye_state);
  119. // Called per time step must return true while it is active, and must
  120. // return false when the motion is completed.
  121. bool onUpdate(F32 time, U8* joint_mask) override;
  122. // Called when a motion is deactivated
  123. void onDeactivate() override;
  124. public:
  125. LLCharacter* mCharacter;
  126. LLJoint* mHeadJoint;
  127. // Joint states to be animated
  128. LLPointer<LLJointState> mLeftEyeState;
  129. LLPointer<LLJointState> mAltLeftEyeState;
  130. LLPointer<LLJointState> mRightEyeState;
  131. LLPointer<LLJointState> mAltRightEyeState;
  132. LLFrameTimer mEyeJitterTimer;
  133. F32 mEyeJitterTime;
  134. F32 mEyeJitterYaw;
  135. F32 mEyeJitterPitch;
  136. F32 mEyeLookAwayTime;
  137. F32 mEyeLookAwayYaw;
  138. F32 mEyeLookAwayPitch;
  139. // Eye blinking
  140. LLFrameTimer mEyeBlinkTimer;
  141. F32 mEyeBlinkTime;
  142. bool mEyesClosed;
  143. };
  144. #endif // LL_LLHEADROTMOTION_H