TransitionEditDialog.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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. // TransitionEditDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "leveleditview.h"
  23. #include "transitioneditdialog.h"
  24. #include "ww3d.h"
  25. #include "scene.h"
  26. #include "camera.h"
  27. #include "utils.h"
  28. #include "mmsystem.h"
  29. #include "matrix3d.h"
  30. #include "rendobj.h"
  31. #include "transition.h"
  32. #include "sphere.h"
  33. #include "box3d.h"
  34. #include "cameramgr.h"
  35. #include "filemgr.h"
  36. #include "filelocations.h"
  37. #include "hanim.h"
  38. #include "quat.h"
  39. #include "vector3.h"
  40. #include "obbox.h"
  41. #include "combatchunkid.h"
  42. #include "soldier.h"
  43. #include "editorbuild.h"
  44. #include "mixfiledatabase.h"
  45. #ifdef _DEBUG
  46. #define new DEBUG_NEW
  47. #undef THIS_FILE
  48. static char THIS_FILE[] = __FILE__;
  49. #endif
  50. /////////////////////////////////////////////////////////////////////////////
  51. //
  52. // Local constants
  53. //
  54. /////////////////////////////////////////////////////////////////////////////
  55. const int TOOLBAR_HEIGHT = 36;
  56. const int TOOLBAR_V_SPACING = 5;
  57. const int TOOLBAR_V_BORDER = TOOLBAR_V_SPACING * 2;
  58. const int TOOLBAR_H_SPACING = 5;
  59. const int TOOLBAR_H_BORDER = TOOLBAR_H_SPACING * 2;
  60. /////////////////////////////////////////////////////////////////////////////
  61. //
  62. // Local prototypes
  63. //
  64. /////////////////////////////////////////////////////////////////////////////
  65. static void Trackball_Camera (HWND hwnd, CameraClass &camera, const Vector3 &center, POINT point, POINT last_point);
  66. /////////////////////////////////////////////////////////////////////////////
  67. //
  68. // TransitionEditDialogClass
  69. //
  70. /////////////////////////////////////////////////////////////////////////////
  71. TransitionEditDialogClass::TransitionEditDialogClass(CWnd* pParent /*=NULL*/)
  72. : m_LookAtDist (0),
  73. m_Camera (NULL),
  74. m_Scene (NULL),
  75. m_RenderObj (NULL),
  76. m_Transition (NULL),
  77. m_Zone (NULL),
  78. m_CharacterObj (NULL),
  79. m_Animation (NULL),
  80. m_SwapChain (NULL),
  81. m_TimerID (0),
  82. m_CurrFrame (0),
  83. m_LastAnimUpdate (0),
  84. m_IsEditingZone (true),
  85. m_IsEditingChar (true),
  86. m_IsAnimating (false),
  87. m_IsSizingZone (false),
  88. m_IsRotatingChar (false),
  89. CDialog(TransitionEditDialogClass::IDD, pParent)
  90. {
  91. //{{AFX_DATA_INIT(TransitionEditDialogClass)
  92. // NOTE: the ClassWizard will add member initialization here
  93. //}}AFX_DATA_INIT
  94. return ;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. // DoDataExchange
  99. //
  100. /////////////////////////////////////////////////////////////////////////////
  101. void
  102. TransitionEditDialogClass::DoDataExchange (CDataExchange* pDX)
  103. {
  104. CDialog::DoDataExchange(pDX);
  105. //{{AFX_DATA_MAP(TransitionEditDialogClass)
  106. DDX_Control(pDX, IDC_EDIT_ZONE, m_MoveZoneCheck);
  107. DDX_Control(pDX, IDC_EDIT_CHAR, m_MoveCharCheck);
  108. DDX_Control(pDX, IDC_SIZE_ZONE, m_SizeZoneCheck);
  109. DDX_Control(pDX, IDC_ROTATE_CHAR, m_RotateCharCheck);
  110. DDX_Control(pDX, IDC_ANIMATION_LIST, m_AnimationList);
  111. DDX_Control(pDX, IDC_TRIGGER_LIST, m_TriggerList);
  112. //}}AFX_DATA_MAP
  113. return ;
  114. }
  115. BEGIN_MESSAGE_MAP(TransitionEditDialogClass, CDialog)
  116. //{{AFX_MSG_MAP(TransitionEditDialogClass)
  117. ON_WM_DESTROY()
  118. ON_BN_CLICKED(IDC_TOP, OnTop)
  119. ON_BN_CLICKED(IDC_FRONT, OnFront)
  120. ON_BN_CLICKED(IDC_LEFT, OnLeft)
  121. ON_BN_CLICKED(IDC_RIGHT, OnRight)
  122. ON_BN_CLICKED(IDC_EDIT_CHAR, OnEditChar)
  123. ON_BN_CLICKED(IDC_EDIT_ZONE, OnEditZone)
  124. ON_CBN_SELCHANGE(IDC_ANIMATION_LIST, OnSelChangeAnimationList)
  125. ON_COMMAND(IDM_ANI_BACK_FRAME, OnAniBackFrame)
  126. ON_COMMAND(IDM_ANI_FIRST_FRAME, OnAniFirstFrame)
  127. ON_COMMAND(IDM_ANI_FWD_FRAME, OnAniFwdFrame)
  128. ON_COMMAND(IDM_ANI_LAST_FRAME, OnAniLastFrame)
  129. ON_COMMAND(IDM_ANI_PAUSE, OnAniPause)
  130. ON_COMMAND(IDM_ANI_PLAY, OnAniPlay)
  131. ON_COMMAND(IDM_ANI_STOP, OnAniStop)
  132. ON_BN_CLICKED(IDC_SIZE_ZONE, OnSizeZone)
  133. ON_BN_CLICKED(IDC_ROTATE_CHAR, OnRotateChar)
  134. //}}AFX_MSG_MAP
  135. END_MESSAGE_MAP()
  136. /////////////////////////////////////////////////////////////////////////////
  137. //
  138. // OnInitDialog
  139. //
  140. /////////////////////////////////////////////////////////////////////////////
  141. BOOL
  142. TransitionEditDialogClass::OnInitDialog (void)
  143. {
  144. CWaitCursor wait_cursor;
  145. CLevelEditView::Allow_Repaint (false);
  146. CDialog::OnInitDialog ();
  147. //
  148. // Subclass the 3D window for mouse-tracking
  149. //
  150. SetWindowLong (::GetDlgItem (m_hWnd, IDC_3D_WINDOW), GWL_WNDPROC, (LONG)fn3DWindow);
  151. ::SetProp (::GetDlgItem (m_hWnd, IDC_3D_WINDOW), "TRANSITION_DIALOG", (HANDLE)this);
  152. //
  153. // Setup the toolbar
  154. //
  155. m_Toolbar.CreateEx (this, TBSTYLE_FLAT, WS_BORDER | WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP, CRect(0, 0, 10, 10), 101);
  156. m_Toolbar.SetOwner (this);
  157. m_Toolbar.LoadToolBar (IDR_ANI_TOOLBAR);
  158. m_Toolbar.SetBarStyle (m_Toolbar.GetBarStyle () | CBRS_TOOLTIPS | CBRS_FLYBY);
  159. // Position the toolbar
  160. CRect rect;
  161. CSize size;
  162. m_Toolbar.GetToolBarCtrl ().GetMaxSize (&size);
  163. ::GetWindowRect (::GetDlgItem (m_hWnd, IDC_TOOLBAR), &rect);
  164. ScreenToClient (&rect);
  165. m_Toolbar.SetWindowPos (NULL,
  166. rect.left + (rect.Width () >> 1) - (size.cx >> 1),
  167. rect.top + (rect.Height () >> 1) - (size.cy >> 1),
  168. rect.Width (),
  169. rect.Height (),
  170. SWP_SHOWWINDOW);
  171. //
  172. // Get the dimensions of the client area of the window we'll be rendering in
  173. //
  174. ::GetClientRect (::GetDlgItem (m_hWnd, IDC_3D_WINDOW), &rect);
  175. int cx = rect.Width ();
  176. int cy = rect.Height ();
  177. //
  178. // Create a swap chain so we can render to this window as well
  179. //
  180. m_SwapChain = DX8Wrapper::Create_Additional_Swap_Chain (::GetDlgItem (m_hWnd, IDC_3D_WINDOW));
  181. //
  182. // Create the scene and camera we will use
  183. //
  184. m_Scene = new SimpleSceneClass;
  185. m_Camera = new CameraClass;
  186. m_Scene->Set_Ambient_Light (Vector3 (1, 1, 1));
  187. m_Camera->Set_Clip_Planes (0.1F, 400.0F);
  188. //
  189. // Configure the camera
  190. //
  191. double hfov = 0;
  192. double vfov = 0;
  193. if (cy > cx) {
  194. vfov = (float)DEG_TO_RAD(45.0f);
  195. hfov = (double)cx / (double)cy * vfov;
  196. } else {
  197. hfov = (float)DEG_TO_RAD(45.0f);
  198. vfov = (double)cy / (double)cx * hfov;
  199. }
  200. m_Camera->Set_View_Plane (hfov, vfov);
  201. //
  202. // Setup the scene
  203. //
  204. Load_Object ();
  205. Insert_Zone ();
  206. Fill_Trigger_List ();
  207. Fill_Animation_List ();
  208. Load_Animation ();
  209. //
  210. // Select the default UI
  211. //
  212. SendDlgItemMessage (IDC_TOP, BM_SETCHECK, (WPARAM)TRUE);
  213. SendDlgItemMessage (IDC_EDIT_ZONE, BM_SETCHECK, (WPARAM)TRUE);
  214. SendDlgItemMessage (IDC_EDIT_CHAR, BM_SETCHECK, (WPARAM)TRUE);
  215. OnTop ();
  216. OnEditZone ();
  217. OnEditChar ();
  218. Update_Status ();
  219. // Kick off a timer that we can use to update
  220. // the display (kinda like a game loop iterator)
  221. m_TimerID = ::timeSetEvent ( 50,
  222. 50,
  223. fnUpdateTimer,
  224. (DWORD)m_hWnd,
  225. TIME_PERIODIC);
  226. return TRUE;
  227. }
  228. /////////////////////////////////////////////////////////////////////////////
  229. //
  230. // OnOK
  231. //
  232. /////////////////////////////////////////////////////////////////////////////
  233. void
  234. TransitionEditDialogClass::OnOK (void)
  235. {
  236. //
  237. // Create a matrix we can use to transform the zone and
  238. // character into 'relative' space.
  239. //
  240. Matrix3D obj_tm = m_RenderObj->Get_Transform ();
  241. Matrix3D obj_inv;
  242. obj_tm.Get_Orthogonal_Inverse (obj_inv);
  243. //
  244. // Pass the new animation name onto the transition object
  245. //
  246. CString name;
  247. m_AnimationList.GetWindowText (name);
  248. CString animation_name = CString ("S_A_HUMAN.") + name;
  249. m_Transition->Set_Animation_Name ((LPCTSTR)animation_name);
  250. //
  251. // Pass the trigger type onto the transition
  252. //
  253. m_Transition->Set_Type ((TransitionDataClass::StyleType)m_TriggerList.GetCurSel ());
  254. //
  255. // Pass the character's ending position onto the transition
  256. //
  257. Matrix3D ending_tm = m_CharacterObj->Get_Transform () * obj_inv;
  258. m_Transition->Set_Ending_TM (ending_tm);
  259. //
  260. // Transform the zone from world space coords to relative coords
  261. //
  262. OBBoxClass zone_box (m_Zone->Get_Transform ().Get_Translation (), m_Zone->Get_Dimensions () * 0.5F);
  263. OBBoxClass rel_zone;
  264. OBBoxClass::Transform (obj_inv, zone_box, &rel_zone);
  265. m_Transition->Set_Zone (rel_zone);
  266. CDialog::OnOK ();
  267. return ;
  268. }
  269. /////////////////////////////////////////////////////////////////////////////
  270. //
  271. // OnDestroy
  272. //
  273. /////////////////////////////////////////////////////////////////////////////
  274. void
  275. TransitionEditDialogClass::OnDestroy (void)
  276. {
  277. // Stop the timer
  278. if (m_TimerID != 0) {
  279. ::timeKillEvent (m_TimerID);
  280. m_TimerID = 0;
  281. }
  282. //
  283. // Free our swap chain
  284. //
  285. if (m_SwapChain != NULL) {
  286. m_SwapChain->Release ();
  287. m_SwapChain = NULL;
  288. }
  289. CLevelEditView::Allow_Repaint (true);
  290. //
  291. // Destroy the scene/camera/render-obj
  292. //
  293. m_Scene->Remove_Render_Object (m_RenderObj);
  294. m_Scene->Remove_Render_Object (m_Zone);
  295. m_Scene->Remove_Render_Object (m_CharacterObj);
  296. MEMBER_RELEASE (m_Scene);
  297. MEMBER_RELEASE (m_Camera);
  298. MEMBER_RELEASE (m_RenderObj);
  299. MEMBER_RELEASE (m_CharacterObj);
  300. MEMBER_RELEASE (m_Zone);
  301. MEMBER_RELEASE (m_Animation);
  302. //
  303. // Free all the data we associated with the animation list
  304. //
  305. int count = m_AnimationList.GetCount ();
  306. for (int index = 0; index < count; index ++) {
  307. LPTSTR data = (LPTSTR)m_AnimationList.GetItemData (index);
  308. if (data != NULL) {
  309. ::free (data);
  310. }
  311. }
  312. m_AnimationList.ResetContent ();
  313. CDialog::OnDestroy ();
  314. return ;
  315. }
  316. /////////////////////////////////////////////////////////////////////////////
  317. //
  318. // Render_View
  319. //
  320. /////////////////////////////////////////////////////////////////////////////
  321. void
  322. TransitionEditDialogClass::Render_View (void)
  323. {
  324. static render_lock = false;
  325. if (!render_lock) {
  326. render_lock = true;
  327. //
  328. // Move the camera if the user is pressing
  329. // the camera-control keys.
  330. //
  331. Handle_Keypress ();
  332. //
  333. // Pick the next animation frame
  334. //
  335. Update_Animation ();
  336. //
  337. // Configure the render target
  338. //
  339. DX8Wrapper::Set_Render_Target (m_SwapChain);
  340. //
  341. // Render the scene
  342. //
  343. WW3D::Begin_Render (true, true, Vector3 (0.4F, 0.4F, 0.4F));
  344. WW3D::Render (m_Scene, m_Camera, FALSE, FALSE);
  345. WW3D::End_Render ();
  346. //
  347. // Blit the frame to the client area of the window
  348. //
  349. m_SwapChain->Present (NULL, NULL, NULL, NULL);
  350. //
  351. // Restore the render target
  352. //
  353. DX8Wrapper::Set_Render_Target ((LPDIRECT3DSURFACE8)NULL);
  354. //
  355. // Cleanup
  356. //
  357. RemoveProp (m_hWnd, "WaitingToProcess");
  358. render_lock = false;
  359. }
  360. return ;
  361. }
  362. ////////////////////////////////////////////////////////////////////////////
  363. //
  364. // fnUpdateTimer
  365. //
  366. /////////////////////////////////////////////////////////////////////////////
  367. void CALLBACK
  368. TransitionEditDialogClass::fnUpdateTimer
  369. (
  370. UINT uID,
  371. UINT uMsg,
  372. DWORD user_data,
  373. DWORD dw1,
  374. DWORD dw2
  375. )
  376. {
  377. HWND hwnd = (HWND)user_data;
  378. if (hwnd != NULL) {
  379. if ((GetProp (hwnd, "WaitingToProcess") == NULL)) {
  380. SetProp (hwnd, "WaitingToProcess", (HANDLE)1);
  381. // Send the message to the view so it will be in the
  382. // same thread (We don't seem to be thread-safe)
  383. ::PostMessage (hwnd, WM_USER+101, 0, 0L);
  384. }
  385. }
  386. return ;
  387. }
  388. ////////////////////////////////////////////////////////////////////////////
  389. //
  390. // WindowProc
  391. //
  392. /////////////////////////////////////////////////////////////////////////////
  393. LRESULT
  394. TransitionEditDialogClass::WindowProc
  395. (
  396. UINT message,
  397. WPARAM wParam,
  398. LPARAM lParam
  399. )
  400. {
  401. if (message == (WM_USER + 101)) {
  402. Render_View ();
  403. } else if (message == WM_KEYDOWN || message == WM_KEYUP) {
  404. //
  405. // Eat the keyboard messages we 'special case'.
  406. //
  407. if (wParam == VK_NUMPAD8 || wParam == VK_NUMPAD2 ||
  408. wParam == VK_NUMPAD4 || wParam == VK_NUMPAD6 ||
  409. wParam == VK_NUMPAD7 || wParam == VK_NUMPAD1)
  410. {
  411. return 0;
  412. }
  413. }
  414. return CDialog::WindowProc (message, wParam, lParam);
  415. }
  416. ////////////////////////////////////////////////////////////////////////////
  417. //
  418. // OnTop
  419. //
  420. /////////////////////////////////////////////////////////////////////////////
  421. void
  422. TransitionEditDialogClass::OnTop (void)
  423. {
  424. Vector3 pos = m_RenderObj->Get_Position ();
  425. Matrix3D transform (1);
  426. transform.Look_At (pos + Vector3 (0, 0, m_LookAtDist), pos, 3.1415926535F);
  427. m_Camera->Set_Transform (transform);
  428. return ;
  429. }
  430. ////////////////////////////////////////////////////////////////////////////
  431. //
  432. // OnFront
  433. //
  434. /////////////////////////////////////////////////////////////////////////////
  435. void
  436. TransitionEditDialogClass::OnFront (void)
  437. {
  438. Vector3 pos = m_RenderObj->Get_Position ();
  439. Matrix3D transform (1);
  440. transform.Look_At (pos + Vector3 (m_LookAtDist, 0, 0), pos, 0);
  441. m_Camera->Set_Transform (transform);
  442. return ;
  443. }
  444. ////////////////////////////////////////////////////////////////////////////
  445. //
  446. // OnLeft
  447. //
  448. /////////////////////////////////////////////////////////////////////////////
  449. void
  450. TransitionEditDialogClass::OnLeft (void)
  451. {
  452. Vector3 pos = m_RenderObj->Get_Position ();
  453. Matrix3D transform (1);
  454. transform.Look_At (pos + Vector3 (0, -m_LookAtDist, 0), pos, 0);
  455. m_Camera->Set_Transform (transform);
  456. return ;
  457. }
  458. ////////////////////////////////////////////////////////////////////////////
  459. //
  460. // OnRight
  461. //
  462. /////////////////////////////////////////////////////////////////////////////
  463. void
  464. TransitionEditDialogClass::OnRight (void)
  465. {
  466. Vector3 pos = m_RenderObj->Get_Position ();
  467. Matrix3D transform (1);
  468. transform.Look_At (pos + Vector3 (0, m_LookAtDist, 0), pos, 0);
  469. m_Camera->Set_Transform (transform);
  470. return ;
  471. }
  472. ////////////////////////////////////////////////////////////////////////////
  473. //
  474. // Load_Object
  475. //
  476. /////////////////////////////////////////////////////////////////////////////
  477. void
  478. TransitionEditDialogClass::Load_Object (void)
  479. {
  480. //
  481. // Determine how big the object is
  482. //
  483. SphereClass sphere = m_RenderObj->Get_Bounding_Sphere ();
  484. m_LookAtDist = sphere.Radius * 1.5F;
  485. m_LookAtDist = max (m_LookAtDist, 4.0F);
  486. //
  487. // Add the render object to the world at 0, 0, 0
  488. //
  489. m_Scene->Add_Render_Object (m_RenderObj);
  490. m_RenderObj->Set_Transform (Matrix3D(Vector3(0, 0, m_Height)));
  491. //
  492. // Add a grid render object to the world to act as a floor
  493. //
  494. RenderObjClass *floor = ::Create_Render_Obj ("GRID");
  495. if (floor != NULL) {
  496. floor->Set_Transform (Matrix3D(1));
  497. m_Scene->Add_Render_Object (floor);
  498. floor->Release_Ref ();
  499. }
  500. return ;
  501. }
  502. ////////////////////////////////////////////////////////////////////////////
  503. //
  504. // Insert_Zone
  505. //
  506. /////////////////////////////////////////////////////////////////////////////
  507. void
  508. TransitionEditDialogClass::Insert_Zone (void)
  509. {
  510. //
  511. // Create the zone and add it to the scene
  512. //
  513. m_Zone = new Box3DClass (Vector3 (1, 1, 1));
  514. m_Zone->Set_Color (Vector3 (0, 0, 0.7F));
  515. //
  516. // Transform the zone from relative to world space coords
  517. //
  518. Matrix3D obj_tm = m_RenderObj->Get_Transform ();
  519. OBBoxClass rel_zone = m_Transition->Get_Zone ();
  520. OBBoxClass zone_box;
  521. OBBoxClass::Transform (obj_tm, rel_zone, &zone_box);
  522. m_Zone->Set_Position (zone_box.Center);
  523. m_Zone->Set_Dimensions (zone_box.Extent * 2.0F);
  524. m_Scene->Add_Render_Object (m_Zone);
  525. return ;
  526. }
  527. ////////////////////////////////////////////////////////////////////////////
  528. //
  529. // Set_Render_Obj
  530. //
  531. /////////////////////////////////////////////////////////////////////////////
  532. void
  533. TransitionEditDialogClass::Set_Render_Obj (RenderObjClass *render_obj)
  534. {
  535. MEMBER_ADD (m_RenderObj, render_obj);
  536. return ;
  537. }
  538. ////////////////////////////////////////////////////////////////////////////
  539. //
  540. // Set_Transition
  541. //
  542. /////////////////////////////////////////////////////////////////////////////
  543. void
  544. TransitionEditDialogClass::Set_Transition (TransitionDataClass *transition)
  545. {
  546. m_Transition = transition;
  547. return ;
  548. }
  549. ////////////////////////////////////////////////////////////////////////////
  550. //
  551. // Handle_Keypress
  552. //
  553. /////////////////////////////////////////////////////////////////////////////
  554. void
  555. TransitionEditDialogClass::Handle_Keypress (void)
  556. {
  557. //
  558. // Determine which speed modifier to use
  559. //
  560. float speed_mod = 1.0F;
  561. if (::GetAsyncKeyState (VK_CONTROL) < 0) {
  562. speed_mod = 3.0F;
  563. }
  564. //
  565. // Move the camera forward-backward (if necessary)
  566. //
  567. if ((::GetAsyncKeyState (VK_NUMPAD8) < 0) ||
  568. (::GetAsyncKeyState (VK_NUMPAD2) < 0)) {
  569. // Get the camera's current position
  570. Vector3 position = m_Camera->Get_Position ();
  571. float orig_z = position.Z;
  572. //
  573. // Determine how far to move the camera
  574. //
  575. float delta = (::GetAsyncKeyState (VK_NUMPAD8) < 0) ? -0.35F : 0.35F;
  576. delta *= speed_mod;
  577. //
  578. // Scale the position along the direction vector
  579. //
  580. Matrix3D transform = m_Camera->Get_Transform ();
  581. position += (delta * transform.Get_Z_Vector ());
  582. //
  583. // Should we lock the z-position?
  584. //
  585. if (::GetAsyncKeyState (VK_CAPITAL) < 0) {
  586. position.Z = orig_z;
  587. }
  588. // Set the camera's new position
  589. m_Camera->Set_Position (position);
  590. }
  591. //
  592. // Pan the camera left-right (if neccessary)
  593. //
  594. if ((::GetAsyncKeyState (VK_NUMPAD4) < 0) ||
  595. (::GetAsyncKeyState (VK_NUMPAD6) < 0)) {
  596. // Get the camera's current position
  597. Vector3 position = m_Camera->Get_Position ();
  598. //
  599. // Determine how far to move the camera
  600. //
  601. float delta = (::GetAsyncKeyState (VK_NUMPAD4) < 0) ? -0.35F : 0.35F;
  602. delta *= speed_mod;
  603. //
  604. // Scale the position along the x-vector
  605. //
  606. Matrix3D transform = m_Camera->Get_Transform ();
  607. position += (delta * transform.Get_X_Vector ());
  608. // Set the camera's new position
  609. m_Camera->Set_Position (position);
  610. }
  611. //
  612. // Elevate the camera up-down (if neccessary)
  613. //
  614. if ((::GetAsyncKeyState (VK_NUMPAD7) < 0) ||
  615. (::GetAsyncKeyState (VK_NUMPAD1) < 0)) {
  616. // Get the camera's current position
  617. Vector3 position = m_Camera->Get_Position ();
  618. //
  619. // Determine how far to move the camera
  620. //
  621. float delta = (::GetAsyncKeyState (VK_NUMPAD1) < 0) ? -0.35F : 0.35F;
  622. delta *= speed_mod;
  623. //
  624. // Scale the position along the x-vector
  625. //
  626. Matrix3D transform = m_Camera->Get_Transform ();
  627. position += (delta * transform.Get_Y_Vector ());
  628. // Set the camera's new position
  629. m_Camera->Set_Position (position);
  630. }
  631. if ((::GetAsyncKeyState (VK_UP) < 0) ||
  632. (::GetAsyncKeyState (VK_DOWN) < 0) ||
  633. (::GetAsyncKeyState (VK_LEFT) < 0) ||
  634. (::GetAsyncKeyState (VK_RIGHT) < 0))
  635. {
  636. float amount = 0.025F;
  637. if (::GetAsyncKeyState (VK_CONTROL) < 0) {
  638. amount *= 4.0F;
  639. }
  640. Vector3 translation(0,0,0);
  641. if (::GetAsyncKeyState (VK_UP) < 0) {
  642. if (::GetAsyncKeyState (VK_SHIFT) < 0) {
  643. translation.Z += amount;
  644. } else {
  645. translation.X += amount;
  646. }
  647. }
  648. if (::GetAsyncKeyState (VK_DOWN) < 0) {
  649. if (::GetAsyncKeyState (VK_SHIFT) < 0) {
  650. translation.Z -= amount;
  651. } else {
  652. translation.X -= amount;
  653. }
  654. }
  655. if (::GetAsyncKeyState (VK_RIGHT) < 0) {
  656. translation.Y += amount;
  657. }
  658. if (::GetAsyncKeyState (VK_LEFT) < 0) {
  659. translation.Y -= amount;
  660. }
  661. //
  662. // Move the zone
  663. //
  664. if (m_IsEditingZone) {
  665. Matrix3D tm = m_Zone->Get_Transform ();
  666. tm.Translate (translation);
  667. m_Zone->Set_Transform (tm);
  668. }
  669. //
  670. // Size the Zone
  671. //
  672. if (m_IsSizingZone) {
  673. Vector3 size = m_Zone->Get_Dimensions ();
  674. size += translation;
  675. m_Zone->Set_Dimensions (size);
  676. }
  677. //
  678. // Move the character
  679. //
  680. if (m_IsEditingChar) {
  681. Matrix3D tm = m_CharacterObj->Get_Transform ();
  682. tm.Set_Translation (tm.Get_Translation () + translation);
  683. m_CharacterObj->Set_Transform (tm);
  684. }
  685. //
  686. // Rotate the character
  687. //
  688. if ( m_IsRotatingChar &&
  689. ((::GetAsyncKeyState (VK_RIGHT) < 0) ||
  690. (::GetAsyncKeyState (VK_LEFT) < 0)) )
  691. {
  692. Matrix3D tm = m_CharacterObj->Get_Transform ();
  693. float deg = (::GetAsyncKeyState (VK_RIGHT) < 0) ? 5.0F : -5.0F;
  694. tm.Rotate_Z (DEG_TO_RAD (deg));
  695. m_CharacterObj->Set_Transform (tm);
  696. }
  697. Update_Status ();
  698. }
  699. return ;
  700. }
  701. ////////////////////////////////////////////////////////////////////////////
  702. //
  703. // Update_Status
  704. //
  705. /////////////////////////////////////////////////////////////////////////////
  706. void
  707. TransitionEditDialogClass::Update_Status (void)
  708. {
  709. //
  710. // Update the zone's status
  711. //
  712. Vector3 zone_pos = m_Zone->Get_Transform ().Get_Translation ();
  713. Vector3 zone_size = m_Zone->Get_Dimensions ();
  714. CString status;
  715. status.Format ("Zone Pos (%.2f, %.2f, %.2f)\nZone Size (%.2f, %.2f, %.2f)",
  716. zone_pos.X, zone_pos.Y, zone_pos.Z,
  717. zone_size.X, zone_size.Y, zone_size.Z);
  718. SetDlgItemText (IDC_ZONE_STATUS, status);
  719. //
  720. // Update the character's status
  721. //
  722. Vector3 char_pos = m_CharacterObj->Get_Transform ().Get_Translation ();
  723. float char_rot = m_CharacterObj->Get_Transform ().Get_Z_Rotation ();
  724. status.Format ("Char Pos (%.2f, %.2f, %.2f)\nChar Rot (%.2f)",
  725. char_pos.X, char_pos.Y, char_pos.Z,
  726. RAD_TO_DEG (char_rot));
  727. SetDlgItemText (IDC_CHAR_STATUS, status);
  728. return ;
  729. }
  730. ////////////////////////////////////////////////////////////////////////////
  731. //
  732. // Fill_Trigger_List
  733. //
  734. /////////////////////////////////////////////////////////////////////////////
  735. void
  736. TransitionEditDialogClass::Fill_Trigger_List (void)
  737. {
  738. int type_to_sel = (int)m_Transition->Get_Type ();
  739. int count = TransitionDataClass::Get_Num_Types ();
  740. for (int index = 0; index < count; index ++) {
  741. LPCTSTR name = TransitionDataClass::Get_Type_Name ((TransitionDataClass::StyleType)index);
  742. int item_index = m_TriggerList.AddString (name);
  743. if (index == type_to_sel) {
  744. m_TriggerList.SetCurSel (item_index);
  745. }
  746. }
  747. return ;
  748. }
  749. ////////////////////////////////////////////////////////////////////////////
  750. //
  751. // Fill_Animation_List
  752. //
  753. /////////////////////////////////////////////////////////////////////////////
  754. void
  755. TransitionEditDialogClass::Fill_Animation_List (void)
  756. {
  757. int index = 0;
  758. //
  759. // Generate a list of animation files
  760. //
  761. DynamicVectorClass<StringClass> file_list;
  762. file_list.Set_Growth_Step (500);
  763. #ifdef PUBLIC_EDITOR_VER
  764. MixFileDatabaseClass::Get_Instance ()->Find_Files (file_list, "h_a_*.w3d");
  765. #else
  766. //
  767. // Generate a list of animation files
  768. //
  769. DynamicVectorClass<CString> temp_file_list;
  770. CString path = ::Get_File_Mgr()->Make_Full_Path (CHAR_ANIMS_PATH);
  771. ::Get_File_Mgr ()->Find_Files (path, "*.w3d", temp_file_list, true);
  772. for (index = 0; index < temp_file_list.Count (); index ++) {
  773. file_list.Add ((const char *)temp_file_list[index]);
  774. }
  775. #endif //PUBLIC_EDITOR_VER
  776. //
  777. // Populate the combobox
  778. //
  779. bool selected = false;
  780. for (index = 0; index < file_list.Count (); index ++) {
  781. StringClass &filename = file_list[index];
  782. CString animation_name = ::Asset_Name_From_Filename (filename);
  783. //
  784. // Add this entry to the animation combobox
  785. //
  786. int cb_index = m_AnimationList.AddString (animation_name);
  787. if (cb_index != CB_ERR) {
  788. m_AnimationList.SetItemData (cb_index, (ULONG)::_strdup ((LPCTSTR)filename));
  789. //
  790. // Should we select this animation by default?
  791. //
  792. CString name = m_Transition->Get_Animation_Name ();
  793. CString real_name = name;
  794. LPCTSTR suffix = ::strstr (name, ".");
  795. if (suffix != NULL) {
  796. real_name = suffix + 1;
  797. }
  798. if (::lstrcmpi (animation_name, real_name) == 0) {
  799. m_AnimationList.SetCurSel (cb_index);
  800. selected = true;
  801. }
  802. }
  803. }
  804. if (!selected) {
  805. m_AnimationList.SetCurSel (0);
  806. }
  807. return ;
  808. }
  809. ////////////////////////////////////////////////////////////////////////////
  810. //
  811. // OnEditChar
  812. //
  813. /////////////////////////////////////////////////////////////////////////////
  814. void
  815. TransitionEditDialogClass::OnEditChar (void)
  816. {
  817. m_IsEditingChar = (SendDlgItemMessage (IDC_EDIT_CHAR, BM_GETCHECK) == 1);
  818. return ;
  819. }
  820. ////////////////////////////////////////////////////////////////////////////
  821. //
  822. // OnEditZone
  823. //
  824. /////////////////////////////////////////////////////////////////////////////
  825. void
  826. TransitionEditDialogClass::OnEditZone (void)
  827. {
  828. m_IsEditingZone = (SendDlgItemMessage (IDC_EDIT_ZONE, BM_GETCHECK) == 1);
  829. return ;
  830. }
  831. ////////////////////////////////////////////////////////////////////////////
  832. //
  833. // Load_Animation
  834. //
  835. /////////////////////////////////////////////////////////////////////////////
  836. void
  837. TransitionEditDialogClass::Load_Animation (void)
  838. {
  839. //
  840. // Determine which animation file to load
  841. //
  842. int index = m_AnimationList.GetCurSel ();
  843. if (index != CB_ERR) {
  844. LPCTSTR filename = (LPCTSTR)m_AnimationList.GetItemData (index);
  845. //
  846. // Load the animation from the file
  847. //
  848. if (filename != NULL) {
  849. Load_Animation (filename);
  850. }
  851. }
  852. return ;
  853. }
  854. ////////////////////////////////////////////////////////////////////////////
  855. //
  856. // Load_Animation
  857. //
  858. /////////////////////////////////////////////////////////////////////////////
  859. void
  860. TransitionEditDialogClass::Load_Animation (LPCTSTR filename)
  861. {
  862. //
  863. // Create the character if necessary
  864. //
  865. Load_Character ();
  866. MEMBER_RELEASE (m_Animation);
  867. //
  868. // Load the new animation
  869. //
  870. CString path = ::Strip_Filename_From_Path (filename);
  871. CString asset_name = CString ("S_A_HUMAN.") + ::Asset_Name_From_Filename (filename);
  872. ::Set_Current_Directory (path);
  873. m_Animation = WW3DAssetManager::Get_Instance ()->Get_HAnim (asset_name);
  874. ASSERT (m_Animation != NULL);
  875. //
  876. // Pass the new animation onto the character
  877. //
  878. m_CurrFrame = 0;
  879. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  880. return ;
  881. }
  882. ////////////////////////////////////////////////////////////////////////////
  883. //
  884. // Load_Character
  885. //
  886. /////////////////////////////////////////////////////////////////////////////
  887. void
  888. TransitionEditDialogClass::Load_Character (void)
  889. {
  890. if (m_CharacterObj == NULL) {
  891. //
  892. // Create the character's render object
  893. //
  894. SoldierGameObjDef *definition = (SoldierGameObjDef *)DefinitionMgrClass::Find_Typed_Definition ("Commando", CLASSID_GAME_OBJECT_DEF_SOLDIER, false);
  895. if (definition != NULL) {
  896. SoldierGameObj *game_obj = new SoldierGameObj;
  897. game_obj->Init (*definition);
  898. REF_PTR_SET (m_CharacterObj, game_obj->Peek_Model ());
  899. game_obj->Set_Delete_Pending ();
  900. }
  901. //
  902. // Transform the character from relative to world space coords
  903. //
  904. Matrix3D obj_tm = m_RenderObj->Get_Transform ();
  905. Matrix3D char_tm = m_Transition->Get_Ending_TM ();
  906. char_tm = char_tm * obj_tm;
  907. m_CharacterObj->Set_Transform (char_tm);
  908. //
  909. // Add the character to the world
  910. //
  911. m_Scene->Add_Render_Object (m_CharacterObj);
  912. }
  913. return ;
  914. }
  915. ////////////////////////////////////////////////////////////////////////////
  916. //
  917. // OnSelChangeAnimationList
  918. //
  919. /////////////////////////////////////////////////////////////////////////////
  920. void
  921. TransitionEditDialogClass::OnSelChangeAnimationList (void)
  922. {
  923. Load_Animation ();
  924. return ;
  925. }
  926. ////////////////////////////////////////////////////////////////////////////
  927. //
  928. // fn3DWindow
  929. //
  930. /////////////////////////////////////////////////////////////////////////////
  931. LRESULT CALLBACK
  932. TransitionEditDialogClass::fn3DWindow
  933. (
  934. HWND hwnd,
  935. UINT message,
  936. WPARAM wparam,
  937. LPARAM lparam
  938. )
  939. {
  940. if (message == WM_LBUTTONDOWN) {
  941. TransitionEditDialogClass *dialog = NULL;
  942. dialog = (TransitionEditDialogClass *)::GetProp (hwnd, "TRANSITION_DIALOG");
  943. dialog->Handle_LBUTTON_DOWN (wparam, lparam);
  944. } else if (message == WM_LBUTTONUP) {
  945. TransitionEditDialogClass *dialog = NULL;
  946. dialog = (TransitionEditDialogClass *)::GetProp (hwnd, "TRANSITION_DIALOG");
  947. dialog->Handle_LBUTTON_UP (wparam, lparam);
  948. } else if (message == WM_MOUSEMOVE) {
  949. TransitionEditDialogClass *dialog = NULL;
  950. dialog = (TransitionEditDialogClass *)::GetProp (hwnd, "TRANSITION_DIALOG");
  951. dialog->Handle_MOUSEMOVE (wparam, lparam);
  952. }
  953. return ::DefWindowProc (hwnd, message, wparam, lparam);
  954. }
  955. ////////////////////////////////////////////////////////////////////////////
  956. //
  957. // Handle_LBUTTON_DOWN
  958. //
  959. /////////////////////////////////////////////////////////////////////////////
  960. void
  961. TransitionEditDialogClass::Handle_LBUTTON_DOWN (WPARAM wparam, LPARAM lparam)
  962. {
  963. ::SetCapture (::GetDlgItem (m_hWnd, IDC_3D_WINDOW));
  964. m_LastPoint.x = LOWORD (lparam);
  965. m_LastPoint.y = HIWORD (lparam);
  966. return ;
  967. }
  968. ////////////////////////////////////////////////////////////////////////////
  969. //
  970. // Handle_LBUTTON_UP
  971. //
  972. /////////////////////////////////////////////////////////////////////////////
  973. void
  974. TransitionEditDialogClass::Handle_LBUTTON_UP (WPARAM wparam, LPARAM lparam)
  975. {
  976. ::ReleaseCapture ();
  977. return ;
  978. }
  979. ////////////////////////////////////////////////////////////////////////////
  980. //
  981. // Handle_MOUSEMOVE
  982. //
  983. /////////////////////////////////////////////////////////////////////////////
  984. void
  985. TransitionEditDialogClass::Handle_MOUSEMOVE (WPARAM wparam, LPARAM lparam)
  986. {
  987. POINT point = { LOWORD (lparam), HIWORD (lparam) };
  988. WWASSERT (m_Camera != NULL);
  989. if ((wparam & MK_LBUTTON) && (wparam & MK_RBUTTON)) {
  990. float delta_x = float(m_LastPoint.x - point.x) / 32;
  991. float delta_y = float(point.y - m_LastPoint.y) / 32;
  992. //
  993. // Scale the position along the direction vector
  994. //
  995. Vector3 position = m_Camera->Get_Position ();
  996. Matrix3D transform = m_Camera->Get_Transform ();
  997. position += (delta_x * transform.Get_X_Vector ());
  998. position += (delta_y * transform.Get_Y_Vector ());
  999. // Set the camera's new position
  1000. m_Camera->Set_Position (position);
  1001. } else if (wparam & MK_LBUTTON) {
  1002. //
  1003. // Orbit the camera around the object
  1004. //
  1005. if (::GetCapture () == ::GetDlgItem (m_hWnd, IDC_3D_WINDOW)) {
  1006. ::Trackball_Camera ( ::GetDlgItem (m_hWnd, IDC_3D_WINDOW),
  1007. *m_Camera,
  1008. Vector3 (0, 0, 0),
  1009. point,
  1010. m_LastPoint );
  1011. }
  1012. } else if (wparam & MK_RBUTTON) {
  1013. float delta = float(m_LastPoint.y - point.y) / 12;
  1014. //
  1015. // Scale the position along the direction vector
  1016. //
  1017. Vector3 position = m_Camera->Get_Position ();
  1018. Matrix3D transform = m_Camera->Get_Transform ();
  1019. position += (delta * transform.Get_Z_Vector ());
  1020. // Set the camera's new position
  1021. m_Camera->Set_Position (position);
  1022. }
  1023. m_LastPoint = point;
  1024. return ;
  1025. }
  1026. ////////////////////////////////////////////////////////////////////////////
  1027. //
  1028. // Trackball_Camera
  1029. //
  1030. /////////////////////////////////////////////////////////////////////////////
  1031. void
  1032. Trackball_Camera
  1033. (
  1034. HWND hwnd,
  1035. CameraClass & camera,
  1036. const Vector3 & center,
  1037. POINT point,
  1038. POINT last_point
  1039. )
  1040. {
  1041. RECT rect;
  1042. ::GetClientRect (hwnd, &rect);
  1043. //
  1044. // Convert the points to normalized units
  1045. //
  1046. float mid_point_x = float(rect.right >> 1);
  1047. float mid_point_y = float(rect.bottom >> 1);
  1048. float last_point_x = ((float)last_point.x - mid_point_x) / mid_point_x;
  1049. float last_point_y = (mid_point_y - (float)last_point.y) / mid_point_y;
  1050. float point_x = ((float)point.x - mid_point_x) / mid_point_x;
  1051. float point_y = (mid_point_y - (float)point.y) / mid_point_y;
  1052. //
  1053. // Calculate the orbit
  1054. //
  1055. Quaternion rotation = ::Trackball (last_point_x, last_point_y, point_x, point_y, 0.8F);
  1056. //
  1057. // Get the transformation matrix for the camera and its inverse
  1058. //
  1059. Matrix3D transform = camera.Get_Transform ();
  1060. Matrix3D inv_tm;
  1061. transform.Get_Orthogonal_Inverse (inv_tm);
  1062. //
  1063. // Translate to the object's center, perform the rotation, then translate back out.
  1064. //
  1065. Vector3 to_object = inv_tm * center;
  1066. transform.Translate (to_object);
  1067. Matrix3D::Multiply (transform, Build_Matrix3D (rotation), &transform);
  1068. transform.Translate (-to_object);
  1069. // Pass the new trnasform onto the camera
  1070. camera.Set_Transform (transform);
  1071. return ;
  1072. }
  1073. ////////////////////////////////////////////////////////////////////////////
  1074. //
  1075. // PreTranslateMessage
  1076. //
  1077. /////////////////////////////////////////////////////////////////////////////
  1078. BOOL
  1079. TransitionEditDialogClass::PreTranslateMessage (MSG *pMsg)
  1080. {
  1081. if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP) {
  1082. if (pMsg->wParam == VK_NUMPAD8 || pMsg->wParam == VK_NUMPAD2 ||
  1083. pMsg->wParam == VK_NUMPAD4 || pMsg->wParam == VK_NUMPAD6 ||
  1084. pMsg->wParam == VK_NUMPAD7 || pMsg->wParam == VK_NUMPAD1 ||
  1085. pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN ||
  1086. pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT)
  1087. {
  1088. return 1;
  1089. }
  1090. }
  1091. return CDialog::PreTranslateMessage(pMsg);
  1092. }
  1093. ////////////////////////////////////////////////////////////////////////////
  1094. //
  1095. // OnAniBackFrame
  1096. //
  1097. /////////////////////////////////////////////////////////////////////////////
  1098. void
  1099. TransitionEditDialogClass::OnAniBackFrame (void)
  1100. {
  1101. m_CurrFrame -= 1.0F;
  1102. if (m_CurrFrame < 0) {
  1103. m_CurrFrame = float(m_Animation->Get_Num_Frames () - 1);
  1104. }
  1105. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1106. m_IsAnimating = false;
  1107. return ;
  1108. }
  1109. ////////////////////////////////////////////////////////////////////////////
  1110. //
  1111. // OnAniFirstFrame
  1112. //
  1113. /////////////////////////////////////////////////////////////////////////////
  1114. void
  1115. TransitionEditDialogClass::OnAniFirstFrame (void)
  1116. {
  1117. m_CurrFrame = 0;
  1118. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1119. m_IsAnimating = false;
  1120. return ;
  1121. }
  1122. ////////////////////////////////////////////////////////////////////////////
  1123. //
  1124. // OnAniFwdFrame
  1125. //
  1126. /////////////////////////////////////////////////////////////////////////////
  1127. void
  1128. TransitionEditDialogClass::OnAniFwdFrame (void)
  1129. {
  1130. m_CurrFrame += 1;
  1131. if (m_CurrFrame >= float(m_Animation->Get_Num_Frames () - 1)) {
  1132. m_CurrFrame = 0;
  1133. }
  1134. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1135. m_IsAnimating = false;
  1136. return ;
  1137. }
  1138. ////////////////////////////////////////////////////////////////////////////
  1139. //
  1140. // OnAniLastFrame
  1141. //
  1142. /////////////////////////////////////////////////////////////////////////////
  1143. void
  1144. TransitionEditDialogClass::OnAniLastFrame (void)
  1145. {
  1146. m_CurrFrame = float(m_Animation->Get_Num_Frames () - 1);
  1147. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1148. m_IsAnimating = false;
  1149. return ;
  1150. }
  1151. ////////////////////////////////////////////////////////////////////////////
  1152. //
  1153. // OnAniPause
  1154. //
  1155. /////////////////////////////////////////////////////////////////////////////
  1156. void
  1157. TransitionEditDialogClass::OnAniPause (void)
  1158. {
  1159. m_IsAnimating = false;
  1160. return ;
  1161. }
  1162. ////////////////////////////////////////////////////////////////////////////
  1163. //
  1164. // OnAniPlay
  1165. //
  1166. /////////////////////////////////////////////////////////////////////////////
  1167. void
  1168. TransitionEditDialogClass::OnAniPlay (void)
  1169. {
  1170. m_IsAnimating = true;
  1171. m_LastAnimUpdate = ::GetTickCount ();
  1172. return ;
  1173. }
  1174. ////////////////////////////////////////////////////////////////////////////
  1175. //
  1176. // OnAniStop
  1177. //
  1178. /////////////////////////////////////////////////////////////////////////////
  1179. void
  1180. TransitionEditDialogClass::OnAniStop (void)
  1181. {
  1182. m_CurrFrame = 0;
  1183. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1184. m_IsAnimating = false;
  1185. return ;
  1186. }
  1187. ////////////////////////////////////////////////////////////////////////////
  1188. //
  1189. // Update_Animation
  1190. //
  1191. /////////////////////////////////////////////////////////////////////////////
  1192. void
  1193. TransitionEditDialogClass::Update_Animation (void)
  1194. {
  1195. if (m_IsAnimating) {
  1196. DWORD curr_ticks = ::GetTickCount ();
  1197. float seconds = float((curr_ticks - m_LastAnimUpdate)/1000.0F);
  1198. float frame_inc = seconds * m_Animation->Get_Frame_Rate ();
  1199. m_CurrFrame += frame_inc;
  1200. if (m_CurrFrame > float(m_Animation->Get_Num_Frames ())) {
  1201. m_CurrFrame -= float(m_Animation->Get_Num_Frames ());
  1202. }
  1203. m_CharacterObj->Set_Animation (m_Animation, m_CurrFrame);
  1204. m_LastAnimUpdate = curr_ticks;
  1205. }
  1206. return ;
  1207. }
  1208. ////////////////////////////////////////////////////////////////////////////
  1209. //
  1210. // OnSizeZone
  1211. //
  1212. /////////////////////////////////////////////////////////////////////////////
  1213. void
  1214. TransitionEditDialogClass::OnSizeZone (void)
  1215. {
  1216. m_IsSizingZone = (m_SizeZoneCheck.GetCheck () == 1);
  1217. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_EDIT_ZONE), !m_IsSizingZone);
  1218. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_EDIT_CHAR), !m_IsSizingZone);
  1219. if (m_IsSizingZone) {
  1220. m_IsEditingZone = false;
  1221. m_IsEditingChar = false;
  1222. m_IsRotatingChar = false;
  1223. m_RotateCharCheck.SetCheck (false);
  1224. } else {
  1225. OnEditChar ();
  1226. OnEditZone ();
  1227. }
  1228. return ;
  1229. }
  1230. ////////////////////////////////////////////////////////////////////////////
  1231. //
  1232. // OnRotateChar
  1233. //
  1234. /////////////////////////////////////////////////////////////////////////////
  1235. void
  1236. TransitionEditDialogClass::OnRotateChar (void)
  1237. {
  1238. m_IsRotatingChar = (m_RotateCharCheck.GetCheck () == 1);
  1239. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_EDIT_ZONE), !m_IsRotatingChar);
  1240. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_EDIT_CHAR), !m_IsRotatingChar);
  1241. if (m_IsRotatingChar) {
  1242. m_IsEditingZone = false;
  1243. m_IsEditingChar = false;
  1244. m_IsSizingZone = false;
  1245. m_SizeZoneCheck.SetCheck (false);
  1246. } else {
  1247. OnEditChar ();
  1248. OnEditZone ();
  1249. }
  1250. return ;
  1251. }