PathObject.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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/wwphys/PathObject.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/21/01 2:33p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "pathobject.h"
  36. #include "rendobj.h"
  37. #include "phys.h"
  38. #include "hlod.h"
  39. #include "boxrobj.h"
  40. #include <stdio.h>
  41. //////////////////////////////////////////////////////////////////
  42. // Local constants
  43. //////////////////////////////////////////////////////////////////
  44. const float DEF_TURN_RADIUS = 0;
  45. const float DEF_SPEED = 4.0F;
  46. const int DEF_FLAGS = PathObjectClass::CAN_USE_EQUIPMENT | PathObjectClass::IS_VEHICLE;
  47. //////////////////////////////////////////////////////////////////
  48. // Local inlines
  49. //////////////////////////////////////////////////////////////////
  50. void Get_Collision_Box (RenderObjClass *render_obj, OBBoxClass &bounding_box);
  51. //////////////////////////////////////////////////////////////////
  52. //
  53. // PathObjectClass
  54. //
  55. //////////////////////////////////////////////////////////////////
  56. PathObjectClass::PathObjectClass (void)
  57. : m_TurnRadius (DEF_TURN_RADIUS),
  58. m_MaxSpeed (DEF_SPEED),
  59. m_CollisionBox (Vector3 (0, 0, 0), Vector3 (0.35F, 0.35F, 0.7F)),
  60. m_Flags (DEF_FLAGS),
  61. m_KeyRing (0)
  62. {
  63. Init_Human ();
  64. return ;
  65. }
  66. //////////////////////////////////////////////////////////////////
  67. //
  68. // ~PathObjectClass
  69. //
  70. //////////////////////////////////////////////////////////////////
  71. PathObjectClass::~PathObjectClass (void)
  72. {
  73. return ;
  74. }
  75. //////////////////////////////////////////////////////////////////
  76. //
  77. // Initialize
  78. //
  79. //////////////////////////////////////////////////////////////////
  80. void
  81. PathObjectClass::Initialize (PhysClass &phys_obj)
  82. {
  83. RenderObjClass *render_obj = phys_obj.Peek_Model ();
  84. if (render_obj != NULL) {
  85. //
  86. // Lookup the render object's collision box
  87. //
  88. ::Get_Collision_Box (render_obj, m_CollisionBox);
  89. }
  90. //
  91. // Everything except for humans rotate their collision boxes
  92. //
  93. Set_Flag (PathObjectClass::CAN_BOX_ROTATE, (phys_obj.As_HumanPhysClass () == NULL));
  94. //
  95. // By default we will assume the vehicles steering-wheels are located in the front...
  96. //
  97. if (phys_obj.As_HumanPhysClass () == NULL) {
  98. Set_Wheel_Offset (m_CollisionBox.Extent.X);
  99. }
  100. return ;
  101. }
  102. //////////////////////////////////////////////////////////////////
  103. //
  104. // Init_Human
  105. //
  106. //////////////////////////////////////////////////////////////////
  107. void
  108. PathObjectClass::Init_Human (void)
  109. {
  110. m_Flags = CAN_USE_EQUIPMENT;
  111. m_TurnRadius = 0;
  112. m_WheelOffset = 0;
  113. // Use some default numbers for the human...
  114. m_CollisionBox.Center.Set (0, 0, 0);
  115. m_CollisionBox.Extent.Set (0.35F, 0.35F, 0.7F);
  116. m_CollisionBox.Basis.Make_Identity ();
  117. // (4.75 meters per sec is approx a 6 min mile)
  118. m_MaxSpeed = 4.75F;
  119. return ;
  120. }
  121. //////////////////////////////////////////////////////////////////
  122. //
  123. // Get_Collision_Box
  124. //
  125. //////////////////////////////////////////////////////////////////
  126. void
  127. Get_Collision_Box (RenderObjClass *render_obj, OBBoxClass &bounding_box)
  128. {
  129. if (render_obj != NULL) {
  130. //
  131. // Try to get the "WorldBox" from the model
  132. //
  133. RenderObjClass *world_box = render_obj->Get_Sub_Object_By_Name ("WorldBox");
  134. // If we didn't finde WorldBox, try to find the LOD named "WorldBox"
  135. // The LOD code generates a unique name for the mesh by appending A,B,C, etc to the name.
  136. // A is the lowest LOD, B is the next, and so on. Our worldbox is specified in the highest
  137. // LOD so we have to construct the name by appending 'A'+LodCount to the name... icky
  138. if ((world_box == NULL) && (render_obj->Class_ID () == RenderObjClass::CLASSID_HLOD)) {
  139. char namebuffer[64];
  140. sprintf(namebuffer,"WorldBox%c",'A' + ((HLodClass *)render_obj)->Get_Lod_Count() - 1);
  141. world_box = render_obj->Get_Sub_Object_By_Name (namebuffer);
  142. }
  143. if (world_box != NULL && world_box->Class_ID() == RenderObjClass::CLASSID_OBBOX) {
  144. bounding_box = ((OBBoxRenderObjClass *)world_box)->Get_Box ();
  145. }
  146. REF_PTR_RELEASE (world_box);
  147. }
  148. return ;
  149. }