CTriangleBBSelector.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "CTriangleBBSelector.h"
  5. #include "ISceneNode.h"
  6. namespace irr
  7. {
  8. namespace scene
  9. {
  10. //! constructor
  11. CTriangleBBSelector::CTriangleBBSelector(ISceneNode* node)
  12. : CTriangleSelector(node)
  13. {
  14. #ifdef _DEBUG
  15. setDebugName("CTriangleBBSelector");
  16. #endif
  17. Triangles.set_used(12); // a box has 12 triangles.
  18. }
  19. //! Gets all triangles.
  20. void CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
  21. s32 arraySize, s32& outTriangleCount,
  22. const core::matrix4* transform) const
  23. {
  24. if (!SceneNode)
  25. return;
  26. // construct triangles
  27. const core::aabbox3d<f32>& box = SceneNode->getBoundingBox();
  28. core::vector3df edges[8];
  29. box.getEdges(edges);
  30. Triangles[0].set( edges[3], edges[0], edges[2]);
  31. Triangles[1].set( edges[3], edges[1], edges[0]);
  32. Triangles[2].set( edges[3], edges[2], edges[7]);
  33. Triangles[3].set( edges[7], edges[2], edges[6]);
  34. Triangles[4].set( edges[7], edges[6], edges[4]);
  35. Triangles[5].set( edges[5], edges[7], edges[4]);
  36. Triangles[6].set( edges[5], edges[4], edges[0]);
  37. Triangles[7].set( edges[5], edges[0], edges[1]);
  38. Triangles[8].set( edges[1], edges[3], edges[7]);
  39. Triangles[9].set( edges[1], edges[7], edges[5]);
  40. Triangles[10].set(edges[0], edges[6], edges[2]);
  41. Triangles[11].set(edges[0], edges[4], edges[6]);
  42. // call parent
  43. CTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount, transform);
  44. }
  45. void CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
  46. s32 arraySize, s32& outTriangleCount,
  47. const core::aabbox3d<f32>& box,
  48. const core::matrix4* transform) const
  49. {
  50. return getTriangles(triangles, arraySize, outTriangleCount, transform);
  51. }
  52. void CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
  53. s32 arraySize, s32& outTriangleCount,
  54. const core::line3d<f32>& line,
  55. const core::matrix4* transform) const
  56. {
  57. return getTriangles(triangles, arraySize, outTriangleCount, transform);
  58. }
  59. } // end namespace scene
  60. } // end namespace irr