pathfindbox.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/pathfindbox.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/06/00 3:49p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PATHFIND_BOX_H
  39. #define __PATHFIND_BOX_H
  40. #include "vector3.h"
  41. #include "aabox.h"
  42. #include "bittype.h"
  43. ////////////////////////////////////////////////////////////////////////////////////
  44. //
  45. // PathfindBoxClass
  46. //
  47. // Utility class that can store a quantized AABox in 8 bytes instead of 24 bytes.
  48. // It assumes a global 'block-size' where x and y values are stored in units
  49. // of this block-size. Z values are stored in 1/10's of a meter (which allows
  50. // for a maximum height of 6,553 meters).
  51. //
  52. ////////////////////////////////////////////////////////////////////////////////////
  53. class PathfindBoxClass
  54. {
  55. public:
  56. //////////////////////////////////////////////////////////////////////////
  57. // Private member data
  58. //////////////////////////////////////////////////////////////////////////
  59. PathfindBoxClass (void)
  60. : x_pos (0),
  61. y_pos (0),
  62. z_pos (0),
  63. x_size (0),
  64. y_size (0) { }
  65. ~PathfindBoxClass (void) { }
  66. //////////////////////////////////////////////////////////////////////////
  67. // Public methods
  68. //////////////////////////////////////////////////////////////////////////
  69. void Get_AABox (AABoxClass &box) const;
  70. void Set_AABox (const AABoxClass &box);
  71. void Set_Position (int x_pos, int y_pos, float z_pos);
  72. void Set_Size (int cx, int cy);
  73. //////////////////////////////////////////////////////////////////////////
  74. // Static methods
  75. //////////////////////////////////////////////////////////////////////////
  76. static const Vector3 & Get_Block_Size (void);
  77. static void Set_Block_Size (const Vector3 &size);
  78. private:
  79. //////////////////////////////////////////////////////////////////////////
  80. // Static member data
  81. //////////////////////////////////////////////////////////////////////////
  82. static Vector3 _BlockSize;
  83. //////////////////////////////////////////////////////////////////////////
  84. // Private member data
  85. //////////////////////////////////////////////////////////////////////////
  86. uint16 x_pos;
  87. uint16 y_pos;
  88. uint16 z_pos;
  89. uint8 x_size;
  90. uint8 y_size;
  91. };
  92. //////////////////////////////////////////////////////////////////////////
  93. // Get_AABox
  94. //////////////////////////////////////////////////////////////////////////
  95. inline void
  96. PathfindBoxClass::Get_AABox (AABoxClass &box) const
  97. {
  98. box.Center.X = ((float)x_pos) * _BlockSize.X;
  99. box.Center.Y = ((float)y_pos) * _BlockSize.Y;
  100. box.Center.Z = ((float)z_pos) / 10.0F;
  101. box.Extent.X = ((float)x_size) * _BlockSize.X;
  102. box.Extent.Y = ((float)y_size) * _BlockSize.Y;
  103. box.Extent.Z = _BlockSize.Z;
  104. return ;
  105. }
  106. //////////////////////////////////////////////////////////////////////////
  107. // Set_AABox
  108. //////////////////////////////////////////////////////////////////////////
  109. inline void
  110. PathfindBoxClass::Set_AABox (const AABoxClass &box)
  111. {
  112. x_pos = uint16(box.Center.X / _BlockSize.X);
  113. y_pos = uint16(box.Center.Y / _BlockSize.Y);
  114. z_pos = uint16(box.Center.Z * 10);
  115. x_size = uint8(box.Extent.X / _BlockSize.X);
  116. y_size = uint8(box.Extent.Y / _BlockSize.Y);
  117. return ;
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. // Set_Position
  121. //////////////////////////////////////////////////////////////////////////
  122. inline void
  123. PathfindBoxClass::Set_Position (int new_x, int new_y, float new_z)
  124. {
  125. x_pos = uint16(new_x);
  126. y_pos = uint16(new_y);
  127. z_pos = uint16(new_z * 10);
  128. return ;
  129. }
  130. //////////////////////////////////////////////////////////////////////////
  131. // Set_Size
  132. //////////////////////////////////////////////////////////////////////////
  133. inline void
  134. PathfindBoxClass::Set_Size (int cx, int cy)
  135. {
  136. x_size = uint8(cx);
  137. y_size = uint8(cy);
  138. return ;
  139. }
  140. #endif // __PATHFIND_BOX_H