Commit 8a9d6361 authored by hybrid's avatar hybrid

Add triangle selector methods to get back single selectors from meta triangle...

Add triangle selector methods to get back single selectors from meta triangle selector. Submitted by LexManos

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3707 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e13d17c2
......@@ -29,10 +29,7 @@ class ITriangleSelector : public virtual IReferenceCounted
{
public:
//! Destructor
virtual ~ITriangleSelector() {}
//! Returns amount of all available triangles in this selector
//! Get amount of all available triangles in this selector
virtual s32 getTriangleCount() const = 0;
//! Gets the triangles for one associated node.
......@@ -41,19 +38,19 @@ public:
selector. If there is more than one scene node associated (e.g. for
an IMetaTriangleSelector) this this function may be called multiple
times to retrieve all triangles.
\param triangles: Array where the resulting triangles will be
\param triangles Array where the resulting triangles will be
written to.
\param arraySize: Size of the target array.
\param arraySize Size of the target array.
\param outTriangleCount: Amount of triangles which have been written
into the array.
\param transform: Pointer to matrix for transforming the triangles
\param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no
transformation will be done. */
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform=0) const = 0;
//! Gets the triangles for one associated node which lie or may lie within a specific bounding box.
//! Gets the triangles for one associated node which may lie within a specific bounding box.
/**
This returns all triangles for one scene node associated with this
selector. If there is more than one scene node associated (e.g. for
......@@ -62,14 +59,14 @@ public:
This method will return at least the triangles that intersect the box,
but may return other triangles as well.
\param triangles: Array where the resulting triangles will be written
\param triangles Array where the resulting triangles will be written
to.
\param arraySize: Size of the target array.
\param outTriangleCount: Amount of triangles which have been written
\param arraySize Size of the target array.
\param outTriangleCount Amount of triangles which have been written
into the array.
\param box: Only triangles which are in this axis aligned bounding box
\param box Only triangles which are in this axis aligned bounding box
will be written into the array.
\param transform: Pointer to matrix for transforming the triangles
\param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no
transformation will be done. */
......@@ -86,14 +83,14 @@ public:
Please note that unoptimized triangle selectors also may return
triangles which are not in contact at all with the 3d line.
\param triangles: Array where the resulting triangles will be written
\param triangles Array where the resulting triangles will be written
to.
\param arraySize: Size of the target array.
\param outTriangleCount: Amount of triangles which have been written
\param arraySize Size of the target array.
\param outTriangleCount Amount of triangles which have been written
into the array.
\param line: Only triangles which may be in contact with this 3d line
\param line Only triangles which may be in contact with this 3d line
will be written into the array.
\param transform: Pointer to matrix for transforming the triangles
\param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no
transformation will be done. */
......@@ -101,9 +98,9 @@ public:
s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform=0) const = 0;
//! Return the scene node associated with a given triangle.
//! Get scene node associated with a given triangle.
/**
This allows you to find which scene node (potentially of several) is
This allows to find which scene node (potentially of several) is
associated with a specific triangle.
\param triangleIndex: the index of the triangle for which you want to find
......@@ -112,11 +109,18 @@ public:
*/
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0;
//! Get number of TriangleSelectors that are part of this one
/** Only useful for MetaTriangleSelector, others return 1
*/
virtual const u32 getSelectorCount() const = 0;
//! Get TriangleSelector based on index based on getSelectorCount
/** Only useful for MetaTriangleSelector, others return 'this' or 0
*/
virtual const ITriangleSelector* getSelector(u32 index) const = 0;
};
} // end namespace scene
} // end namespace irr
#endif
......@@ -152,6 +152,26 @@ ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) co
}
/* Return the number of TriangleSelectors that are inside this one,
Only useful for MetaTriangleSelector others return 1
*/
const u32 CMetaTriangleSelector::getSelectorCount() const
{
return TriangleSelectors.size();
}
/* Returns the TriangleSelector based on index based on getSelectorCount
Only useful for MetaTriangleSelector others return 'this'
*/
const ITriangleSelector* CMetaTriangleSelector::getSelector(u32 index) const
{
if(index >= TriangleSelectors.size())
return 0;
return TriangleSelectors[index];
}
} // end namespace scene
} // end namespace irr
......@@ -24,7 +24,7 @@ public:
//! destructor
virtual ~CMetaTriangleSelector();
//! Returns amount of all available triangles in this selector
//! Get amount of all available triangles in this selector
virtual s32 getTriangleCount() const;
//! Gets all triangles.
......@@ -51,9 +51,15 @@ public:
//! Removes all triangle selectors from the collection.
virtual void removeAllTriangleSelectors();
//! Return the scene node associated with a given triangle.
//! Get the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const;
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
private:
core::array<ITriangleSelector*> TriangleSelectors;
......
......@@ -34,11 +34,8 @@ CTerrainTriangleSelector::~CTerrainTriangleSelector()
//! Clears and sets triangle data
void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
{
core::triangle3df tri;
core::array<u32> indices;
// Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = static_cast<video::S3DVertex2TCoords*>(node->getRenderBuffer()->getVertices());
const video::S3DVertex2TCoords* vertices = static_cast<const video::S3DVertex2TCoords*>(node->getRenderBuffer()->getVertices());
// Clear current data
const s32 count = (static_cast<CTerrainSceneNode*>(node))->TerrainData.PatchCount;
......@@ -49,6 +46,8 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
for (s32 o=0; o<TrianglePatches.NumPatches; ++o)
TrianglePatches.TrianglePatchArray.push_back(SGeoMipMapTrianglePatch());
core::triangle3df tri;
core::array<u32> indices;
s32 tIndex = 0;
for(s32 x = 0; x < count; ++x )
{
......@@ -74,9 +73,11 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
}
}
//! Gets all triangles.
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform) const
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount,
const core::matrix4* transform) const
{
s32 count = TrianglePatches.TotalTriangles;
......@@ -110,9 +111,9 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
//! Gets all triangles which lie within a specific bounding box.
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::aabbox3d<f32>& box,
const core::matrix4* transform) const
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount,
const core::aabbox3d<f32>& box, const core::matrix4* transform) const
{
s32 count = TrianglePatches.TotalTriangles;
......@@ -145,10 +146,11 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
outTriangleCount = tIndex;
}
//! Gets all triangles which have or may have contact with a 3d line.
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform) const
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32 arraySize, s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform) const
{
const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize);
......@@ -180,17 +182,41 @@ void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 ar
outTriangleCount = tIndex;
}
//! Returns amount of all available triangles in this selector
s32 CTerrainTriangleSelector::getTriangleCount() const
{
return TrianglePatches.TotalTriangles;
}
ISceneNode* CTerrainTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
ISceneNode* CTerrainTriangleSelector::getSceneNodeForTriangle(
u32 triangleIndex) const
{
return SceneNode;
}
/* Get the number of TriangleSelectors that are part of this one.
Only useful for MetaTriangleSelector others return 1
*/
const u32 CTerrainTriangleSelector::getSelectorCount() const
{
return 1;
}
/* Get the TriangleSelector based on index based on getSelectorCount.
Only useful for MetaTriangleSelector others return 'this' or 0
*/
const ITriangleSelector* CTerrainTriangleSelector::getSelector(u32 index) const
{
if (index)
return 0;
else
return this;
}
} // end namespace scene
} // end namespace irr
......@@ -20,14 +20,16 @@ namespace scene
class ITerrainSceneNode;
//! Triangle Selector for the TerrainSceneNode
//! The code for the TerrainTriangleSelector is based on the GeoMipMapSelector
//! developed by Spintz. He made it available for Irrlicht and allowed it to be
//! distributed under this licence. I only modified some parts. A lot of thanks go to him.
/** The code for the TerrainTriangleSelector is based on the GeoMipMapSelector
developed by Spintz. He made it available for Irrlicht and allowed it to be
distributed under this licence. I only modified some parts. A lot of thanks go
to him.
*/
class CTerrainTriangleSelector : public ITriangleSelector
{
public:
//! Constructs a selector based on an IGeoMipMapSceneNode
//! Constructs a selector based on an ITerrainSceneNode
CTerrainTriangleSelector(ITerrainSceneNode* node, s32 LOD);
//! Destructor
......@@ -55,15 +57,21 @@ public:
//! Return the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const;
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
private:
friend class CTerrainSceneNode;
struct SGeoMipMapTrianglePatch
{
core::array<core::triangle3df> Triangles;
s32 NumTriangles;
core::aabbox3df Box;
core::array<core::triangle3df> Triangles;
s32 NumTriangles;
core::aabbox3df Box;
};
struct SGeoMipMapTrianglePatches
......@@ -73,13 +81,13 @@ private:
{
}
core::array<SGeoMipMapTrianglePatch> TrianglePatchArray;
s32 NumPatches;
u32 TotalTriangles;
core::array<SGeoMipMapTrianglePatch> TrianglePatchArray;
s32 NumPatches;
u32 TotalTriangles;
};
ITerrainSceneNode* SceneNode;
SGeoMipMapTrianglePatches TrianglePatches;
ITerrainSceneNode* SceneNode;
SGeoMipMapTrianglePatches TrianglePatches;
};
} // end namespace scene
......@@ -87,4 +95,3 @@ private:
#endif // __C_TERRAIN_TRIANGLE_SELECTOR_H__
......@@ -231,6 +231,26 @@ s32 CTriangleSelector::getTriangleCount() const
}
/* Get the number of TriangleSelectors that are part of this one.
Only useful for MetaTriangleSelector others return 1
*/
const u32 CTriangleSelector::getSelectorCount() const
{
return 1;
}
/* Get the TriangleSelector based on index based on getSelectorCount.
Only useful for MetaTriangleSelector others return 'this' or 0
*/
const ITriangleSelector* CTriangleSelector::getSelector(u32 index) const
{
if (index)
return 0;
else
return this;
}
} // end namespace scene
} // end namespace irr
......
......@@ -54,6 +54,12 @@ public:
//! Return the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const { return SceneNode; }
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
protected:
//! Create from a mesh
virtual void createFromMesh(const IMesh* mesh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment