Revert my previous ITriangleSelector patch and implement garritg's great idea about retrieving an ISceneNode by index. Add an out parameter to ISceneCollisionManager::getCollisionPoint() to return the hit scene node. This is an API breaking change; the test and example apps have been updated. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2125 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
74658ced68
commit
81671c23b2
|
@ -1,5 +1,7 @@
|
||||||
Changes in version 1.6
|
Changes in version 1.6
|
||||||
|
|
||||||
|
- Add an outNode to getCollisionPoint() that returns the scene node that was hit, as well as the triangle.
|
||||||
|
|
||||||
- Initial support for Alpha To Coverage, needs some more fixing until it works on all supported platforms.
|
- Initial support for Alpha To Coverage, needs some more fixing until it works on all supported platforms.
|
||||||
|
|
||||||
- Added support for Anti-Aliasing modes per material
|
- Added support for Anti-Aliasing modes per material
|
||||||
|
|
|
@ -123,10 +123,10 @@ int main()
|
||||||
*/
|
*/
|
||||||
IrrlichtDevice *device =
|
IrrlichtDevice *device =
|
||||||
#ifdef _IRR_OSX_PLATFORM_
|
#ifdef _IRR_OSX_PLATFORM_
|
||||||
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
|
createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
|
||||||
false, false, false, 0);
|
false, false, false, 0);
|
||||||
#else
|
#else
|
||||||
createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
|
createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
|
||||||
false, false, false, 0);
|
false, false, false, 0);
|
||||||
#endif
|
#endif
|
||||||
if (!device)
|
if (!device)
|
||||||
|
|
|
@ -251,9 +251,10 @@ int main()
|
||||||
|
|
||||||
core::vector3df intersection;
|
core::vector3df intersection;
|
||||||
core::triangle3df tri;
|
core::triangle3df tri;
|
||||||
|
const scene::ISceneNode* hitNode;
|
||||||
|
|
||||||
if (smgr->getSceneCollisionManager()->getCollisionPoint(
|
if (smgr->getSceneCollisionManager()->getCollisionPoint(
|
||||||
line, selector, intersection, tri))
|
line, selector, intersection, tri, hitNode))
|
||||||
{
|
{
|
||||||
bill->setPosition(intersection);
|
bill->setPosition(intersection);
|
||||||
|
|
||||||
|
|
|
@ -635,9 +635,9 @@ void CDemo::shoot()
|
||||||
core::line3d<f32> line(start, end);
|
core::line3d<f32> line(start, end);
|
||||||
|
|
||||||
// get intersection point with map
|
// get intersection point with map
|
||||||
|
const scene::ISceneNode* hitNode;
|
||||||
if (sm->getSceneCollisionManager()->getCollisionPoint(
|
if (sm->getSceneCollisionManager()->getCollisionPoint(
|
||||||
line, mapSelector, end, triangle))
|
line, mapSelector, end, triangle, hitNode))
|
||||||
{
|
{
|
||||||
// collides with wall
|
// collides with wall
|
||||||
core::vector3df out = triangle.getNormal();
|
core::vector3df out = triangle.getNormal();
|
||||||
|
|
|
@ -38,10 +38,13 @@ namespace scene
|
||||||
contain the position of the nearest collision.
|
contain the position of the nearest collision.
|
||||||
\param outTriangle: If a collision is detected, this will
|
\param outTriangle: If a collision is detected, this will
|
||||||
contain the triangle with which the ray collided.
|
contain the triangle with which the ray collided.
|
||||||
|
\param outNode: If a collision is detected, this will contain
|
||||||
|
the scene node associated with the triangle that was hit.
|
||||||
\return True if a collision was detected and false if not. */
|
\return True if a collision was detected and false if not. */
|
||||||
virtual bool getCollisionPoint(const core::line3d<f32>& ray,
|
virtual bool getCollisionPoint(const core::line3d<f32>& ray,
|
||||||
ITriangleSelector* selector, core::vector3df& outCollisionPoint,
|
ITriangleSelector* selector, core::vector3df& outCollisionPoint,
|
||||||
core::triangle3df& outTriangle) = 0;
|
core::triangle3df& outTriangle,
|
||||||
|
const ISceneNode*& outNode) = 0;
|
||||||
|
|
||||||
//! Collides a moving ellipsoid with a 3d world with gravity and returns the resulting new position of the ellipsoid.
|
//! Collides a moving ellipsoid with a 3d world with gravity and returns the resulting new position of the ellipsoid.
|
||||||
/** This can be used for moving a character in a 3d world: The
|
/** This can be used for moving a character in a 3d world: The
|
||||||
|
|
|
@ -49,23 +49,9 @@ public:
|
||||||
\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
|
before they are returned. Useful for example to scale all triangles
|
||||||
down into an ellipsoid space. If this pointer is null, no
|
down into an ellipsoid space. If this pointer is null, no
|
||||||
transformation will be done.
|
transformation will be done. */
|
||||||
\param node: On input, if this is 0 then all triangles for all nodes
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
will be returned. If *node is 0, or a node that is not associated
|
s32& outTriangleCount, const core::matrix4* transform=0) const = 0;
|
||||||
with any of the triangles in this selector, then the selector will return
|
|
||||||
the triangles for its first (or only) associated node. If you pass in
|
|
||||||
a node for which the selector holds triangles, then it will return
|
|
||||||
the triangles for the *next* node. On output, *node will return the node
|
|
||||||
that is associated with the triangles being returned.
|
|
||||||
\return false if the triangles and node for the last (or only) node
|
|
||||||
are being returned. true if there are more nodes and triangles to
|
|
||||||
return; on true, you may call this method again, passing in the same
|
|
||||||
node that was just returned in order to retrieve the triangles for the
|
|
||||||
next node.
|
|
||||||
*/
|
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
|
||||||
s32& outTriangleCount, const core::matrix4* transform=0,
|
|
||||||
const ISceneNode * * node = 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 lie or may lie within a specific bounding box.
|
||||||
/**
|
/**
|
||||||
|
@ -86,24 +72,10 @@ public:
|
||||||
\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
|
before they are returned. Useful for example to scale all triangles
|
||||||
down into an ellipsoid space. If this pointer is null, no
|
down into an ellipsoid space. If this pointer is null, no
|
||||||
transformation will be done.
|
transformation will be done. */
|
||||||
\param node: On input, if this is 0 then all triangles for all nodes
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
will be returned. If *node is 0, or a node that is not associated
|
|
||||||
with any of the triangles in this selector, then the selector will return
|
|
||||||
the triangles for its first (or only) associated node. If you pass in
|
|
||||||
a node for which the selector holds triangles, then it will return
|
|
||||||
the triangles for the *next* node. On output, *node will return the node
|
|
||||||
that is associated with the triangles being returned.
|
|
||||||
\return false if the triangles and node for the last (or only) node
|
|
||||||
are being returned. true if there are more nodes and triangles to
|
|
||||||
return; on true, you may call this method again, passing in the same
|
|
||||||
node that was just returned in order to retrieve the triangles for the
|
|
||||||
next node.
|
|
||||||
*/
|
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
|
||||||
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const = 0;
|
||||||
const ISceneNode * * node = 0) const = 0;
|
|
||||||
|
|
||||||
//! Gets the triangles for one associated node which have or may have contact with a 3d line.
|
//! Gets the triangles for one associated node which have or may have contact with a 3d line.
|
||||||
/**
|
/**
|
||||||
|
@ -124,27 +96,22 @@ public:
|
||||||
\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
|
before they are returned. Useful for example to scale all triangles
|
||||||
down into an ellipsoid space. If this pointer is null, no
|
down into an ellipsoid space. If this pointer is null, no
|
||||||
transformation will be done.
|
transformation will be done. */
|
||||||
\param node: On input, if this is 0 then all triangles for all nodes
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
will be returned. If *node is 0, or a node that is not associated
|
|
||||||
with any of the triangles in this selector, then the selector will return
|
|
||||||
the triangles for its first (or only) associated node. If you pass in
|
|
||||||
a node for which the selector holds triangles, then it will return
|
|
||||||
the triangles for the *next* node. On output, *node will return the node
|
|
||||||
that is associated with the triangles being returned.
|
|
||||||
\return false if the triangles and node for the last (or only) node
|
|
||||||
are being returned. true if there are more nodes and triangles to
|
|
||||||
return; on true, you may call this method again, passing in the same
|
|
||||||
node that was just returned in order to retrieve the triangles for the
|
|
||||||
next node.
|
|
||||||
*/
|
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const = 0;
|
||||||
const ISceneNode * * node = 0) const = 0;
|
|
||||||
|
//! Return the scene node associated with a given triangle.
|
||||||
|
/**
|
||||||
|
This allows you 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
|
||||||
|
the associated scene node.
|
||||||
|
\return The scene node associated with that triangle.
|
||||||
|
*/
|
||||||
|
virtual const ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0;
|
||||||
|
|
||||||
//! Gets the scene node to which this selector is associated.
|
|
||||||
virtual const ISceneNode* getSceneNode(void) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace scene
|
} // end namespace scene
|
||||||
|
|
|
@ -37,163 +37,58 @@ s32 CMetaTriangleSelector::getTriangleCount() const
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
bool CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::matrix4* transform,
|
s32& outTriangleCount, const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
s32 outWritten = 0;
|
s32 outWritten = 0;
|
||||||
|
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
||||||
if(node)
|
|
||||||
{
|
{
|
||||||
if(TriangleSelectors.size() == 0)
|
|
||||||
{
|
|
||||||
*node = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 selector = 0;
|
|
||||||
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
if(*node == TriangleSelectors[i]->getSceneNode())
|
|
||||||
{
|
|
||||||
selector = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 t = 0;
|
s32 t = 0;
|
||||||
TriangleSelectors[selector]->getTriangles(triangles + outWritten,
|
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
||||||
arraySize - outWritten, t,
|
arraySize - outWritten, t,
|
||||||
transform);
|
transform);
|
||||||
outWritten += t;
|
outWritten += t;
|
||||||
|
|
||||||
*node = TriangleSelectors[selector]->getSceneNode();
|
|
||||||
|
|
||||||
if(selector < TriangleSelectors.size() - 1)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
{
|
|
||||||
s32 t = 0;
|
|
||||||
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
|
||||||
arraySize - outWritten, t,
|
|
||||||
transform);
|
|
||||||
outWritten += t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = outWritten;
|
outTriangleCount = outWritten;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
bool CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
s32 outWritten = 0;
|
s32 outWritten = 0;
|
||||||
|
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
||||||
if(node)
|
|
||||||
{
|
{
|
||||||
if(TriangleSelectors.size() == 0)
|
|
||||||
{
|
|
||||||
*node = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 selector = 0;
|
|
||||||
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
if(*node == TriangleSelectors[i]->getSceneNode())
|
|
||||||
{
|
|
||||||
selector = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 t = 0;
|
s32 t = 0;
|
||||||
TriangleSelectors[selector]->getTriangles(triangles + outWritten,
|
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
||||||
arraySize - outWritten, t,
|
arraySize - outWritten, t,
|
||||||
box, transform);
|
box, transform);
|
||||||
outWritten += t;
|
outWritten += t;
|
||||||
|
|
||||||
*node = TriangleSelectors[selector]->getSceneNode();
|
|
||||||
|
|
||||||
if(selector < TriangleSelectors.size() - 1)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
{
|
|
||||||
s32 t = 0;
|
|
||||||
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
|
||||||
arraySize - outWritten, t,
|
|
||||||
box, transform);
|
|
||||||
outWritten += t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = outWritten;
|
outTriangleCount = outWritten;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
bool CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
void CMetaTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
s32 outWritten = 0;
|
s32 outWritten = 0;
|
||||||
|
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
||||||
if(node)
|
|
||||||
{
|
{
|
||||||
if(TriangleSelectors.size() == 0)
|
|
||||||
{
|
|
||||||
*node = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 selector = 0;
|
|
||||||
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
if(*node == TriangleSelectors[i]->getSceneNode())
|
|
||||||
{
|
|
||||||
selector = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
s32 t = 0;
|
s32 t = 0;
|
||||||
TriangleSelectors[selector]->getTriangles(triangles + outWritten,
|
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
||||||
arraySize - outWritten, t,
|
arraySize - outWritten, t,
|
||||||
line, transform);
|
line, transform);
|
||||||
outWritten += t;
|
outWritten += t;
|
||||||
|
|
||||||
*node = TriangleSelectors[selector]->getSceneNode();
|
|
||||||
|
|
||||||
if(selector < TriangleSelectors.size() - 1)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
|
||||||
{
|
|
||||||
s32 t = 0;
|
|
||||||
TriangleSelectors[i]->getTriangles(triangles + outWritten,
|
|
||||||
arraySize - outWritten, t,
|
|
||||||
line, transform);
|
|
||||||
outWritten += t;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = outWritten;
|
outTriangleCount = outWritten;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,6 +130,24 @@ void CMetaTriangleSelector::removeAllTriangleSelectors()
|
||||||
TriangleSelectors.clear();
|
TriangleSelectors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Return the scene node associated with a given triangle.
|
||||||
|
const ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
|
||||||
|
{
|
||||||
|
u32 totalTriangles = 0;
|
||||||
|
|
||||||
|
for (u32 i=0; i<TriangleSelectors.size(); ++i)
|
||||||
|
{
|
||||||
|
totalTriangles += TriangleSelectors[i]->getTriangleCount();
|
||||||
|
|
||||||
|
if(totalTriangles > triangleIndex)
|
||||||
|
return TriangleSelectors[i]->getSceneNodeForTriangle(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For lack of anything more sensible, return the first selector.
|
||||||
|
return TriangleSelectors[0]->getSceneNodeForTriangle(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace scene
|
} // end namespace scene
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
|
|
@ -28,21 +28,18 @@ public:
|
||||||
virtual s32 getTriangleCount() const;
|
virtual s32 getTriangleCount() const;
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::matrix4* transform=0,
|
s32& outTriangleCount, const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Adds a triangle selector to the collection of triangle selectors
|
//! Adds a triangle selector to the collection of triangle selectors
|
||||||
//! in this metaTriangleSelector.
|
//! in this metaTriangleSelector.
|
||||||
|
@ -54,8 +51,8 @@ public:
|
||||||
//! Removes all triangle selectors from the collection.
|
//! Removes all triangle selectors from the collection.
|
||||||
virtual void removeAllTriangleSelectors();
|
virtual void removeAllTriangleSelectors();
|
||||||
|
|
||||||
//! *This* selector isn't associated with any specific node
|
//! Return the scene node associated with a given triangle.
|
||||||
virtual const ISceneNode* getSceneNode(void) const { return 0; }
|
virtual const ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -109,11 +109,10 @@ void COctTreeTriangleSelector::constructOctTree(SOctTreeNode* node)
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
bool COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles,
|
void COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
s32 arraySize, s32& outTriangleCount,
|
s32 arraySize, s32& outTriangleCount,
|
||||||
const core::aabbox3d<f32>& box,
|
const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
core::matrix4 mat;
|
core::matrix4 mat;
|
||||||
core::aabbox3d<f32> invbox = box;
|
core::aabbox3d<f32> invbox = box;
|
||||||
|
@ -140,10 +139,6 @@ bool COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
arraySize, invbox, &mat, triangles);
|
arraySize, invbox, &mat, triangles);
|
||||||
|
|
||||||
outTriangleCount = trianglesWritten;
|
outTriangleCount = trianglesWritten;
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,10 +173,9 @@ void COctTreeTriangleSelector::getTrianglesFromOctTree(
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
bool COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
void COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
core::aabbox3d<f32> box(line.start);
|
core::aabbox3d<f32> box(line.start);
|
||||||
box.addInternalPoint(line.end);
|
box.addInternalPoint(line.end);
|
||||||
|
@ -189,10 +183,6 @@ bool COctTreeTriangleSelector::getTriangles(core::triangle3df* triangles, s32 ar
|
||||||
// TODO: Could be optimized for line a little bit more.
|
// TODO: Could be optimized for line a little bit more.
|
||||||
COctTreeTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount,
|
COctTreeTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount,
|
||||||
box, transform);
|
box, transform);
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,13 @@ public:
|
||||||
virtual ~COctTreeTriangleSelector();
|
virtual ~COctTreeTriangleSelector();
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::aabbox3d<f32>& box, const core::matrix4* transform=0,
|
const core::aabbox3d<f32>& box, const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,8 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromCameraBB(
|
||||||
//! Finds the collision point of a line and lots of triangles, if there is one.
|
//! Finds the collision point of a line and lots of triangles, if there is one.
|
||||||
bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray,
|
bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray,
|
||||||
ITriangleSelector* selector, core::vector3df& outIntersection,
|
ITriangleSelector* selector, core::vector3df& outIntersection,
|
||||||
core::triangle3df& outTriangle)
|
core::triangle3df& outTriangle,
|
||||||
|
const ISceneNode*& outNode)
|
||||||
{
|
{
|
||||||
if (!selector)
|
if (!selector)
|
||||||
{
|
{
|
||||||
|
@ -291,6 +292,7 @@ bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray,
|
||||||
nearest = tmp;
|
nearest = tmp;
|
||||||
outTriangle = triangle;
|
outTriangle = triangle;
|
||||||
outIntersection = intersection;
|
outIntersection = intersection;
|
||||||
|
outNode = selector->getSceneNodeForTriangle(i);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ namespace scene
|
||||||
//! Finds the collision point of a line and lots of triangles, if there is one.
|
//! Finds the collision point of a line and lots of triangles, if there is one.
|
||||||
virtual bool getCollisionPoint(const core::line3d<f32>& ray,
|
virtual bool getCollisionPoint(const core::line3d<f32>& ray,
|
||||||
ITriangleSelector* selector, core::vector3df& outCollisionPoint,
|
ITriangleSelector* selector, core::vector3df& outCollisionPoint,
|
||||||
core::triangle3df& outTriangle);
|
core::triangle3df& outTriangle,
|
||||||
|
const ISceneNode* & outNode);
|
||||||
|
|
||||||
//! Collides a moving ellipsoid with a 3d world with gravity and returns
|
//! Collides a moving ellipsoid with a 3d world with gravity and returns
|
||||||
//! the resulting new position of the ellipsoid.
|
//! the resulting new position of the ellipsoid.
|
||||||
|
|
|
@ -75,8 +75,8 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
bool CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
|
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::matrix4* transform, const ISceneNode * * node) const
|
s32& outTriangleCount, const core::matrix4* transform) const
|
||||||
{
|
{
|
||||||
s32 count = TrianglePatches.TotalTriangles;
|
s32 count = TrianglePatches.TotalTriangles;
|
||||||
|
|
||||||
|
@ -106,17 +106,13 @@ bool CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = tIndex;
|
outTriangleCount = tIndex;
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
bool CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
|
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
s32& outTriangleCount, const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform, const ISceneNode * * node) const
|
const core::matrix4* transform) const
|
||||||
{
|
{
|
||||||
s32 count = TrianglePatches.TotalTriangles;
|
s32 count = TrianglePatches.TotalTriangles;
|
||||||
|
|
||||||
|
@ -147,16 +143,12 @@ bool CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = tIndex;
|
outTriangleCount = tIndex;
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
bool CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform, const ISceneNode * * node) const
|
const core::matrix4* transform) const
|
||||||
{
|
{
|
||||||
const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize);
|
const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize);
|
||||||
|
|
||||||
|
@ -186,10 +178,6 @@ bool CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 ar
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = tIndex;
|
outTriangleCount = tIndex;
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Returns amount of all available triangles in this selector
|
//! Returns amount of all available triangles in this selector
|
||||||
|
|
|
@ -37,26 +37,25 @@ public:
|
||||||
virtual void setTriangleData (ITerrainSceneNode* node, s32 LOD);
|
virtual void setTriangleData (ITerrainSceneNode* node, s32 LOD);
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::aabbox3d<f32>& box, const core::matrix4* transform=0,
|
const core::aabbox3d<f32>& box, const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Returns amount of all available triangles in this selector
|
//! Returns amount of all available triangles in this selector
|
||||||
virtual s32 getTriangleCount() const;
|
virtual s32 getTriangleCount() const;
|
||||||
|
|
||||||
//! ITerrainSceneNode is an ISceneNode, we just don't know it yet.
|
//! Return the scene node associated with a given triangle.
|
||||||
virtual const ISceneNode* getSceneNode(void) const { return (ISceneNode*)SceneNode; }
|
/** ITerrainSceneNode is an ISceneNode, we just don't know it yet. */
|
||||||
|
virtual const ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const
|
||||||
|
{ return (ISceneNode*)SceneNode; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,12 @@ CTriangleBBSelector::CTriangleBBSelector(const ISceneNode* node)
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
bool CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
|
void CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
|
||||||
s32 arraySize, s32& outTriangleCount,
|
s32 arraySize, s32& outTriangleCount,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
if (!SceneNode)
|
if (!SceneNode)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
// construct triangles
|
// construct triangles
|
||||||
const core::aabbox3d<f32>& box = SceneNode->getBoundingBox();
|
const core::aabbox3d<f32>& box = SceneNode->getBoundingBox();
|
||||||
|
@ -57,10 +56,6 @@ bool CTriangleBBSelector::getTriangles(core::triangle3df* triangles,
|
||||||
|
|
||||||
// call parent
|
// call parent
|
||||||
CTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount, transform);
|
CTriangleSelector::getTriangles(triangles, arraySize, outTriangleCount, transform);
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ public:
|
||||||
CTriangleBBSelector(const ISceneNode* node);
|
CTriangleBBSelector(const ISceneNode* node);
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::matrix4* transform=0, const ISceneNode * * node = 0) const;
|
const core::matrix4* transform=0) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace scene
|
} // end namespace scene
|
||||||
|
|
|
@ -67,10 +67,9 @@ CTriangleSelector::CTriangleSelector(const core::aabbox3d<f32>& box, const IScen
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
bool CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
s32 arraySize, s32& outTriangleCount,
|
s32 arraySize, s32& outTriangleCount,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
s32 cnt = Triangles.size();
|
s32 cnt = Triangles.size();
|
||||||
if (cnt > arraySize)
|
if (cnt > arraySize)
|
||||||
|
@ -93,36 +92,29 @@ bool CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
}
|
}
|
||||||
|
|
||||||
outTriangleCount = cnt;
|
outTriangleCount = cnt;
|
||||||
|
|
||||||
if(node)
|
|
||||||
*node = SceneNode;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
bool CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
s32 arraySize, s32& outTriangleCount,
|
s32 arraySize, s32& outTriangleCount,
|
||||||
const core::aabbox3d<f32>& box,
|
const core::aabbox3d<f32>& box,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
// return all triangles
|
// return all triangles
|
||||||
return getTriangles(triangles, arraySize, outTriangleCount, transform, node);
|
return getTriangles(triangles, arraySize, outTriangleCount, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
bool CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
void CTriangleSelector::getTriangles(core::triangle3df* triangles,
|
||||||
s32 arraySize, s32& outTriangleCount,
|
s32 arraySize, s32& outTriangleCount,
|
||||||
const core::line3d<f32>& line,
|
const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform,
|
const core::matrix4* transform) const
|
||||||
const ISceneNode * * node) const
|
|
||||||
{
|
{
|
||||||
// return all triangles
|
// return all triangles
|
||||||
return getTriangles(triangles, arraySize, outTriangleCount, transform, node);
|
return getTriangles(triangles, arraySize, outTriangleCount, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,26 +31,23 @@ public:
|
||||||
CTriangleSelector(const core::aabbox3d<f32>& box, const ISceneNode* node);
|
CTriangleSelector(const core::aabbox3d<f32>& box, const ISceneNode* node);
|
||||||
|
|
||||||
//! Gets all triangles.
|
//! Gets all triangles.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which lie within a specific bounding box.
|
//! Gets all triangles which lie within a specific bounding box.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
void getTriangles(core::triangle3df* triangles, s32 arraySize, s32& outTriangleCount,
|
||||||
const core::aabbox3d<f32>& box, const core::matrix4* transform=0,
|
const core::aabbox3d<f32>& box, const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Gets all triangles which have or may have contact with a 3d line.
|
//! Gets all triangles which have or may have contact with a 3d line.
|
||||||
virtual bool getTriangles(core::triangle3df* triangles, s32 arraySize,
|
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
|
||||||
s32& outTriangleCount, const core::line3d<f32>& line,
|
s32& outTriangleCount, const core::line3d<f32>& line,
|
||||||
const core::matrix4* transform=0,
|
const core::matrix4* transform=0) const;
|
||||||
const ISceneNode * * node = 0) const;
|
|
||||||
|
|
||||||
//! Returns amount of all available triangles in this selector
|
//! Returns amount of all available triangles in this selector
|
||||||
virtual s32 getTriangleCount() const;
|
virtual s32 getTriangleCount() const;
|
||||||
|
|
||||||
//! Gets the scene node to which this selector is associated.
|
//! Return the scene node associated with a given triangle.
|
||||||
virtual const ISceneNode* getSceneNode(void) const { return SceneNode; }
|
virtual const ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const { return SceneNode; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -99,11 +99,18 @@ static bool getCollisionPoint_ignoreTriangleVertices(IrrlichtDevice * device,
|
||||||
line3df ray(0, 0, -5, 0, 0, 100);
|
line3df ray(0, 0, -5, 0, 0, 100);
|
||||||
vector3df hitPosition;
|
vector3df hitPosition;
|
||||||
triangle3df hitTriangle;
|
triangle3df hitTriangle;
|
||||||
|
const ISceneNode* hitNode;
|
||||||
|
|
||||||
bool collision = collMgr->getCollisionPoint(ray, meta, hitPosition, hitTriangle);
|
bool collision = collMgr->getCollisionPoint(ray, meta, hitPosition, hitTriangle, hitNode);
|
||||||
|
|
||||||
meta->drop();
|
meta->drop();
|
||||||
|
|
||||||
|
if(hitNode != nearBigCube)
|
||||||
|
{
|
||||||
|
logTestString("getCollisionPoint_ignoreTriangleVertices: hit the wrong node.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(!collision)
|
if(!collision)
|
||||||
{
|
{
|
||||||
logTestString("getCollisionPoint_ignoreTriangleVertices: didn't get a hit.\n");
|
logTestString("getCollisionPoint_ignoreTriangleVertices: didn't get a hit.\n");
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
Test suite pass at GMT Thu Jan 22 14:10:54 2009
|
Test suite pass at GMT Thu Jan 22 15:48:42 2009
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue