llmotion.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @file llmotion.cpp
  3. * @brief Implementation of LLMotion 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. #include "linden_common.h"
  33. #include "llmotion.h"
  34. #include "llcriticaldamp.h"
  35. LLMotion::LLMotion(const LLUUID &id)
  36. : mStopped(true),
  37. mActive(false),
  38. mID(id),
  39. mActivationTimestamp(0.f),
  40. mStopTimestamp(0.f),
  41. mSendStopTimestamp(F32_MAX),
  42. mResidualWeight(0.f),
  43. mFadeWeight(1.f),
  44. mDeactivateCallback(NULL),
  45. mDeactivateCallbackUserData(NULL)
  46. {
  47. for (S32 i = 0; i < 3; ++i)
  48. {
  49. memset(&mJointSignature[i][0], 0,
  50. sizeof(U8) * LL_CHARACTER_MAX_ANIMATED_JOINTS);
  51. }
  52. }
  53. void LLMotion::fadeOut()
  54. {
  55. if (mFadeWeight > 0.01f)
  56. {
  57. mFadeWeight = lerp(mFadeWeight, 0.f, LLCriticalDamp::getInterpolant(0.15f));
  58. }
  59. else
  60. {
  61. mFadeWeight = 0.f;
  62. }
  63. }
  64. void LLMotion::fadeIn()
  65. {
  66. if (mFadeWeight < 0.99f)
  67. {
  68. mFadeWeight = lerp(mFadeWeight, 1.f,
  69. LLCriticalDamp::getInterpolant(0.15f));
  70. }
  71. else
  72. {
  73. mFadeWeight = 1.f;
  74. }
  75. }
  76. void LLMotion::addJointState(const LLPointer<LLJointState>& joint_state)
  77. {
  78. mPose.addJointState(joint_state);
  79. S32 priority = joint_state->getPriority();
  80. if (priority == LLJoint::USE_MOTION_PRIORITY)
  81. {
  82. priority = getPriority();
  83. }
  84. U32 usage = joint_state->getUsage();
  85. // For now, usage is everything
  86. S32 joint_num = joint_state->getJoint()->getJointNum();
  87. if (joint_num < 0 || joint_num >= (S32)LL_CHARACTER_MAX_ANIMATED_JOINTS)
  88. {
  89. LL_DEBUGS("Avatar") << "Joint number (" << joint_num
  90. << ") is outside of the legal range [0-"
  91. << LL_CHARACTER_MAX_ANIMATED_JOINTS << "]"
  92. << LL_ENDL;
  93. }
  94. mJointSignature[0][joint_num] = (usage & LLJointState::POS) ? (0xff >> (7 - priority)) : 0;
  95. mJointSignature[1][joint_num] = (usage & LLJointState::ROT) ? (0xff >> (7 - priority)) : 0;
  96. mJointSignature[2][joint_num] = (usage & LLJointState::SCALE) ? (0xff >> (7 - priority)) : 0;
  97. }
  98. void LLMotion::setDeactivateCallback(void (*cb)(void*), void* userdata)
  99. {
  100. mDeactivateCallback = cb;
  101. mDeactivateCallbackUserData = userdata;
  102. }
  103. //virtual
  104. void LLMotion::setStopTime(F32 time)
  105. {
  106. mStopTimestamp = time;
  107. mStopped = true;
  108. }
  109. bool LLMotion::isBlending() const
  110. {
  111. return mPose.getWeight() < 1.f;
  112. }
  113. void LLMotion::activate(F32 time)
  114. {
  115. mActivationTimestamp = time;
  116. mStopped = false;
  117. mActive = true;
  118. onActivate();
  119. }
  120. void LLMotion::deactivate()
  121. {
  122. mActive = false;
  123. mPose.setWeight(0.f);
  124. if (mDeactivateCallback)
  125. {
  126. (*mDeactivateCallback)(mDeactivateCallbackUserData);
  127. mDeactivateCallback = NULL; // only call callback once
  128. mDeactivateCallbackUserData = NULL;
  129. }
  130. onDeactivate();
  131. }