torqueRecast.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TORQUE_RECAST_H_
  23. #define _TORQUE_RECAST_H_
  24. #include "console/simSet.h"
  25. #include "math/mPoint3.h"
  26. #include "math/mBox.h"
  27. inline Point3F DTStoRC(F32 x, F32 y, F32 z) { return Point3F(x, z, -y); }
  28. inline Point3F DTStoRC(const Point3F& point){ return Point3F(point.x, point.z, -point.y); }
  29. inline Point3F RCtoDTS(const F32* xyz) { return Point3F(xyz[0], -xyz[2], xyz[1]); }
  30. inline Point3F RCtoDTS(F32 x, F32 y, F32 z) { return Point3F(x, -z, y); }
  31. inline Point3F RCtoDTS(const Point3F& point){ return Point3F(point.x, -point.z, point.y); }
  32. inline Box3F DTStoRC(const Box3F& box)
  33. {
  34. return Box3F(box.minExtents.x, box.minExtents.z, -box.maxExtents.y,
  35. box.maxExtents.x, box.maxExtents.z, -box.minExtents.y);
  36. }
  37. inline Box3F RCtoDTS(const F32 *min, const F32 *max)
  38. {
  39. return Box3F(min[0], -max[2], min[1], max[0], -min[2], max[1]);
  40. }
  41. /// Convert a Rcast colour integer to RGBA components.
  42. inline void rcCol(unsigned int col, U8 &r, U8 &g, U8 &b, U8 &a)
  43. {
  44. r = col % 256; col /= 256;
  45. g = col % 256; col /= 256;
  46. b = col % 256; col /= 256;
  47. a = col % 256;
  48. }
  49. enum PolyAreas {
  50. GroundArea,
  51. WaterArea,
  52. OffMeshArea,
  53. NumAreas
  54. };
  55. enum PolyFlags {
  56. WalkFlag = 1 << 0,
  57. SwimFlag = 1 << 1,
  58. JumpFlag = 1 << 2,
  59. LedgeFlag = 1 << 3,
  60. DropFlag = 1 << 4,
  61. ClimbFlag = 1 << 5,
  62. TeleportFlag = 1 << 6,
  63. AllFlags = 0xffff
  64. };
  65. /// Stores information about a link.
  66. struct LinkData {
  67. bool walk;
  68. bool jump;
  69. bool drop;
  70. bool swim;
  71. bool ledge;
  72. bool climb;
  73. bool teleport;
  74. LinkData(U16 flags = 0)
  75. {
  76. walk = flags & WalkFlag;
  77. jump = flags & JumpFlag;
  78. drop = flags & DropFlag;
  79. swim = flags & SwimFlag;
  80. ledge = flags & LedgeFlag;
  81. climb = flags & ClimbFlag;
  82. teleport = flags & TeleportFlag;
  83. }
  84. U16 getFlags() const
  85. {
  86. return
  87. (walk ? WalkFlag : 0) |
  88. (jump ? JumpFlag : 0) |
  89. (drop ? DropFlag : 0) |
  90. (swim ? SwimFlag : 0) |
  91. (ledge ? LedgeFlag : 0) |
  92. (climb ? ClimbFlag : 0) |
  93. (teleport ? TeleportFlag : 0);
  94. }
  95. };
  96. #endif