PageRenderTime 42ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcharacter/llmotion.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 171 lines | 93 code | 19 blank | 59 comment | 6 complexity | e05ec8677a694aca7c6e7348227abb50 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmotion.cpp
  3. * @brief Implementation of LLMotion class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. //-----------------------------------------------------------------------------
  27. // Header Files
  28. //-----------------------------------------------------------------------------
  29. #include "linden_common.h"
  30. #include "llmotion.h"
  31. #include "llcriticaldamp.h"
  32. //-----------------------------------------------------------------------------
  33. //-----------------------------------------------------------------------------
  34. // LLMotion class
  35. //-----------------------------------------------------------------------------
  36. //-----------------------------------------------------------------------------
  37. //-----------------------------------------------------------------------------
  38. // LLMotion()
  39. // Class Constructor
  40. //-----------------------------------------------------------------------------
  41. LLMotion::LLMotion( const LLUUID &id ) :
  42. mStopped(TRUE),
  43. mActive(FALSE),
  44. mID(id),
  45. mActivationTimestamp(0.f),
  46. mStopTimestamp(0.f),
  47. mSendStopTimestamp(F32_MAX),
  48. mResidualWeight(0.f),
  49. mFadeWeight(1.f),
  50. mDeactivateCallback(NULL),
  51. mDeactivateCallbackUserData(NULL)
  52. {
  53. for (int i=0; i<3; ++i)
  54. memset(&mJointSignature[i][0], 0, sizeof(U8) * LL_CHARACTER_MAX_JOINTS);
  55. }
  56. //-----------------------------------------------------------------------------
  57. // ~LLMotion()
  58. // Class Destructor
  59. //-----------------------------------------------------------------------------
  60. LLMotion::~LLMotion()
  61. {
  62. }
  63. //-----------------------------------------------------------------------------
  64. // fadeOut()
  65. //-----------------------------------------------------------------------------
  66. void LLMotion::fadeOut()
  67. {
  68. if (mFadeWeight > 0.01f)
  69. {
  70. mFadeWeight = lerp(mFadeWeight, 0.f, LLCriticalDamp::getInterpolant(0.15f));
  71. }
  72. else
  73. {
  74. mFadeWeight = 0.f;
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // fadeIn()
  79. //-----------------------------------------------------------------------------
  80. void LLMotion::fadeIn()
  81. {
  82. if (mFadeWeight < 0.99f)
  83. {
  84. mFadeWeight = lerp(mFadeWeight, 1.f, LLCriticalDamp::getInterpolant(0.15f));
  85. }
  86. else
  87. {
  88. mFadeWeight = 1.f;
  89. }
  90. }
  91. //-----------------------------------------------------------------------------
  92. // addJointState()
  93. //-----------------------------------------------------------------------------
  94. void LLMotion::addJointState(const LLPointer<LLJointState>& jointState)
  95. {
  96. mPose.addJointState(jointState);
  97. S32 priority = jointState->getPriority();
  98. if (priority == LLJoint::USE_MOTION_PRIORITY)
  99. {
  100. priority = getPriority();
  101. }
  102. U32 usage = jointState->getUsage();
  103. // for now, usage is everything
  104. mJointSignature[0][jointState->getJoint()->getJointNum()] = (usage & LLJointState::POS) ? (0xff >> (7 - priority)) : 0;
  105. mJointSignature[1][jointState->getJoint()->getJointNum()] = (usage & LLJointState::ROT) ? (0xff >> (7 - priority)) : 0;
  106. mJointSignature[2][jointState->getJoint()->getJointNum()] = (usage & LLJointState::SCALE) ? (0xff >> (7 - priority)) : 0;
  107. }
  108. void LLMotion::setDeactivateCallback( void (*cb)(void *), void* userdata )
  109. {
  110. mDeactivateCallback = cb;
  111. mDeactivateCallbackUserData = userdata;
  112. }
  113. //virtual
  114. void LLMotion::setStopTime(F32 time)
  115. {
  116. mStopTimestamp = time;
  117. mStopped = TRUE;
  118. }
  119. BOOL LLMotion::isBlending()
  120. {
  121. return mPose.getWeight() < 1.f;
  122. }
  123. //-----------------------------------------------------------------------------
  124. // activate()
  125. //-----------------------------------------------------------------------------
  126. void LLMotion::activate(F32 time)
  127. {
  128. mActivationTimestamp = time;
  129. mStopped = FALSE;
  130. mActive = TRUE;
  131. onActivate();
  132. }
  133. //-----------------------------------------------------------------------------
  134. // deactivate()
  135. //-----------------------------------------------------------------------------
  136. void LLMotion::deactivate()
  137. {
  138. mActive = FALSE;
  139. mPose.setWeight(0.f);
  140. if (mDeactivateCallback)
  141. {
  142. (*mDeactivateCallback)(mDeactivateCallbackUserData);
  143. mDeactivateCallback = NULL; // only call callback once
  144. mDeactivateCallbackUserData = NULL;
  145. }
  146. onDeactivate();
  147. }
  148. BOOL LLMotion::canDeprecate()
  149. {
  150. return TRUE;
  151. }
  152. // End