MouseMgr.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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. /***********************************************************************************************
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/MouseMgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/25/02 4:38p $*
  29. * *
  30. * $Revision:: 13 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "mousemgr.h"
  37. #include "utils.h"
  38. #include "leveleditview.h"
  39. #include "cameramgr.h"
  40. #include "node.h"
  41. #include "quat.h"
  42. #include "groupmgr.h"
  43. #include "resource.h"
  44. #include "sceneeditor.h"
  45. #include "collisiongroups.h"
  46. #include "mover.h"
  47. #include "waypathnode.h"
  48. #include "heightfieldeditor.h"
  49. ///////////////////////////////////////////////////////////////
  50. //
  51. // MouseMgrClass
  52. //
  53. ///////////////////////////////////////////////////////////////
  54. MouseMgrClass::MouseMgrClass (void) :
  55. m_MouseMode (MODE_OBJECT_MANIPULATE),
  56. IsLButtonDown (false),
  57. IsRButtonDown (false)
  58. {
  59. // Allocate each entry in the state table
  60. m_pModeObjects[MOUSE_MODE::MODE_CAMERA_DEFAULT] = new MMCameraDefaultClass;
  61. m_pModeObjects[MOUSE_MODE::MODE_CAMERA_WALK] = new MMCameraWalkClass;
  62. m_pModeObjects[MOUSE_MODE::MODE_CAMERA_FLY] = new MMCameraFlyClass;
  63. m_pModeObjects[MOUSE_MODE::MODE_CAMERA_ORBIT] = new MMCameraOrbitClass;
  64. m_pModeObjects[MOUSE_MODE::MODE_OBJECT_DROP] = new MMObjectDropClass;
  65. m_pModeObjects[MOUSE_MODE::MODE_OBJECT_MANIPULATE] = new MMObjectManipulateClass;
  66. m_pModeObjects[MOUSE_MODE::MODE_OBJECT_SELECT] = new MMObjectSelectClass;
  67. m_pModeObjects[MOUSE_MODE::MODE_GRABHANDLE_DRAG] = new MMGrabHandleDragClass;
  68. m_pModeObjects[MOUSE_MODE::MODE_WAYPATH_EDIT] = new MMWaypathEditClass;
  69. m_pModeObjects[MOUSE_MODE::MODE_HEIGHTFIELD_EDIT] = new MMHeightfieldEditClass;
  70. return ;
  71. }
  72. ///////////////////////////////////////////////////////////////
  73. //
  74. // ~MouseMgrClass
  75. //
  76. ///////////////////////////////////////////////////////////////
  77. MouseMgrClass::~MouseMgrClass (void)
  78. {
  79. // Free the state table
  80. for (int mode = 0; mode < MOUSE_MODE::MODE_COUNT; mode ++) {
  81. SAFE_DELETE (m_pModeObjects[mode]);
  82. m_pModeObjects[mode] = NULL;
  83. }
  84. return ;
  85. }
  86. ///////////////////////////////////////////////////////////////
  87. //
  88. // Move_Node
  89. //
  90. ///////////////////////////////////////////////////////////////
  91. void
  92. MouseMgrClass::Move_Node (NodeClass *node)
  93. {
  94. ::Get_Scene_Editor ()->Set_Selection (node);
  95. Set_Mouse_Mode (MouseMgrClass::MODE_OBJECT_MANIPULATE);
  96. ((MMObjectManipulateClass *)m_pModeObjects[MOUSE_MODE::MODE_OBJECT_MANIPULATE])->Set_Move_Nodes_Mode ();
  97. return ;
  98. }
  99. ///////////////////////////////////////////////////////////////
  100. //
  101. // Set_Mouse_Mode
  102. //
  103. ///////////////////////////////////////////////////////////////
  104. void
  105. MouseMgrClass::Set_Mouse_Mode (MOUSE_MODE new_mode)
  106. {
  107. //
  108. // Change the camera mode
  109. //
  110. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  111. cameramgr->Set_Camera_Mode (m_pModeObjects[new_mode]->m_LButtonMode);
  112. if (m_MouseMode != new_mode) {
  113. //
  114. // Notify the old mode that it is ending
  115. //
  116. m_pModeObjects[m_MouseMode]->On_Mode_Exit ();
  117. //
  118. // Set the new mode
  119. //
  120. m_MouseMode = new_mode;
  121. m_pModeObjects[m_MouseMode]->On_Mode_Set ();
  122. }
  123. return ;
  124. }
  125. ///////////////////////////////////////////////////////////////
  126. //
  127. // Handle_LButton_Down
  128. //
  129. ///////////////////////////////////////////////////////////////
  130. void
  131. MouseModeClass::Handle_LButton_Down
  132. (
  133. UINT flags,
  134. CPoint point
  135. )
  136. {
  137. // Default new mode is lbutton down only
  138. CameraMgr::CAMERA_MODE new_mode = m_LButtonMode;
  139. //
  140. // If both buttons are down, then set that mode
  141. //
  142. if (flags & MK_RBUTTON) {
  143. new_mode = m_BothButtonMode;
  144. }
  145. //
  146. // Change the camera mode
  147. //
  148. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  149. cameramgr->Set_Camera_Mode (new_mode);
  150. m_bUpdate = true;
  151. m_LastMousePoint = point;
  152. ::Get_Main_View ()->SetCapture ();
  153. return ;
  154. }
  155. ///////////////////////////////////////////////////////////////
  156. //
  157. // Handle_LButton_Up
  158. //
  159. ///////////////////////////////////////////////////////////////
  160. void
  161. MouseModeClass::Handle_LButton_Up
  162. (
  163. UINT flags,
  164. CPoint point
  165. )
  166. {
  167. // Is the right button down?
  168. if (flags & MK_RBUTTON) {
  169. // Change the camera mode
  170. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  171. cameramgr->Set_Camera_Mode (m_RButtonMode);
  172. } else {
  173. // No need to update the camera anymore
  174. m_bUpdate = false;
  175. ReleaseCapture ();
  176. }
  177. m_LastMousePoint = point;
  178. return ;
  179. }
  180. ///////////////////////////////////////////////////////////////
  181. //
  182. // Handle_RButton_Down
  183. //
  184. ///////////////////////////////////////////////////////////////
  185. void
  186. MouseModeClass::Handle_RButton_Down
  187. (
  188. UINT flags,
  189. CPoint point
  190. )
  191. {
  192. // Default new mode is rbutton down only
  193. CameraMgr::CAMERA_MODE new_mode = m_RButtonMode;
  194. //
  195. // If both buttons are down, then set that mode
  196. //
  197. if (flags & MK_LBUTTON) {
  198. new_mode = m_BothButtonMode;
  199. }
  200. //
  201. // Change the camera mode
  202. //
  203. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  204. cameramgr->Set_Camera_Mode (new_mode);
  205. m_bUpdate = true;
  206. m_LastMousePoint = point;
  207. ::Get_Main_View ()->SetCapture ();
  208. return ;
  209. }
  210. ///////////////////////////////////////////////////////////////
  211. //
  212. // Handle_RButton_Up
  213. //
  214. ///////////////////////////////////////////////////////////////
  215. void
  216. MouseModeClass::Handle_RButton_Up
  217. (
  218. UINT flags,
  219. CPoint point
  220. )
  221. {
  222. // Is the right button down?
  223. if (flags & MK_LBUTTON) {
  224. // Change the camera mode
  225. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  226. cameramgr->Set_Camera_Mode (m_LButtonMode);
  227. } else {
  228. // No need to update the camera anymore
  229. m_bUpdate = false;
  230. ReleaseCapture ();
  231. }
  232. m_LastMousePoint = point;
  233. return ;
  234. }
  235. ///////////////////////////////////////////////////////////////
  236. //
  237. // Handle_Mouse_Move
  238. //
  239. ///////////////////////////////////////////////////////////////
  240. void
  241. MouseModeClass::Handle_Mouse_Move
  242. (
  243. UINT flags,
  244. CPoint point
  245. )
  246. {
  247. m_MousePoint = point;
  248. if (m_bUpdate) {
  249. CLevelEditView *view = Get_Main_View ();
  250. // Get the bouding rectangle of the main view
  251. RECT rect;
  252. view->GetClientRect (&rect);
  253. //
  254. // Calculcate the delta's for both x and y as a scaled percent from 0 to 1.
  255. //
  256. float deltax = (float(point.x - m_LastMousePoint.x))/(float(rect.right - rect.left));
  257. float deltay = (float(point.y - m_LastMousePoint.y))/(float(rect.bottom - rect.top));
  258. // Have the camera manager update the display based on the deltas
  259. CameraMgr *cameramgr = ::Get_Camera_Mgr ();
  260. cameramgr->Update_Camera (deltax, deltay);
  261. // This point now becomes our last point
  262. m_LastMousePoint = point;
  263. }
  264. return ;
  265. }
  266. //**********************************************************************************************
  267. //*
  268. //* Start of MMObjectManipulateClass
  269. //*
  270. //**********************************************************************************************
  271. /////////////////////////////////////////////////////////////
  272. //
  273. // Change_Operation
  274. //
  275. ///////////////////////////////////////////////////////////////
  276. void
  277. MMObjectManipulateClass::Change_Operation (OBJECT_MODE type)
  278. {
  279. if (type != m_ObjectMode) {
  280. // Let the scene editor know we are ending a previous operation
  281. if ((m_ObjectMode == MODE_MOVE) ||
  282. (m_ObjectMode == MODE_ROTATE)) {
  283. ::Get_Scene_Editor ()->End_Operation ();
  284. }
  285. // Remember our new mode
  286. m_ObjectMode = type;
  287. // Let the scene editor know we staring a new operation
  288. if (m_ObjectMode == MODE_MOVE) {
  289. ::Get_Scene_Editor ()->Begin_Operation (OPERATION_MOVE);
  290. //
  291. // Determine where our initial point is
  292. //
  293. Matrix3D coord_system (1);
  294. m_CurrentMovePos = MoverClass::Calc_New_Position (coord_system, m_IntersectPoint);
  295. } else if (m_ObjectMode == MODE_ROTATE) {
  296. ::Get_Scene_Editor ()->Begin_Operation (OPERATION_ROTATE);
  297. }
  298. }
  299. m_ForceDropToGround = false;
  300. return ;
  301. }
  302. /////////////////////////////////////////////////////////////
  303. //
  304. // Handle_LButton_Dblclk
  305. //
  306. ///////////////////////////////////////////////////////////////
  307. void
  308. MMObjectManipulateClass::Handle_LButton_Dblclk
  309. (
  310. UINT flags,
  311. CPoint point
  312. )
  313. {
  314. // Allow the base class to process this message
  315. MouseModeClass::Handle_LButton_Dblclk (flags, point);
  316. // Find the item the user clicked on
  317. NodeClass *node = ::Get_Scene_Editor ()->Find_Node_At_Point (point);
  318. if (node != NULL) {
  319. //
  320. // Display the settings dialog for this node
  321. //
  322. node->Show_Settings_Dialog ();
  323. }
  324. return ;
  325. }
  326. ///////////////////////////////////////////////////////////////
  327. //
  328. // Handle_LButton_Down
  329. //
  330. ///////////////////////////////////////////////////////////////
  331. void
  332. MMObjectManipulateClass::Handle_LButton_Down
  333. (
  334. UINT flags,
  335. CPoint point
  336. )
  337. {
  338. // Allow the base class to process this message
  339. MouseModeClass::Handle_LButton_Down (flags, point);
  340. //
  341. // If there was no 'special' functionality at this point (like grab handles)
  342. // then process as normal
  343. //
  344. if (::Get_Scene_Editor ()->Execute_Function_At_Point (point) == false) {
  345. // Only the left mouse button is down so we are
  346. // in select mode
  347. Change_Operation (MODE_SELECT);
  348. //
  349. // Determine which node the user clicked on (and where)
  350. //
  351. NodeClass *node = ::Get_Scene_Editor ()->Find_Node_At_Point (point, &m_IntersectPoint);
  352. //
  353. // Either toggle the selection state of this node,
  354. // or reset the selection group to contain only this node.
  355. //
  356. if (flags & MK_CONTROL) {
  357. ::Get_Scene_Editor ()->Toggle_Selection (node);
  358. } else {
  359. ::Get_Scene_Editor ()->Set_Selection (node);
  360. }
  361. // Make sure we have the mouse captured
  362. ::Get_Main_View ()->SetCapture ();
  363. m_LastMousePoint = point;
  364. } else {
  365. Change_Operation (MODE_NONE);
  366. ::ReleaseCapture ();
  367. }
  368. return ;
  369. }
  370. ///////////////////////////////////////////////////////////////
  371. //
  372. // Handle_LButton_Up
  373. //
  374. ///////////////////////////////////////////////////////////////
  375. void
  376. MMObjectManipulateClass::Handle_LButton_Up
  377. (
  378. UINT flags,
  379. CPoint point
  380. )
  381. {
  382. MouseModeClass::Handle_LButton_Up (flags, point);
  383. // Is the right mouse button down?
  384. if (flags & MK_RBUTTON) {
  385. // Only the right button is down so we are in rotate mode
  386. Change_Operation (MODE_ROTATE);
  387. // Make sure we have the mouse captured
  388. ::Get_Main_View ()->SetCapture ();
  389. m_bUpdate = true;
  390. } else {
  391. // No buttons are down so release the mouse capture
  392. ::ReleaseCapture ();
  393. Change_Operation (MODE_NONE);
  394. }
  395. return ;
  396. }
  397. ///////////////////////////////////////////////////////////////
  398. //
  399. // Handle_RButton_Down
  400. //
  401. ///////////////////////////////////////////////////////////////
  402. void
  403. MMObjectManipulateClass::Handle_RButton_Down
  404. (
  405. UINT flags,
  406. CPoint point
  407. )
  408. {
  409. MouseModeClass::Handle_RButton_Down (flags, point);
  410. if (flags & MK_LBUTTON) {
  411. ::Get_Selection_Mgr ().Clone_Group ();
  412. } else {
  413. // Only the right mouse button is down so we are
  414. // in select mode
  415. Change_Operation (MODE_ROTATE);
  416. }
  417. // Make sure we have the mouse captured
  418. ::Get_Main_View ()->SetCapture ();
  419. m_LastMousePoint = point;
  420. return ;
  421. }
  422. ///////////////////////////////////////////////////////////////
  423. //
  424. // Handle_RButton_Up
  425. //
  426. ///////////////////////////////////////////////////////////////
  427. void
  428. MMObjectManipulateClass::Handle_RButton_Up
  429. (
  430. UINT flags,
  431. CPoint point
  432. )
  433. {
  434. MouseModeClass::Handle_RButton_Up (flags, point);
  435. // Is the left mouse button down?
  436. if (flags & MK_LBUTTON) {
  437. // Only the left button is down so we are in move mode
  438. Change_Operation (MODE_MOVE);
  439. // Make sure we have the mouse captured
  440. ::Get_Main_View ()->SetCapture ();
  441. m_bUpdate = true;
  442. // Set the 'object move' cursor.
  443. ::SetCursor (::LoadCursor (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDC_OBJ_MOVE)));
  444. } else {
  445. // No buttons are down so release the mouse capture
  446. ::ReleaseCapture ();
  447. Change_Operation (MODE_NONE);
  448. }
  449. return ;
  450. }
  451. ///////////////////////////////////////////////////////////////
  452. //
  453. // Handle_Mouse_Move
  454. //
  455. ///////////////////////////////////////////////////////////////
  456. void
  457. MMObjectManipulateClass::Handle_Mouse_Move
  458. (
  459. UINT flags,
  460. CPoint point
  461. )
  462. {
  463. if (m_ObjectMode == MODE_SELECT) {
  464. if ((abs (point.x - m_LastMousePoint.x) > 3) ||
  465. (abs (point.y - m_LastMousePoint.y) > 3)) {
  466. // The user moved the mouse more than our
  467. // alloted selection fudge factor so now
  468. // we are in move mode.
  469. Change_Operation (MODE_MOVE);
  470. // If the control button is down, then do a copy
  471. // operation before the move.
  472. if (flags & MK_SHIFT) {
  473. //::Get_Selection_Mgr ().Clone_Group ();
  474. }
  475. // Set the 'object move' cursor.
  476. ::SetCursor (::LoadCursor (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDC_OBJ_MOVE)));
  477. }
  478. }
  479. if (m_ObjectMode == MODE_MOVE) {
  480. Move_Selection (point);
  481. } else if (m_ObjectMode == MODE_ROTATE) {
  482. Rotate_Selection (point);
  483. }
  484. return ;
  485. }
  486. ///////////////////////////////////////////////////////////////
  487. //
  488. // Set_Move_Nodes_Mode
  489. //
  490. ///////////////////////////////////////////////////////////////
  491. void
  492. MMObjectManipulateClass::Set_Move_Nodes_Mode (void)
  493. {
  494. SelectionMgrClass &sel_mgr = ::Get_Selection_Mgr ();
  495. m_CurrentMovePos = sel_mgr.Get_Center ();
  496. m_ObjectMode = MODE_MOVE;
  497. m_ForceDropToGround = true;
  498. return ;
  499. }
  500. ///////////////////////////////////////////////////////////////
  501. //
  502. // On_Mode_Set
  503. //
  504. ///////////////////////////////////////////////////////////////
  505. void
  506. MMObjectManipulateClass::On_Mode_Set (void)
  507. {
  508. // Reset the state
  509. ::ReleaseCapture ();
  510. Change_Operation (MODE_NONE);
  511. return ;
  512. }
  513. /*Vector2
  514. World_To_Device (const Vector3 &world_pos)
  515. {
  516. Vector2 device_pos (0, 0);
  517. Vector3 camera_pos = ::Get_Camera_Mgr ()->Get_Camera ()->Get_Position ();
  518. //Vector3 ray_start =
  519. const PlaneClass *planes = ::Get_Camera_Mgr ()->Get_Camera ()->Get_Frustum_Planes ();
  520. float percent = 0;
  521. if (planes[0]->Compute_Intersection (camera_pos, world_pos, &percent)) {
  522. Vector3 view_pos = camera_pos + ((world_pos - camera_pos) * percent);
  523. device_pos.X = view_pos.X -
  524. }
  525. return device_pos;
  526. }*/
  527. ///////////////////////////////////////////////////////////////
  528. //
  529. // Move_Selection
  530. //
  531. ///////////////////////////////////////////////////////////////
  532. void
  533. MMObjectManipulateClass::Move_Selection (CPoint point)
  534. {
  535. if ( m_ForceDropToGround ||
  536. ::Get_Current_Document ()->Get_Mode_Modifiers () & MODE_MOD_DROP_TO_GROUND) {
  537. //
  538. // Build a list of nodes from the current selection set
  539. //
  540. NODE_LIST list;
  541. Vector3 center = ::Get_Scene_Editor ()->Build_Node_List (list);
  542. //
  543. // Determine what ray to cast the node along
  544. //
  545. Vector3 ray_start;
  546. Vector3 ray_end;
  547. MoverClass::Get_Mouse_Ray (500.00F, ray_start, ray_end);
  548. //
  549. // If we are in drop-to-ground mode, then reposition the current
  550. // selection set along the line-of-sight ray
  551. //
  552. Vector3 tracking_pt (m_CurrentMovePos);
  553. tracking_pt.Z = center.Z;
  554. m_CurrentMovePos = MoverClass::Position_Nodes_Along_Ray (list, tracking_pt, ray_start, ray_end);
  555. } else {
  556. //
  557. // Build a list of nodes from the current selection set
  558. //
  559. NODE_LIST list;
  560. ::Get_Scene_Editor ()->Build_Node_List (list);
  561. //
  562. // Move the selected nodes using the current axis restrictions
  563. // and coordinate system
  564. //
  565. m_CurrentMovePos = MoverClass::Move_Nodes (list, m_CurrentMovePos);
  566. }
  567. m_LastMousePoint = point;
  568. return ;
  569. }
  570. ///////////////////////////////////////////////////////////////
  571. //
  572. // Rotate_Selection
  573. //
  574. ///////////////////////////////////////////////////////////////
  575. void
  576. MMObjectManipulateClass::Rotate_Selection (CPoint point)
  577. {
  578. // Get the bouding rectangle of the main view
  579. CRect rect;
  580. ::Get_Main_View ()->GetClientRect (&rect);
  581. //
  582. // Calculcate the delta's for both x and y as a scaled percent from -1 to 1.
  583. //
  584. float midx = (float)(rect.Width () >> 1);
  585. float midy = (float)(rect.Height () >> 1);
  586. float lastx = -(float(m_LastMousePoint.x - midx)) / midx;
  587. float lasty = (float(m_LastMousePoint.y - midy)) / midy;
  588. float currx = -(float(point.x - midx)) / midx;
  589. float curry = (float(point.y - midy)) / midy;
  590. //
  591. // Rotaate the item like it was trackballed
  592. //
  593. Quaternion rotation = ::Trackball (lastx, lasty, currx, curry, 0.9F);
  594. //
  595. // Now perform the rotation
  596. //
  597. float deltax = (float(point.x - m_LastMousePoint.x))/(float(rect.right - rect.left));
  598. float deltay = (float(point.y - m_LastMousePoint.y)) / (float(rect.bottom - rect.top));
  599. MoverClass::Rotate_Nodes (deltax, deltay, rotation);
  600. // This point now becomes our last point
  601. m_LastMousePoint = point;
  602. return ;
  603. }
  604. //**********************************************************************************************
  605. //*
  606. //* Start of MMWaypathEditClass
  607. //*
  608. //**********************************************************************************************
  609. ///////////////////////////////////////////////////////////////
  610. //
  611. // Exit_Mode
  612. //
  613. ///////////////////////////////////////////////////////////////
  614. void
  615. MMWaypathEditClass::Exit_Mode (void)
  616. {
  617. m_Waypath = NULL;
  618. m_CurrentPoint = -1;
  619. ::Get_Mouse_Mgr ()->Set_Mouse_Mode (MouseMgrClass::MODE_OBJECT_MANIPULATE);
  620. return ;
  621. }
  622. ///////////////////////////////////////////////////////////////
  623. //
  624. // On_Mode_Exit
  625. //
  626. ///////////////////////////////////////////////////////////////
  627. void
  628. MMWaypathEditClass::On_Mode_Exit (void)
  629. {
  630. if (m_Waypath != NULL && m_CurrentPoint >= 0) {
  631. m_Waypath->Delete_Point (m_CurrentPoint);
  632. }
  633. return ;
  634. }
  635. ///////////////////////////////////////////////////////////////
  636. //
  637. // Handle_LButton_Down
  638. //
  639. ///////////////////////////////////////////////////////////////
  640. void
  641. MMWaypathEditClass::Handle_LButton_Down
  642. (
  643. UINT flags,
  644. CPoint point
  645. )
  646. {
  647. /*NodeClass *node = ::Get_Scene_Editor ()->Find_Node_At_Point (point);
  648. if ((node != NULL) && (node->Get_Type () == NODE_TYPE_WAYPATH)) {
  649. WaypathNodeClass *waypath = (WaypathNodeClass *)node;
  650. }*/
  651. return ;
  652. }
  653. ///////////////////////////////////////////////////////////////
  654. //
  655. // Handle_LButton_Up
  656. //
  657. ///////////////////////////////////////////////////////////////
  658. void
  659. MMWaypathEditClass::Handle_LButton_Up
  660. (
  661. UINT flags,
  662. CPoint point
  663. )
  664. {
  665. if (m_Waypath != NULL && m_CurrentPoint >= 0) {
  666. //
  667. // If the user is holding the shift key, then exit the mode...
  668. //
  669. if (flags & MK_SHIFT) {
  670. Exit_Mode ();
  671. } else {
  672. //
  673. // Determine where are last point was
  674. //
  675. Vector3 last_pos (0, 0, 0);
  676. m_Waypath->Get_Point (m_CurrentPoint, last_pos);
  677. //
  678. // Lock that point and start a new point
  679. //
  680. m_CurrentPoint = m_Waypath->Add_Point (last_pos);
  681. ::Get_Main_View ()->SetCapture ();
  682. }
  683. }
  684. return ;
  685. }
  686. ///////////////////////////////////////////////////////////////
  687. //
  688. // Handle_RButton_Down
  689. //
  690. ///////////////////////////////////////////////////////////////
  691. void
  692. MMWaypathEditClass::Handle_RButton_Down
  693. (
  694. UINT flags,
  695. CPoint point
  696. )
  697. {
  698. return ;
  699. }
  700. ///////////////////////////////////////////////////////////////
  701. //
  702. // Handle_RButton_Up
  703. //
  704. ///////////////////////////////////////////////////////////////
  705. void
  706. MMWaypathEditClass::Handle_RButton_Up
  707. (
  708. UINT flags,
  709. CPoint point
  710. )
  711. {
  712. return ;
  713. }
  714. ///////////////////////////////////////////////////////////////
  715. //
  716. // Handle_Mouse_Move
  717. //
  718. ///////////////////////////////////////////////////////////////
  719. void
  720. MMWaypathEditClass::Handle_Mouse_Move
  721. (
  722. UINT flags,
  723. CPoint point
  724. )
  725. {
  726. if (m_Waypath != NULL && m_CurrentPoint >= 0) {
  727. //
  728. // Get a pointer to this waypoint
  729. //
  730. WaypointNodeClass *waypoint = NULL;
  731. m_Waypath->Get_Point (m_CurrentPoint, &waypoint);
  732. //
  733. // Reposition this node
  734. //
  735. MoverClass::Position_Node_Along_Ray (waypoint);
  736. }
  737. m_LastMousePoint = point;
  738. return ;
  739. }
  740. ///////////////////////////////////////////////////////////////
  741. //
  742. // On_Mode_Set
  743. //
  744. ///////////////////////////////////////////////////////////////
  745. void
  746. MMWaypathEditClass::On_Mode_Set (void)
  747. {
  748. // Reset the state
  749. ::ReleaseCapture ();
  750. m_Waypath = NULL;
  751. m_CurrentPoint = -1;
  752. return ;
  753. }
  754. //**********************************************************************************************
  755. //*
  756. //* Start of MMGrabHandleDragClass
  757. //*
  758. //**********************************************************************************************
  759. ///////////////////////////////////////////////////////////////
  760. //
  761. // Handle_LButton_Up
  762. //
  763. ///////////////////////////////////////////////////////////////
  764. void
  765. MMGrabHandleDragClass::Handle_LButton_Up
  766. (
  767. UINT flags,
  768. CPoint point
  769. )
  770. {
  771. // Put the mouse mode back to what it was
  772. ::Get_Mouse_Mgr ()->Set_Mouse_Mode (MouseMgrClass::MODE_OBJECT_MANIPULATE);
  773. // Let the node know its done dragging
  774. if (m_Node != NULL) {
  775. m_Node->On_Vertex_Drag_End (m_Vertex);
  776. }
  777. return ;
  778. }
  779. ///////////////////////////////////////////////////////////////
  780. //
  781. // Handle_Mouse_Move
  782. //
  783. ///////////////////////////////////////////////////////////////
  784. void
  785. MMGrabHandleDragClass::Handle_Mouse_Move
  786. (
  787. UINT flags,
  788. CPoint point
  789. )
  790. {
  791. //
  792. // Pass this information onto the node so it can process
  793. // the 'drag' in whatever fashion it wants
  794. //
  795. if (m_Node != NULL) {
  796. m_Node->On_Vertex_Drag (m_Vertex, point);
  797. }
  798. return ;
  799. }
  800. ///////////////////////////////////////////////////////////////
  801. //
  802. // Set_Node_Info
  803. //
  804. ///////////////////////////////////////////////////////////////
  805. void
  806. MMGrabHandleDragClass::Set_Node_Info
  807. (
  808. NodeClass * node,
  809. int vertex_index
  810. )
  811. {
  812. m_Node = node;
  813. m_Vertex = vertex_index;
  814. // Notify the undo manager of the operation
  815. ::Get_Scene_Editor ()->Begin_Operation (OPERATION_RESIZE, m_Node);
  816. //
  817. // Let the node know its done dragging
  818. //
  819. if (m_Node != NULL) {
  820. m_Node->On_Vertex_Drag_Begin (m_Vertex);
  821. }
  822. return ;
  823. }
  824. ///////////////////////////////////////////////////////////////
  825. //
  826. // Handle_LButton_Down
  827. //
  828. ///////////////////////////////////////////////////////////////
  829. void
  830. MMHeightfieldEditClass::Handle_LButton_Down (UINT flags, CPoint point)
  831. {
  832. return ;
  833. }
  834. ///////////////////////////////////////////////////////////////
  835. //
  836. // Handle_LButton_Up
  837. //
  838. ///////////////////////////////////////////////////////////////
  839. void
  840. MMHeightfieldEditClass::Handle_LButton_Up (UINT flags, CPoint point)
  841. {
  842. return ;
  843. }
  844. ///////////////////////////////////////////////////////////////
  845. //
  846. // Handle_RButton_Down
  847. //
  848. ///////////////////////////////////////////////////////////////
  849. void
  850. MMHeightfieldEditClass::Handle_RButton_Down (UINT flags, CPoint point)
  851. {
  852. return ;
  853. }
  854. ///////////////////////////////////////////////////////////////
  855. //
  856. // Handle_RButton_Up
  857. //
  858. ///////////////////////////////////////////////////////////////
  859. void
  860. MMHeightfieldEditClass::Handle_RButton_Up (UINT flags, CPoint point)
  861. {
  862. return ;
  863. }
  864. ///////////////////////////////////////////////////////////////
  865. //
  866. // On_Mode_Set
  867. //
  868. ///////////////////////////////////////////////////////////////
  869. void
  870. MMHeightfieldEditClass::On_Mode_Set (void)
  871. {
  872. return ;
  873. }
  874. ///////////////////////////////////////////////////////////////
  875. //
  876. // On_Mode_Exit
  877. //
  878. ///////////////////////////////////////////////////////////////
  879. void
  880. MMHeightfieldEditClass::On_Mode_Exit (void)
  881. {
  882. return ;
  883. }