PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcharacter/llkeyframefallmotion.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 144 lines | 64 code | 23 blank | 57 comment | 7 complexity | d1f9735eac8cd355cc310ee634411f28 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llkeyframefallmotion.cpp
  3. * @brief Implementation of LLKeyframeFallMotion 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 "llkeyframefallmotion.h"
  31. #include "llcharacter.h"
  32. #include "m3math.h"
  33. //-----------------------------------------------------------------------------
  34. // Macros
  35. //-----------------------------------------------------------------------------
  36. #define GO_TO_KEY_POSE 1
  37. #define MIN_TRACK_SPEED 0.01f
  38. //-----------------------------------------------------------------------------
  39. // LLKeyframeFallMotion()
  40. // Class Constructor
  41. //-----------------------------------------------------------------------------
  42. LLKeyframeFallMotion::LLKeyframeFallMotion(const LLUUID &id) : LLKeyframeMotion(id)
  43. {
  44. mVelocityZ = 0.f;
  45. mCharacter = NULL;
  46. }
  47. //-----------------------------------------------------------------------------
  48. // ~LLKeyframeFallMotion()
  49. // Class Destructor
  50. //-----------------------------------------------------------------------------
  51. LLKeyframeFallMotion::~LLKeyframeFallMotion()
  52. {
  53. }
  54. //-----------------------------------------------------------------------------
  55. // LLKeyframeFallMotion::onInitialize()
  56. //-----------------------------------------------------------------------------
  57. LLMotion::LLMotionInitStatus LLKeyframeFallMotion::onInitialize(LLCharacter *character)
  58. {
  59. // save character pointer for later use
  60. mCharacter = character;
  61. // load keyframe data, setup pose and joint states
  62. LLMotion::LLMotionInitStatus result = LLKeyframeMotion::onInitialize(character);
  63. for (U32 jm=0; jm<mJointMotionList->getNumJointMotions(); jm++)
  64. {
  65. if (!mJointStates[jm]->getJoint())
  66. continue;
  67. if (mJointStates[jm]->getJoint()->getName() == std::string("mPelvis"))
  68. {
  69. mPelvisState = mJointStates[jm];
  70. }
  71. }
  72. return result;
  73. }
  74. //-----------------------------------------------------------------------------
  75. // LLKeyframeFallMotion::onActivate()
  76. //-----------------------------------------------------------------------------
  77. BOOL LLKeyframeFallMotion::onActivate()
  78. {
  79. LLVector3 ground_pos;
  80. LLVector3 ground_normal;
  81. LLQuaternion inverse_pelvis_rot;
  82. LLVector3 fwd_axis(1.f, 0.f, 0.f);
  83. mVelocityZ = -mCharacter->getCharacterVelocity().mV[VZ];
  84. mCharacter->getGround( mCharacter->getCharacterPosition(), ground_pos, ground_normal);
  85. ground_normal.normVec();
  86. inverse_pelvis_rot = mCharacter->getCharacterRotation();
  87. inverse_pelvis_rot.transQuat();
  88. // find ground normal in pelvis space
  89. ground_normal = ground_normal * inverse_pelvis_rot;
  90. // calculate new foward axis
  91. fwd_axis = fwd_axis - (ground_normal * (ground_normal * fwd_axis));
  92. fwd_axis.normVec();
  93. mRotationToGroundNormal = LLQuaternion(fwd_axis, ground_normal % fwd_axis, ground_normal);
  94. return LLKeyframeMotion::onActivate();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // LLKeyframeFallMotion::onUpdate()
  98. //-----------------------------------------------------------------------------
  99. BOOL LLKeyframeFallMotion::onUpdate(F32 activeTime, U8* joint_mask)
  100. {
  101. BOOL result = LLKeyframeMotion::onUpdate(activeTime, joint_mask);
  102. F32 slerp_amt = clamp_rescale(activeTime / getDuration(), 0.5f, 0.75f, 0.f, 1.f);
  103. if (mPelvisState.notNull())
  104. {
  105. mPelvisState->setRotation(mPelvisState->getRotation() * slerp(slerp_amt, mRotationToGroundNormal, LLQuaternion()));
  106. }
  107. return result;
  108. }
  109. //-----------------------------------------------------------------------------
  110. // LLKeyframeFallMotion::getEaseInDuration()
  111. //-----------------------------------------------------------------------------
  112. F32 LLKeyframeFallMotion::getEaseInDuration()
  113. {
  114. if (mVelocityZ == 0.f)
  115. {
  116. // we've already hit the ground
  117. return 0.4f;
  118. }
  119. return mCharacter->getPreferredPelvisHeight() / mVelocityZ;
  120. }
  121. // End