abstractPolyList.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. S32 v1 = base + PolyFace[i][0];
  52. S32 v2 = base + PolyFace[i][1];
  53. S32 v3 = base + PolyFace[i][2];
  54. S32 v4 = base + PolyFace[i][3];
  55. // First triangle
  56. begin(material, i);
  57. vertex(v1);
  58. vertex(v2);
  59. vertex(v3);
  60. plane(v1, v2, v3);
  61. end();
  62. // Second triangle
  63. begin(material, i);
  64. vertex(v3);
  65. vertex(v4);
  66. vertex(v1);
  67. plane(v3, v4, v1);
  68. end();
  69. }
  70. }
  71. bool AbstractPolyList::getMapping(MatrixF *, Box3F *)
  72. {
  73. // return list transform and bounds in list space...optional
  74. return false;
  75. }
  76. bool AbstractPolyList::isInterestedInPlane(const PlaneF& plane)
  77. {
  78. if (mInterestNormalRegistered == false) {
  79. return true;
  80. }
  81. else {
  82. PlaneF xformed;
  83. mPlaneTransformer.transform(plane, xformed);
  84. if (mDot(xformed, mInterestNormal) >= 0.0f)
  85. return false;
  86. else
  87. return true;
  88. }
  89. }
  90. bool AbstractPolyList::isInterestedInPlane(const U32 index)
  91. {
  92. if (mInterestNormalRegistered == false) {
  93. return true;
  94. }
  95. else {
  96. const PlaneF& rPlane = getIndexedPlane(index);
  97. if (mDot(rPlane, mInterestNormal) >= 0.0f)
  98. return false;
  99. else
  100. return true;
  101. }
  102. }
  103. void AbstractPolyList::setInterestNormal(const Point3F& normal)
  104. {
  105. mInterestNormalRegistered = true;
  106. mInterestNormal = normal;
  107. }