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 5 #ifndef __I_TRIANGLE_SELECTOR_H_INCLUDED__ 6 #define __I_TRIANGLE_SELECTOR_H_INCLUDED__ 7 8 #include "IReferenceCounted.h" 9 #include "triangle3d.h" 10 #include "aabbox3d.h" 11 #include "matrix4.h" 12 #include "line3d.h" 13 14 namespace irr 15 { 16 namespace scene 17 { 18 19 class ISceneNode; 20 21 //! Interface to return triangles with specific properties. 22 /** Every ISceneNode may have a triangle selector, available with 23 ISceneNode::getTriangleScelector() or ISceneManager::createTriangleSelector. 24 This is used for doing collision detection: For example if you know, that a 25 collision may have happened in the area between (1,1,1) and (10,10,10), you 26 can get all triangles of the scene node in this area with the 27 ITriangleSelector easily and check every triangle if it collided. */ 28 class ITriangleSelector : public virtual IReferenceCounted 29 { 30 public: 31 32 //! Get amount of all available triangles in this selector 33 virtual s32 getTriangleCount() const = 0; 34 35 //! Gets the triangles for one associated node. 36 /** 37 This returns all triangles for one scene node associated with this 38 selector. If there is more than one scene node associated (e.g. for 39 an IMetaTriangleSelector) this this function may be called multiple 40 times to retrieve all triangles. 41 \param triangles Array where the resulting triangles will be 42 written to. 43 \param arraySize Size of the target array. 44 \param outTriangleCount: Amount of triangles which have been written 45 into the array. 46 \param transform Pointer to matrix for transforming the triangles 47 before they are returned. Useful for example to scale all triangles 48 down into an ellipsoid space. If this pointer is null, no 49 transformation will be done. */ 50 virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, 51 s32& outTriangleCount, const core::matrix4* transform=0) const = 0; 52 53 //! Gets the triangles for one associated node which may lie within a specific bounding box. 54 /** 55 This returns all triangles for one scene node associated with this 56 selector. If there is more than one scene node associated (e.g. for 57 an IMetaTriangleSelector) this this function may be called multiple 58 times to retrieve all triangles. 59 60 This method will return at least the triangles that intersect the box, 61 but may return other triangles as well. 62 \param triangles Array where the resulting triangles will be written 63 to. 64 \param arraySize Size of the target array. 65 \param outTriangleCount Amount of triangles which have been written 66 into the array. 67 \param box Only triangles which are in this axis aligned bounding box 68 will be written into the array. 69 \param transform Pointer to matrix for transforming the triangles 70 before they are returned. Useful for example to scale all triangles 71 down into an ellipsoid space. If this pointer is null, no 72 transformation will be done. */ 73 virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, 74 s32& outTriangleCount, const core::aabbox3d<f32>& box, 75 const core::matrix4* transform=0) const = 0; 76 77 //! Gets the triangles for one associated node which have or may have contact with a 3d line. 78 /** 79 This returns all triangles for one scene node associated with this 80 selector. If there is more than one scene node associated (e.g. for 81 an IMetaTriangleSelector) this this function may be called multiple 82 times to retrieve all triangles. 83 84 Please note that unoptimized triangle selectors also may return 85 triangles which are not in contact at all with the 3d line. 86 \param triangles Array where the resulting triangles will be written 87 to. 88 \param arraySize Size of the target array. 89 \param outTriangleCount Amount of triangles which have been written 90 into the array. 91 \param line Only triangles which may be in contact with this 3d line 92 will be written into the array. 93 \param transform Pointer to matrix for transforming the triangles 94 before they are returned. Useful for example to scale all triangles 95 down into an ellipsoid space. If this pointer is null, no 96 transformation will be done. */ 97 virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, 98 s32& outTriangleCount, const core::line3d<f32>& line, 99 const core::matrix4* transform=0) const = 0; 100 101 //! Get scene node associated with a given triangle. 102 /** 103 This allows to find which scene node (potentially of several) is 104 associated with a specific triangle. 105 106 \param triangleIndex: the index of the triangle for which you want to find 107 the associated scene node. 108 \return The scene node associated with that triangle. 109 */ 110 virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0; 111 112 //! Get number of TriangleSelectors that are part of this one 113 /** Only useful for MetaTriangleSelector, others return 1 114 */ 115 virtual u32 getSelectorCount() const = 0; 116 117 //! Get TriangleSelector based on index based on getSelectorCount 118 /** Only useful for MetaTriangleSelector, others return 'this' or 0 119 */ 120 virtual ITriangleSelector* getSelector(u32 index) = 0; 121 122 //! Get TriangleSelector based on index based on getSelectorCount 123 /** Only useful for MetaTriangleSelector, others return 'this' or 0 124 */ 125 virtual const ITriangleSelector* getSelector(u32 index) const = 0; 126 }; 127 128 } // end namespace scene 129 } // end namespace irr 130 131 #endif 132