SplineTestDoc.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. ** Command & Conquer Renegade(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. // SplineTestDoc.cpp : implementation of the CSplineTestDoc class
  19. //
  20. #include "stdafx.h"
  21. #include "SplineTest.h"
  22. #include "SplineTestDoc.h"
  23. #include "CurvePoints.h"
  24. #include "curve.h"
  25. #include "hermitespline.h"
  26. #include "catmullromspline.h"
  27. #include "cardinalspline.h"
  28. #include "tcbspline.h"
  29. #include "wwmath.h"
  30. #include "CardinalDialog.h"
  31. #include "TCBDialog.h"
  32. #include "Matrix3D.h"
  33. #include "vehiclecurve.h"
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. const float GRAB_DIST = 0.25f;
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CSplineTestDoc
  42. IMPLEMENT_DYNCREATE(CSplineTestDoc, CDocument)
  43. BEGIN_MESSAGE_MAP(CSplineTestDoc, CDocument)
  44. //{{AFX_MSG_MAP(CSplineTestDoc)
  45. // NOTE - the ClassWizard will add and remove mapping macros here.
  46. // DO NOT EDIT what you see in these blocks of generated code!
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CSplineTestDoc construction/destruction
  51. CSplineTestDoc::CSplineTestDoc()
  52. {
  53. CurveType = LINEAR;
  54. Curve = new LinearCurve3DClass;
  55. DragIndex = -1;
  56. }
  57. CSplineTestDoc::~CSplineTestDoc()
  58. {
  59. if (Curve != NULL) {
  60. delete Curve;
  61. }
  62. }
  63. BOOL CSplineTestDoc::OnNewDocument()
  64. {
  65. if (!CDocument::OnNewDocument())
  66. return FALSE;
  67. // TODO: add reinitialization code here
  68. // (SDI documents will reuse this document)
  69. return TRUE;
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CSplineTestDoc serialization
  73. void CSplineTestDoc::Serialize(CArchive& ar)
  74. {
  75. if (ar.IsStoring())
  76. {
  77. // TODO: add storing code here
  78. }
  79. else
  80. {
  81. // TODO: add loading code here
  82. }
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CSplineTestDoc diagnostics
  86. #ifdef _DEBUG
  87. void CSplineTestDoc::AssertValid() const
  88. {
  89. CDocument::AssertValid();
  90. }
  91. void CSplineTestDoc::Dump(CDumpContext& dc) const
  92. {
  93. CDocument::Dump(dc);
  94. }
  95. #endif //_DEBUG
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CSplineTestDoc commands
  98. void CSplineTestDoc::Reset_Curve(void)
  99. {
  100. if (Curve != NULL) {
  101. delete Curve;
  102. }
  103. Curve = Create_Curve(CurveType);
  104. DragIndex = -1;
  105. UpdateAllViews(NULL);
  106. }
  107. void CSplineTestDoc::Set_Curve_Type(int type)
  108. {
  109. assert (Curve != NULL);
  110. if (type != CurveType) {
  111. Curve3DClass * new_curve = NULL;
  112. new_curve = Create_Curve(type);
  113. for (int i=0; i<Curve->Key_Count(); i++) {
  114. Vector3 pt;
  115. float t;
  116. Curve->Get_Key(i,&pt,&t);
  117. new_curve->Add_Key(pt,t);
  118. UpdateAllViews(NULL);
  119. }
  120. delete Curve;
  121. Curve = new_curve;
  122. CurveType = type;
  123. }
  124. }
  125. int CSplineTestDoc::Get_Curve_Type(void)
  126. {
  127. return CurveType;
  128. }
  129. Curve3DClass * CSplineTestDoc::Get_Curve(void)
  130. {
  131. return Curve;
  132. }
  133. Curve3DClass * CSplineTestDoc::Create_Curve(int type)
  134. {
  135. Curve3DClass * new_curve = NULL;
  136. switch (type) {
  137. case LINEAR:
  138. new_curve = new LinearCurve3DClass;
  139. break;
  140. case VEHICLE:
  141. new_curve = new VehicleCurveClass (1.0F);
  142. break;
  143. case CATMULL_ROM:
  144. new_curve = new CatmullRomSpline3DClass;
  145. break;
  146. case CARDINAL:
  147. new_curve = new CardinalSpline3DClass;
  148. break;
  149. case TCB:
  150. new_curve = new TCBSpline3DClass;
  151. break;
  152. }
  153. return new_curve;
  154. }
  155. bool CSplineTestDoc::Grab_Point(const Vector3 & pos)
  156. {
  157. DragIndex = -1;
  158. if (Curve) {
  159. DragIndex = Pick(pos);
  160. }
  161. return (DragIndex != -1);
  162. }
  163. bool CSplineTestDoc::Drag_Point(const Vector3 & pos)
  164. {
  165. if (DragIndex == -1) {
  166. return false;
  167. } else {
  168. if (Curve) {
  169. Curve->Set_Key(DragIndex,pos);
  170. UpdateAllViews(NULL);
  171. }
  172. return true;
  173. }
  174. }
  175. bool CSplineTestDoc::Release_Point(void)
  176. {
  177. DragIndex = -1;
  178. return true;
  179. }
  180. bool CSplineTestDoc::Is_Dragging(void)
  181. {
  182. return (DragIndex != -1);
  183. }
  184. bool CSplineTestDoc::Add_Point(const Vector3 & pos)
  185. {
  186. if (Curve == NULL) return false;
  187. if (Curve->Key_Count() == 0) {
  188. Curve->Add_Key(pos,0.0f);
  189. } else {
  190. // make dt random for testing
  191. Curve->Add_Key(pos,Curve->Get_End_Time() + 1.0f); //WWMath::Random_Float(0.1f,5.0f));
  192. }
  193. UpdateAllViews(NULL);
  194. return true;
  195. }
  196. int CSplineTestDoc::Pick(const Vector3 & pos)
  197. {
  198. int index = -1;
  199. for (int pi=0; pi<Curve->Key_Count(); pi++) {
  200. Vector3 keypt;
  201. Curve->Get_Key(pi,&keypt,NULL);
  202. if ((keypt - pos).Length() < GRAB_DIST) {
  203. index = pi;
  204. break;
  205. }
  206. }
  207. return index;
  208. }
  209. void CSplineTestDoc::Edit_Point(const Vector3 & pos)
  210. {
  211. int index = Pick(pos);
  212. if (index == -1) return;
  213. switch (CurveType) {
  214. case LINEAR:
  215. case CATMULL_ROM:
  216. case VEHICLE:
  217. break;
  218. case CARDINAL:
  219. {
  220. CCardinalDialog dlg(::AfxGetMainWnd(),(CardinalSpline3DClass *)Curve,index);
  221. dlg.DoModal();
  222. break;
  223. }
  224. case TCB:
  225. {
  226. CTCBDialog dlg(::AfxGetMainWnd(),(TCBSpline3DClass *)Curve,index);
  227. dlg.DoModal();
  228. break;
  229. }
  230. }
  231. UpdateAllViews(NULL);
  232. return;
  233. }
  234. void CSplineTestDoc::Simulate_Turn_Radius (void)
  235. {
  236. return ;
  237. }