PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/llcriticaldamp.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 89 lines | 40 code | 11 blank | 38 comment | 7 complexity | bf1e1dd61b97b999e2c547d638e2f122 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcriticaldamp.cpp
  3. * @brief Implementation of the critical damping functionality.
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #include "linden_common.h"
  27. #include "llcriticaldamp.h"
  28. //-----------------------------------------------------------------------------
  29. // static members
  30. //-----------------------------------------------------------------------------
  31. LLFrameTimer LLCriticalDamp::sInternalTimer;
  32. std::map<F32, F32> LLCriticalDamp::sInterpolants;
  33. F32 LLCriticalDamp::sTimeDelta;
  34. //-----------------------------------------------------------------------------
  35. // LLCriticalDamp()
  36. //-----------------------------------------------------------------------------
  37. LLCriticalDamp::LLCriticalDamp()
  38. {
  39. sTimeDelta = 0.f;
  40. }
  41. // static
  42. //-----------------------------------------------------------------------------
  43. // updateInterpolants()
  44. //-----------------------------------------------------------------------------
  45. void LLCriticalDamp::updateInterpolants()
  46. {
  47. sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32();
  48. F32 time_constant;
  49. for (std::map<F32, F32>::iterator iter = sInterpolants.begin();
  50. iter != sInterpolants.end(); iter++)
  51. {
  52. time_constant = iter->first;
  53. F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
  54. new_interpolant = llclamp(new_interpolant, 0.f, 1.f);
  55. sInterpolants[time_constant] = new_interpolant;
  56. }
  57. }
  58. //-----------------------------------------------------------------------------
  59. // getInterpolant()
  60. //-----------------------------------------------------------------------------
  61. F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache)
  62. {
  63. if (time_constant == 0.f)
  64. {
  65. return 1.f;
  66. }
  67. if (use_cache && sInterpolants.count(time_constant))
  68. {
  69. return sInterpolants[time_constant];
  70. }
  71. F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
  72. interpolant = llclamp(interpolant, 0.f, 1.f);
  73. if (use_cache)
  74. {
  75. sInterpolants[time_constant] = interpolant;
  76. }
  77. return interpolant;
  78. }