abstractPolyList.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #include "collision/abstractPolyList.h"
  23. //----------------------------------------------------------------------------
  24. AbstractPolyList::~AbstractPolyList()
  25. {
  26. mInterestNormalRegistered = false;
  27. }
  28. static U32 PolyFace[6][4] = {
  29. { 3, 2, 1, 0 },
  30. { 7, 4, 5, 6 },
  31. { 0, 5, 4, 3 },
  32. { 6, 5, 0, 1 },
  33. { 7, 6, 1, 2 },
  34. { 4, 7, 2, 3 },
  35. };
  36. void AbstractPolyList::addBox(const Box3F &box, BaseMatInstance* material)
  37. {
  38. Point3F pos = box.minExtents;
  39. F32 dx = box.maxExtents.x - box.minExtents.x;
  40. F32 dy = box.maxExtents.y - box.minExtents.y;
  41. F32 dz = box.maxExtents.z - box.minExtents.z;
  42. U32 base = addPoint(pos);
  43. pos.y += dy; addPoint(pos);
  44. pos.x += dx; addPoint(pos);
  45. pos.y -= dy; addPoint(pos);
  46. pos.z += dz; addPoint(pos);
  47. pos.x -= dx; addPoint(pos);
  48. pos.y += dy; addPoint(pos);
  49. pos.x += dx; addPoint(pos);
  50. for (S32 i = 0; i < 6; i++) {
  51. begin(material, i);
  52. S32 v1 = base + PolyFace[i][0];
  53. S32 v2 = base + PolyFace[i][1];
  54. S32 v3 = base + PolyFace[i][2];
  55. S32 v4 = base + PolyFace[i][3];
  56. vertex(v1);
  57. vertex(v2);
  58. vertex(v3);
  59. vertex(v4);
  60. plane(v1, v2, v3);
  61. end();
  62. }
  63. }
  64. bool AbstractPolyList::getMapping(MatrixF *, Box3F *)
  65. {
  66. // return list transform and bounds in list space...optional
  67. return false;
  68. }
  69. bool AbstractPolyList::isInterestedInPlane(const PlaneF& plane)
  70. {
  71. if (mInterestNormalRegistered == false) {
  72. return true;
  73. }
  74. else {
  75. PlaneF xformed;
  76. mPlaneTransformer.transform(plane, xformed);
  77. if (mDot(xformed, mInterestNormal) >= 0.0f)
  78. return false;
  79. else
  80. return true;
  81. }
  82. }
  83. bool AbstractPolyList::isInterestedInPlane(const U32 index)
  84. {
  85. if (mInterestNormalRegistered == false) {
  86. return true;
  87. }
  88. else {
  89. const PlaneF& rPlane = getIndexedPlane(index);
  90. if (mDot(rPlane, mInterestNormal) >= 0.0f)
  91. return false;
  92. else
  93. return true;
  94. }
  95. }
  96. void AbstractPolyList::setInterestNormal(const Point3F& normal)
  97. {
  98. mInterestNormalRegistered = true;
  99. mInterestNormal = normal;
  100. }