Mover.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/Mover.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/15/01 10:16a $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __MOVER_H
  39. #define __MOVER_H
  40. #include "listtypes.h"
  41. #include "bittype.h"
  42. #include "collisiongroups.h"
  43. #include "coltest.h"
  44. #include "physcoltest.h"
  45. #include "utils.h"
  46. #include "sceneeditor.h"
  47. // Forward declarations
  48. class NodeClass;
  49. class Quaternion;
  50. class Vector3;
  51. class Matrix3D;
  52. struct CastResultStruct;
  53. ///////////////////////////////////////////////////////////////////////
  54. //
  55. // MoverClass
  56. //
  57. ///////////////////////////////////////////////////////////////////////
  58. class MoverClass
  59. {
  60. public:
  61. ////////////////////////////////////////////////////////////////////
  62. // Static methods
  63. ////////////////////////////////////////////////////////////////////
  64. //
  65. // Node 'casting' functions.
  66. // These position a node at the interesction point of a ray cast into the world.
  67. //
  68. static void Position_Node (NodeClass *node);
  69. static void Position_Node_Along_Ray (NodeClass *node);
  70. static Vector3 Position_Node_Along_Ray (NodeClass *node, const Vector3 &start, const Vector3 &end);
  71. static void Position_Nodes_Along_Ray (void);
  72. static void Position_Nodes_Along_Ray (const Vector3 &start, const Vector3 &end);
  73. static Vector3 Position_Nodes_Along_Ray (NODE_LIST &list, const Vector3 &tracking_pt, const Vector3 &start, const Vector3 &end);
  74. static Vector3 Calc_New_Position (const Matrix3D &coord_system, const Vector3 &start_point_in_world_coords, LPPOINT mouse_pos = NULL);
  75. //
  76. // Translation functions
  77. //
  78. static void Move_Node (NodeClass *node, const Vector3 &translation);
  79. static void Move_Nodes (const Vector3 &translation);
  80. static Vector3 Move_Nodes (NODE_LIST &list, const Vector3 &tracking_point);
  81. static void Simple_Move_Nodes (NODE_LIST &list, const Vector3 &translation);
  82. //
  83. // Rotation functions
  84. //
  85. static void Rotate_Nodes (float deltax, float deltay, const Quaternion &rotation);
  86. static void Rotate_Nodes (NODE_LIST &list, const Vector3 &center, float deltax, float deltay, const Quaternion &rotation);
  87. static void Rotate_Nodes (NODE_LIST &list, const Matrix3D &rotation_matrix, const Vector3 &center);
  88. static void Rotate_Nodes_Z (float multiplier);
  89. static void Rotate_Nodes_Z (NODE_LIST &list, const Vector3 &center, float multiplier);
  90. //
  91. // Low-level rotate and translate functions on a per-node basis.
  92. // These are called by the other functions once the rotatation or translation params are calculated.
  93. //
  94. static void Rotate_Node (NodeClass *node, const Matrix3D &rotation_matrix, const Matrix3D &coord_system);
  95. static void Rotate_Node_Freely (NodeClass *node, const Matrix3D &rotation_matrix, const Matrix3D &coord_system);
  96. static void Rotate_Node_Z90 (NodeClass *node, const Matrix3D &rotation_matrix, const Matrix3D &coord_system);
  97. static void Translate_Node (NodeClass *node, const Vector3 &vector);
  98. static void Transform_Node (NodeClass *node, const Matrix3D &transform);
  99. static void Transform_Nodes (NodeClass *node, const Matrix3D &transform);
  100. static void Transform_Nodes (NODE_LIST &list, NodeClass *node, const Matrix3D &transform);
  101. //
  102. // Ray-Cast helper functions
  103. // These are used to simplify ray casting and line-of-sight casting
  104. //
  105. static void Get_LOS_Ray (const POINT &mouse_pos, float length, Vector3 &start, Vector3 &end);
  106. static void Get_LOS_Ray (float length, Vector3 &start, Vector3 &end);
  107. static void Get_Mouse_Ray (const POINT &mouse_pos, float length, Vector3 &start, Vector3 &end);
  108. static void Get_Mouse_Ray (float length, Vector3 &start, Vector3 &end);
  109. static PhysClass *Cast_Ray (CastResultStruct &result, const Vector3 &start, const Vector3 &end, uint32 group = DEF_COLLISION_GROUP, uint32 type = COLLISION_TYPE_PHYSICAL | COLLISION_TYPE_PROJECTILE | COLLISION_TYPE_6);
  110. static PhysClass *Cast_Box (CastResultStruct &result, const AABoxClass &box, const Vector3 &move, uint32 group = DEF_COLLISION_GROUP, uint32 type = COLLISION_TYPE_PHYSICAL | COLLISION_TYPE_PROJECTILE | COLLISION_TYPE_6);
  111. protected:
  112. ////////////////////////////////////////////////////////////////////
  113. // Protected methods
  114. ////////////////////////////////////////////////////////////////////
  115. static bool Calc_Ray_Intersection_XY (float plane, const Vector3 &start, const Vector3 &end, Vector3 &result);
  116. static bool Calc_Ray_Intersection_XZ (float plane, const Vector3 &start, const Vector3 &end, Vector3 &result);
  117. static bool Calc_Ray_Intersection_YZ (float plane, const Vector3 &start, const Vector3 &end, Vector3 &result);
  118. private:
  119. ////////////////////////////////////////////////////////////////////
  120. // Private member data
  121. ////////////////////////////////////////////////////////////////////
  122. };
  123. ////////////////////////////////////////////////////////////////////
  124. // Cast_Ray
  125. ////////////////////////////////////////////////////////////////////
  126. inline PhysClass *
  127. MoverClass::Cast_Ray
  128. (
  129. CastResultStruct & result,
  130. const Vector3 & start,
  131. const Vector3 & end,
  132. uint32 group,
  133. uint32 type
  134. )
  135. {
  136. bool retval = false;
  137. LineSegClass ray (start, end);
  138. PhysRayCollisionTestClass raytest (ray, &result, group, type);
  139. ::Get_Scene_Editor ()->Cast_Ray (raytest);
  140. //
  141. // Return a pointer to the collided physics object if the
  142. // cast hit something
  143. //
  144. PhysClass *collided_obj = NULL;
  145. if (result.Fraction < 1.0F) {
  146. collided_obj = raytest.CollidedPhysObj;
  147. }
  148. return collided_obj;
  149. }
  150. ////////////////////////////////////////////////////////////////////
  151. // Cast_Box
  152. ////////////////////////////////////////////////////////////////////
  153. inline PhysClass *
  154. MoverClass::Cast_Box
  155. (
  156. CastResultStruct & result,
  157. const AABoxClass & box,
  158. const Vector3 & move,
  159. uint32 group,
  160. uint32 type
  161. )
  162. {
  163. bool retval = false;
  164. PhysAABoxCollisionTestClass boxtest (box, move, &result, group, type);
  165. PhysicsSceneClass::Get_Instance()->Cast_AABox (boxtest);
  166. //
  167. // Return a pointer to the collided physics object if the
  168. // cast hit something
  169. //
  170. PhysClass *collided_obj = NULL;
  171. if (result.Fraction < 1.0F) {
  172. collided_obj = boxtest.CollidedPhysObj;
  173. }
  174. return collided_obj;
  175. }
  176. #endif //__MOVER_H