PageRenderTime 1426ms CodeModel.GetById 8ms RepoModel.GetById 45ms app.codeStats 0ms

/indra/newview/llviewertextureanim.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 212 lines | 160 code | 22 blank | 30 comment | 21 complexity | 672f5aa4a84bac623b4a1be6b027908d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewertextureanim.cpp
  3. * @brief LLViewerTextureAnim class implementation
  4. *
  5. * $LicenseInfo:firstyear=2003&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 "llviewerprecompiledheaders.h"
  27. #include "llviewertextureanim.h"
  28. #include "llmath.h"
  29. #include "llerror.h"
  30. LLViewerTextureAnim::LLViewerTextureAnim() : LLTextureAnim()
  31. {
  32. mLastFrame = -1.f; // Force an update initially
  33. mLastTime = 0.f;
  34. mOffS = mOffT = 0;
  35. mScaleS = mScaleT = 1;
  36. mRot = 0;
  37. }
  38. LLViewerTextureAnim::~LLViewerTextureAnim()
  39. {
  40. }
  41. void LLViewerTextureAnim::reset()
  42. {
  43. LLTextureAnim::reset();
  44. mTimer.reset();
  45. }
  46. S32 LLViewerTextureAnim::animateTextures(F32 &off_s, F32 &off_t,
  47. F32 &scale_s, F32 &scale_t,
  48. F32 &rot)
  49. {
  50. S32 result = 0;
  51. if (!(mMode & ON))
  52. {
  53. mLastTime = 0.f;
  54. mLastFrame = -1.f;
  55. return result;
  56. }
  57. F32 num_frames = 1.0;
  58. F32 full_length = 1.0;
  59. if (mLength)
  60. {
  61. num_frames = mLength;
  62. }
  63. else
  64. {
  65. num_frames = llmax(1.f, (F32)(mSizeX * mSizeY));
  66. }
  67. if (mMode & PING_PONG)
  68. {
  69. if (mMode & SMOOTH)
  70. {
  71. full_length = 2.f*num_frames;
  72. }
  73. else if (mMode & LOOP)
  74. {
  75. full_length = 2.f*num_frames - 2.f;
  76. full_length = llmax(1.f, full_length);
  77. }
  78. else
  79. {
  80. full_length = 2.f*num_frames - 1.f;
  81. full_length = llmax(1.f, full_length);
  82. }
  83. }
  84. else
  85. {
  86. full_length = num_frames;
  87. }
  88. F32 frame_counter;
  89. if (mMode & SMOOTH)
  90. {
  91. frame_counter = mTimer.getElapsedTimeAndResetF32() * mRate + (F32)mLastTime;
  92. }
  93. else
  94. {
  95. frame_counter = mTimer.getElapsedTimeF32() * mRate;
  96. }
  97. mLastTime = frame_counter;
  98. if (mMode & LOOP)
  99. {
  100. frame_counter = fmod(frame_counter, full_length);
  101. }
  102. else
  103. {
  104. frame_counter = llmin(full_length - 1.f, frame_counter);
  105. }
  106. if (!(mMode & SMOOTH))
  107. {
  108. frame_counter = (F32)llfloor(frame_counter + 0.01f);
  109. }
  110. if (mMode & PING_PONG)
  111. {
  112. if (frame_counter >= num_frames)
  113. {
  114. if (mMode & SMOOTH)
  115. {
  116. frame_counter = num_frames - (frame_counter - num_frames);
  117. }
  118. else
  119. {
  120. frame_counter = (num_frames - 1.99f) - (frame_counter - num_frames);
  121. }
  122. }
  123. }
  124. if (mMode & REVERSE)
  125. {
  126. if (mMode & SMOOTH)
  127. {
  128. frame_counter = num_frames - frame_counter;
  129. }
  130. else
  131. {
  132. frame_counter = (num_frames - 0.99f) - frame_counter;
  133. }
  134. }
  135. frame_counter += mStart;
  136. if (!(mMode & SMOOTH))
  137. {
  138. frame_counter = (F32)llround(frame_counter);
  139. }
  140. //
  141. // Now that we've calculated the frame time, do an update.
  142. // Will we correctly update stuff if the texture anim has
  143. // changed, but not the frame counter?
  144. //
  145. if (mLastFrame != frame_counter)
  146. {
  147. mLastFrame = frame_counter;
  148. if (mMode & ROTATE)
  149. {
  150. result |= ROTATE;
  151. mRot = rot = frame_counter;
  152. }
  153. else if (mMode & SCALE)
  154. {
  155. result |= SCALE;
  156. mScaleS = scale_s = frame_counter;
  157. mScaleT = scale_t = frame_counter;
  158. }
  159. else
  160. {
  161. result |= TRANSLATE;
  162. F32 x_frame;
  163. S32 y_frame;
  164. F32 x_pos;
  165. F32 y_pos;
  166. if ( (mSizeX)
  167. &&(mSizeY))
  168. {
  169. result |= SCALE;
  170. mScaleS = scale_s = 1.f/mSizeX;
  171. mScaleT = scale_t = 1.f/mSizeY;
  172. x_frame = fmod(frame_counter, mSizeX);
  173. y_frame = (S32)(frame_counter / mSizeX);
  174. x_pos = x_frame * scale_s;
  175. y_pos = y_frame * scale_t;
  176. mOffS = off_s = (-0.5f + 0.5f*scale_s)+ x_pos;
  177. mOffT = off_t = (0.5f - 0.5f*scale_t) - y_pos;
  178. }
  179. else
  180. {
  181. mScaleS = scale_s = 1.f;
  182. mScaleT = scale_t = 1.f;
  183. x_pos = frame_counter * scale_s;
  184. mOffS = off_s = (-0.5f + 0.5f*scale_s)+ x_pos;
  185. mOffT = off_t = 0.f;
  186. }
  187. }
  188. }
  189. return result;
  190. }