llinterp.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @file llinterp.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewergpl$
  5. *
  6. * Copyright (c) 2001-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #include "linden_common.h"
  32. #include "llinterp.h"
  33. void LLInterpLinear::update(F32 time)
  34. {
  35. F32 target_frac = (time - mStartTime) / mDuration;
  36. F32 dfrac = target_frac - mCurFrac;
  37. if (target_frac >= 0.f)
  38. {
  39. mActive = true;
  40. }
  41. if (target_frac > 1.f)
  42. {
  43. mCurVal = mEndVal;
  44. mCurFrac = 1.f;
  45. mCurTime = time;
  46. mDone = true;
  47. return;
  48. }
  49. target_frac = llmax(0.f, target_frac);
  50. if (dfrac >= 0.f)
  51. {
  52. F32 total_frac = 1.f - mCurFrac;
  53. F32 inc_frac = dfrac / total_frac;
  54. mCurVal = inc_frac * mEndVal + (1.f - inc_frac) * mCurVal;
  55. mCurTime = time;
  56. }
  57. else
  58. {
  59. F32 total_frac = mCurFrac - 1.f;
  60. F32 inc_frac = dfrac / total_frac;
  61. mCurVal = inc_frac * mStartVal + (1.f - inc_frac) * mCurVal;
  62. mCurTime = time;
  63. }
  64. mCurFrac = target_frac;
  65. }