Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.5 KiB

  1. #if !defined(CTRL__OldInterpolation_h__INCLUDED)
  2. #define CTRL__OldInterpolation_h__INCLUDED
  3. #pragma once
  4. #include "SmObject.h"
  5. /***************************************************************************\
  6. *****************************************************************************
  7. *
  8. * class OldInterpolationT
  9. *
  10. * OldInterpolationT defines a common implementation class for building
  11. * Interpolation functions that can be used with Animations in DirectUser.
  12. *
  13. *****************************************************************************
  14. \***************************************************************************/
  15. template <class base, class iface>
  16. class OldInterpolationT : public SmObjectT<base, iface>
  17. {
  18. // Operations
  19. public:
  20. static HRESULT
  21. Build(REFIID riid, void ** ppv)
  22. {
  23. OldInterpolationT<base, iface> * pObj = new OldInterpolationT<base, iface>;
  24. if (pObj != NULL) {
  25. pObj->m_cRef = 0;
  26. HRESULT hr = pObj->QueryInterface(riid, ppv);
  27. if (FAILED(hr)) {
  28. delete pObj;
  29. }
  30. return hr;
  31. } else {
  32. return E_OUTOFMEMORY;
  33. }
  34. }
  35. };
  36. /***************************************************************************\
  37. *****************************************************************************
  38. *
  39. * class OldLinearInterpolation
  40. *
  41. *****************************************************************************
  42. \***************************************************************************/
  43. class OldLinearInterpolation : public ILinearInterpolation
  44. {
  45. public:
  46. STDMETHOD_(float, Compute)(float flProgress, float flStart, float flEnd)
  47. {
  48. return (1.0f - flProgress) * flStart + flProgress * flEnd;
  49. }
  50. protected:
  51. static const IID * s_rgpIID[];
  52. };
  53. /***************************************************************************\
  54. *****************************************************************************
  55. *
  56. * class OldLogInterpolation
  57. *
  58. *****************************************************************************
  59. \***************************************************************************/
  60. class OldLogInterpolation : public ILogInterpolation
  61. {
  62. // Operations
  63. public:
  64. inline OldLogInterpolation()
  65. {
  66. m_flScale = 1.0f;
  67. }
  68. STDMETHOD_(float, Compute)(float flProgress, float flStart, float flEnd)
  69. {
  70. float flMax = (float) log10(m_flScale * 9.0f + 1.0f);
  71. float flT = (float) log10(flProgress * m_flScale * 9.0f + 1.0f) / flMax;
  72. return (1.0f - flT) * flStart + flT * flEnd;
  73. }
  74. STDMETHOD_(void, SetScale)(float flScale)
  75. {
  76. m_flScale = flScale;
  77. }
  78. // Data
  79. protected:
  80. float m_flScale;
  81. static const IID * s_rgpIID[];
  82. };
  83. /***************************************************************************\
  84. *****************************************************************************
  85. *
  86. * class OldExpInterpolation
  87. *
  88. *****************************************************************************
  89. \***************************************************************************/
  90. class OldExpInterpolation : public IExpInterpolation
  91. {
  92. // Operations
  93. public:
  94. inline OldExpInterpolation()
  95. {
  96. m_flScale = 1.0f;
  97. }
  98. STDMETHOD_(float, Compute)(float flProgress, float flStart, float flEnd)
  99. {
  100. double dflProgress = flProgress;
  101. double dflStart = flStart;
  102. double dflEnd = flEnd;
  103. double dflScale = m_flScale;
  104. double dflMax = (((10.0 * dflScale) - 1.0) / 9.0);
  105. double dflT = (((pow(10.0 * dflScale, dflProgress) - 1.0) / 9.0) / dflMax);
  106. return (float) ((1.0 - dflT) * dflStart + dflT * dflEnd);
  107. }
  108. STDMETHOD_(void, SetScale)(float flScale)
  109. {
  110. m_flScale = flScale;
  111. }
  112. // Data
  113. protected:
  114. float m_flScale;
  115. static const IID * s_rgpIID[];
  116. };
  117. /***************************************************************************\
  118. *****************************************************************************
  119. *
  120. * class OldSInterpolation
  121. *
  122. *****************************************************************************
  123. \***************************************************************************/
  124. class OldSInterpolation : public ISInterpolation
  125. {
  126. // Operations
  127. public:
  128. inline OldSInterpolation()
  129. {
  130. m_flScale = 1.0f;
  131. }
  132. STDMETHOD_(float, Compute)(float flProgress, float flStart, float flEnd)
  133. {
  134. //
  135. // Slow - fast - slow
  136. //
  137. double dflProgress = flProgress;
  138. double dflStart = flStart;
  139. double dflEnd = flEnd;
  140. double dflScale = m_flScale;
  141. double dflMax;
  142. double dflT;
  143. if (dflProgress < 0.5) {
  144. double dflPartProgress = dflProgress * 2.0;
  145. dflMax = (((10.0 * dflScale) - 1.0) / 9.0) * 2.0;
  146. dflT = ((pow(10.0 * dflScale, dflPartProgress) - 1.0) / 9.0) / dflMax;
  147. } else {
  148. double dflPartProgress = (1.0 - dflProgress) * 2.0;
  149. dflMax = (((10.0 * dflScale) - 1.0) / 9.0) * 2.0;
  150. dflT = 1.0 - ((pow(10.0 * dflScale, dflPartProgress) - 1.0) / 9.0) / dflMax;
  151. }
  152. return (float) ((1.0 - dflT) * dflStart + dflT * dflEnd);
  153. }
  154. STDMETHOD_(void, SetScale)(float flScale)
  155. {
  156. m_flScale = flScale;
  157. }
  158. // Data
  159. protected:
  160. float m_flScale;
  161. static const IID * s_rgpIID[];
  162. };
  163. #endif // CTRL__OldInterpolation_h__INCLUDED