curve.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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/curve.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 6/13/01 2:18p $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef CURVE_H
  39. #define CURVE_H
  40. #ifndef ALWAYS_H
  41. #include "always.h"
  42. #endif
  43. #ifndef VECTOR_H
  44. #include "vector.h"
  45. #endif
  46. #ifndef VECTOR3_H
  47. #include "vector3.h"
  48. #endif
  49. #ifndef PERSIST_H
  50. #include "persist.h"
  51. #endif
  52. class ChunkLoadClass;
  53. class ChunkSaveClass;
  54. class Curve3DClass : public PersistClass
  55. {
  56. public:
  57. Curve3DClass(void);
  58. Curve3DClass(const Curve3DClass & that);
  59. virtual ~Curve3DClass(void);
  60. Curve3DClass & operator = (const Curve3DClass & that);
  61. virtual void Evaluate(float time,Vector3 * set_val) = 0;
  62. virtual bool Is_Looping(void);
  63. virtual void Set_Looping(bool onoff);
  64. virtual int Key_Count(void);
  65. virtual void Get_Key(int i,Vector3 * set_point,float * set_t);
  66. virtual void Set_Key(int i,const Vector3 & point);
  67. virtual int Add_Key(const Vector3 & point,float t);
  68. virtual void Remove_Key(int i);
  69. virtual void Clear_Keys(void);
  70. float Get_Start_Time(void);
  71. float Get_End_Time(void);
  72. // persistant object support
  73. virtual bool Save (ChunkSaveClass &csave);
  74. virtual bool Load (ChunkLoadClass &cload);
  75. protected:
  76. void Find_Interval(float time,int * i0,int * i1,float * t);
  77. class KeyClass
  78. {
  79. public:
  80. Vector3 Point;
  81. float Time;
  82. bool operator == (const KeyClass & that) { return ((Point == that.Point) && (Time == that.Time)); }
  83. bool operator != (const KeyClass & that) { return !KeyClass::operator==(that); }
  84. };
  85. bool IsLooping;
  86. DynamicVectorClass<KeyClass> Keys;
  87. };
  88. class LinearCurve3DClass : public Curve3DClass
  89. {
  90. public:
  91. virtual void Evaluate(float time,Vector3 * set_val);
  92. // persistant object support
  93. virtual const PersistFactoryClass & Get_Factory(void) const;
  94. virtual bool Save(ChunkSaveClass &csave);
  95. virtual bool Load(ChunkLoadClass &cload);
  96. };
  97. /*
  98. ** 1-Dimensional curve classes.
  99. */
  100. class Curve1DClass : public PersistClass
  101. {
  102. public:
  103. Curve1DClass(void);
  104. Curve1DClass(const Curve1DClass & that);
  105. virtual ~Curve1DClass(void);
  106. Curve1DClass & operator = (const Curve1DClass & that);
  107. virtual void Evaluate(float time,float * set_val) = 0;
  108. virtual bool Is_Looping(void);
  109. virtual void Set_Looping(bool onoff);
  110. virtual int Key_Count(void);
  111. virtual void Get_Key(int i,float * set_point,float * set_t,unsigned int * extra=NULL);
  112. virtual void Set_Key(int i,float point,unsigned int extra=0);
  113. virtual int Add_Key(float point,float t,unsigned int extra=0);
  114. virtual void Remove_Key(int i);
  115. virtual void Clear_Keys(void);
  116. float Get_Start_Time(void);
  117. float Get_End_Time(void);
  118. // persistant object support
  119. virtual bool Save (ChunkSaveClass &csave);
  120. virtual bool Load (ChunkLoadClass &cload);
  121. protected:
  122. void Find_Interval(float time,int * i0,int * i1,float * t);
  123. class KeyClass
  124. {
  125. public:
  126. float Point;
  127. float Time;
  128. unsigned int Extra;
  129. bool operator == (const KeyClass & that) { return ((Point == that.Point) && (Time == that.Time) && (Extra == that.Extra)); }
  130. bool operator != (const KeyClass & that) { return !KeyClass::operator==(that); }
  131. };
  132. bool IsLooping;
  133. DynamicVectorClass<KeyClass> Keys;
  134. };
  135. class LinearCurve1DClass : public Curve1DClass
  136. {
  137. public:
  138. virtual void Evaluate(float time,float * set_val);
  139. // persistant object support
  140. virtual const PersistFactoryClass & Get_Factory(void) const;
  141. virtual bool Save(ChunkSaveClass &csave);
  142. virtual bool Load(ChunkLoadClass &cload);
  143. };
  144. #endif //CURVE_H