ITriangleSelector.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #ifndef IRR_I_TRIANGLE_SELECTOR_H_INCLUDED
  5. #define IRR_I_TRIANGLE_SELECTOR_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "triangle3d.h"
  8. #include "aabbox3d.h"
  9. #include "matrix4.h"
  10. #include "line3d.h"
  11. #include "irrArray.h"
  12. namespace irr
  13. {
  14. namespace scene
  15. {
  16. class ISceneNode;
  17. class ITriangleSelector;
  18. class IMeshBuffer;
  19. //! Additional information about the triangle arrays returned by ITriangleSelector::getTriangles
  20. /** ITriangleSelector are free to fill out this information fully, partly or ignore it.
  21. Usually they will try to fill it when they can and set values to 0 otherwise.
  22. */
  23. struct SCollisionTriangleRange
  24. {
  25. SCollisionTriangleRange()
  26. : RangeStart(0), RangeSize(0)
  27. , Selector(0), SceneNode(0)
  28. , MeshBuffer(0), MaterialIndex(0)
  29. {}
  30. //! Check if this triangle index inside the range
  31. /**
  32. \param triangleIndex Index to an element inside the array of triangles returned by ITriangleSelector::getTriangles
  33. */
  34. bool isIndexInRange(irr::u32 triangleIndex) const
  35. {
  36. return triangleIndex >= RangeStart && triangleIndex < RangeStart+RangeSize;
  37. }
  38. //! First index in the returned triangle array for which this struct is valid
  39. irr::u32 RangeStart;
  40. //! Number of elements in the returned triangle array for which this struct is valid (starting with RangeStart)
  41. irr::u32 RangeSize;
  42. //! Real selector which contained those triangles (useful when working with MetaTriangleSelector)
  43. const ITriangleSelector* Selector;
  44. //! SceneNode from which the triangles are from
  45. ISceneNode* SceneNode;
  46. //! Meshbuffer from which the triangles are from
  47. //! Is 0 when the ITriangleSelector doesn't support meshbuffer selection
  48. const IMeshBuffer* MeshBuffer;
  49. //! Index of selected material in the SceneNode. Usually only valid when MeshBuffer is also set, otherwise always 0
  50. irr::u32 MaterialIndex;
  51. };
  52. //! Interface to return triangles with specific properties.
  53. /** Every ISceneNode may have a triangle selector, available with
  54. ISceneNode::getTriangleSelector() or ISceneManager::createTriangleSelector.
  55. This is used for doing collision detection: For example if you know, that a
  56. collision may have happened in the area between (1,1,1) and (10,10,10), you
  57. can get all triangles of the scene node in this area with the
  58. ITriangleSelector easily and check every triangle if it collided. */
  59. class ITriangleSelector : public virtual IReferenceCounted
  60. {
  61. public:
  62. //! Get amount of all available triangles in this selector
  63. virtual s32 getTriangleCount() const = 0;
  64. //! Gets the triangles for one associated node.
  65. /**
  66. This returns all triangles for one scene node associated with this
  67. selector. If there is more than one scene node associated (e.g. for
  68. an IMetaTriangleSelector) this this function may be called multiple
  69. times to retrieve all triangles.
  70. \param triangles Array where the resulting triangles will be
  71. written to.
  72. \param arraySize Size of the target array.
  73. \param outTriangleCount: Amount of triangles which have been written
  74. into the array.
  75. \param transform Pointer to matrix for transforming the triangles
  76. before they are returned. Useful for example to scale all triangles
  77. down into an ellipsoid space.
  78. \param useNodeTransform When the selector has a node then transform the
  79. triangles by that node's transformation matrix.
  80. \param outTriangleInfo When a pointer to an array is passed then that
  81. array is filled with additional information about the returned triangles.
  82. One element of SCollisionTriangleRange added for each range of triangles which
  83. has distinguishable information. For example one range per meshbuffer.
  84. */
  85. virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
  86. s32& outTriangleCount, const core::matrix4* transform=0,
  87. bool useNodeTransform=true,
  88. irr::core::array<SCollisionTriangleRange>* outTriangleInfo=0) const = 0;
  89. //! Gets the triangles for one associated node which may lie within a specific bounding box.
  90. /**
  91. This returns all triangles for one scene node associated with this
  92. selector. If there is more than one scene node associated (e.g. for
  93. an IMetaTriangleSelector) this this function may be called multiple
  94. times to retrieve all triangles.
  95. This method will return at least the triangles that intersect the box,
  96. but may return other triangles as well.
  97. \param triangles Array where the resulting triangles will be written
  98. to.
  99. \param arraySize Size of the target array.
  100. \param outTriangleCount Amount of triangles which have been written
  101. into the array.
  102. \param box Only triangles which are in this axis aligned bounding box
  103. will be written into the array.
  104. \param transform Pointer to matrix for transforming the triangles
  105. before they are returned. Useful for example to scale all triangles
  106. down into an ellipsoid space.
  107. \param useNodeTransform When the selector has a node then transform the
  108. triangles by that node's transformation matrix.
  109. \param outTriangleInfo When a pointer to an array is passed then that
  110. array is filled with additional information about the returned triangles.
  111. One element of SCollisionTriangleRange added for each range of triangles which
  112. has distinguishable information. For example one range per meshbuffer. */
  113. virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
  114. s32& outTriangleCount, const core::aabbox3d<f32>& box,
  115. const core::matrix4* transform=0, bool useNodeTransform=true,
  116. irr::core::array<SCollisionTriangleRange>* outTriangleInfo=0) const = 0;
  117. //! Gets the triangles for one associated node which have or may have contact with a 3d line.
  118. /**
  119. This returns all triangles for one scene node associated with this
  120. selector. If there is more than one scene node associated (e.g. for
  121. an IMetaTriangleSelector) this this function may be called multiple
  122. times to retrieve all triangles.
  123. Please note that unoptimized triangle selectors also may return
  124. triangles which are not in contact at all with the 3d line.
  125. \param triangles Array where the resulting triangles will be written
  126. to.
  127. \param arraySize Size of the target array.
  128. \param outTriangleCount Amount of triangles which have been written
  129. into the array.
  130. \param line Only triangles which may be in contact with this 3d line
  131. will be written into the array.
  132. \param transform Pointer to matrix for transforming the triangles
  133. before they are returned. Useful for example to scale all triangles
  134. down into an ellipsoid space.
  135. \param useNodeTransform When the selector has a node then transform the
  136. triangles by that node's transformation matrix.
  137. \param outTriangleInfo When a pointer to an array is passed then that
  138. array is filled with additional information about the returned triangles.
  139. One element of SCollisionTriangleRange added for each range of triangles which
  140. has distinguishable information. For example one range per meshbuffer. */
  141. virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
  142. s32& outTriangleCount, const core::line3d<f32>& line,
  143. const core::matrix4* transform=0, bool useNodeTransform=true,
  144. irr::core::array<SCollisionTriangleRange>* outTriangleInfo=0) const = 0;
  145. //! Get number of TriangleSelectors that are part of this one
  146. /** Only useful for MetaTriangleSelector, others return 1
  147. */
  148. virtual u32 getSelectorCount() const = 0;
  149. //! Get TriangleSelector based on index based on getSelectorCount
  150. /** Only useful for MetaTriangleSelector, others return 'this' or 0
  151. */
  152. virtual ITriangleSelector* getSelector(u32 index) = 0;
  153. //! Get TriangleSelector based on index based on getSelectorCount
  154. /** Only useful for MetaTriangleSelector, others return 'this' or 0
  155. */
  156. virtual const ITriangleSelector* getSelector(u32 index) const = 0;
  157. //! Get scene node associated with a given triangle.
  158. /** With CMetaTriangleSelector-selectors it's possible to find out a node
  159. belonging to a certain triangle index.
  160. NOTE: triangleIndex has nothing to do with the order of triangles returned by getTriangles functions!
  161. So you can _not_ use this function to find out anything about to which node returned triangles belong.
  162. Use STriangleCollisionInfo struct for that.
  163. \param triangleIndex: the index of the triangle for which you want to find.
  164. \return The scene node associated with that triangle.
  165. */
  166. virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0;
  167. };
  168. } // end namespace scene
  169. } // end namespace irr
  170. #endif