hermitespline.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWMath *
  23. * *
  24. * $Archive:: /VSS_Sync/wwmath/hermitespline.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 6/13/01 2:18p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef HERMITE_H
  39. #define HERMITE_H
  40. #include "curve.h"
  41. /*
  42. ** HermiteSpline3DClass
  43. ** 3-Dimensional hermite spline interpolation
  44. ** Hermite splines require you to input all of the tangents...
  45. */
  46. class HermiteSpline3DClass : public Curve3DClass
  47. {
  48. public:
  49. HermiteSpline3DClass(void)
  50. : TangentsDirty (true) { }
  51. HermiteSpline3DClass(const HermiteSpline3DClass &that)
  52. : TangentsDirty (true) { (*this) = that; }
  53. const HermiteSpline3DClass &operator= (const HermiteSpline3DClass &that);
  54. virtual void Evaluate(float time,Vector3 * set_val);
  55. virtual void Evaluate_Derivative(float time,Vector3 * set_val);
  56. virtual void Set_Looping(bool onoff);
  57. virtual void Set_Key(int i,const Vector3 & point);
  58. virtual int Add_Key(const Vector3 & point,float t);
  59. virtual void Remove_Key(int i);
  60. virtual void Clear_Keys(void);
  61. virtual void Set_Tangents(int i,const Vector3 & in_tan,const Vector3 & out_tan);
  62. virtual void Get_Tangents(int i,Vector3 * set_in,Vector3 * set_out);
  63. virtual void Update_Tangents(void) { TangentsDirty = false; }
  64. // save-load support
  65. virtual const PersistFactoryClass & Get_Factory(void) const;
  66. virtual bool Save(ChunkSaveClass &csave);
  67. virtual bool Load(ChunkLoadClass &cload);
  68. protected:
  69. class TangentsClass
  70. {
  71. public:
  72. Vector3 InTangent;
  73. Vector3 OutTangent;
  74. bool operator == (const TangentsClass & that) { return ((InTangent == that.InTangent) && (OutTangent == that.OutTangent)); }
  75. bool operator != (const TangentsClass & that) { return !TangentsClass::operator == (that); }
  76. };
  77. bool TangentsDirty;
  78. DynamicVectorClass<TangentsClass> Tangents;
  79. };
  80. /*
  81. ** HermiteSpline1DClass
  82. ** 1-Dimensional hermite spline interpolation
  83. ** Hermite splines require you to input all of the tangents...
  84. */
  85. class HermiteSpline1DClass : public Curve1DClass
  86. {
  87. public:
  88. HermiteSpline1DClass (void)
  89. : TangentsDirty (true) { }
  90. virtual void Evaluate(float time,float * set_val);
  91. virtual void Set_Looping(bool onoff);
  92. virtual void Set_Key(int i,float point,unsigned int extra=0);
  93. virtual int Add_Key(float point,float t,unsigned int extra=0);
  94. virtual void Remove_Key(int i);
  95. virtual void Clear_Keys(void);
  96. virtual void Set_Tangents(int i,float in_tan,float out_tan);
  97. virtual void Get_Tangents(int i,float * set_in,float * set_out);
  98. // save-load support
  99. virtual const PersistFactoryClass & Get_Factory(void) const;
  100. virtual bool Save(ChunkSaveClass &csave);
  101. virtual bool Load(ChunkLoadClass &cload);
  102. protected:
  103. class TangentsClass
  104. {
  105. public:
  106. float InTangent;
  107. float OutTangent;
  108. bool operator == (const TangentsClass & that) { return ((InTangent == that.InTangent) && (OutTangent == that.OutTangent)); }
  109. bool operator != (const TangentsClass & that) { return !TangentsClass::operator == (that); }
  110. };
  111. virtual void Update_Tangents(void) { TangentsDirty = false; }
  112. bool TangentsDirty;
  113. DynamicVectorClass<TangentsClass> Tangents;
  114. };
  115. #endif