Commit 2563bf14 authored by Rogerborg's avatar Rogerborg

Small efficiency improvements in scene collision:

Have all public ISceneCollisionManager.h methods take 'const type &' rather than 'type' where appropriate.

Conversely, have CSceneManager::getPickedNodeBB() take a non-const 'core::line3df& ray', so that child nodes can truncate the master ray when they get a collision.

This is an API change, so goes to the trunk only.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2050 dfc29bdd-3216-0410-991c-e03cc46cb475
parent d232810c
...@@ -84,7 +84,7 @@ namespace scene ...@@ -84,7 +84,7 @@ namespace scene
at a length of the far value of the camera at a position which at a length of the far value of the camera at a position which
would be behind the 2d screen coodinates. */ would be behind the 2d screen coodinates. */
virtual core::line3d<f32> getRayFromScreenCoordinates( virtual core::line3d<f32> getRayFromScreenCoordinates(
core::position2d<s32> pos, ICameraSceneNode* camera = 0) = 0; const core::position2d<s32> & pos, ICameraSceneNode* camera = 0) = 0;
//! Calculates 2d screen position from a 3d position. //! Calculates 2d screen position from a 3d position.
/** \param pos: 3D position in world space to be transformed /** \param pos: 3D position in world space to be transformed
...@@ -98,7 +98,7 @@ namespace scene ...@@ -98,7 +98,7 @@ namespace scene
method for drawing a decorator over a 3d object, it will be method for drawing a decorator over a 3d object, it will be
clipped by the screen borders. */ clipped by the screen borders. */
virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition( virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition(
core::vector3df pos, ICameraSceneNode* camera=0) = 0; const core::vector3df & pos, ICameraSceneNode* camera=0) = 0;
//! Gets the scene node, which is currently visible under the given screencoordinates, viewed from the currently active camera. //! Gets the scene node, which is currently visible under the given screencoordinates, viewed from the currently active camera.
/** The collision tests are done using a bounding box for each /** The collision tests are done using a bounding box for each
...@@ -113,7 +113,7 @@ namespace scene ...@@ -113,7 +113,7 @@ namespace scene
\return Visible scene node under screen coordinates with \return Visible scene node under screen coordinates with
matching bits in its id. If there is no scene node under this matching bits in its id. If there is no scene node under this
position, 0 is returned. */ position, 0 is returned. */
virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(core::position2d<s32> pos, virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(const core::position2d<s32> & pos,
s32 idBitMask=0, bool bNoDebugObjects = false) = 0; s32 idBitMask=0, bool bNoDebugObjects = false) = 0;
//! Get the nearest scene node which collides with a 3d ray and whose id matches a bitmask. //! Get the nearest scene node which collides with a 3d ray and whose id matches a bitmask.
...@@ -128,7 +128,7 @@ namespace scene ...@@ -128,7 +128,7 @@ namespace scene
\return Scene node nearest to ray.start, which collides with \return Scene node nearest to ray.start, which collides with
the ray and matches the idBitMask, if the mask is not null. If the ray and matches the idBitMask, if the mask is not null. If
no scene node is found, 0 is returned. */ no scene node is found, 0 is returned. */
virtual ISceneNode* getSceneNodeFromRayBB(core::line3d<f32> ray, virtual ISceneNode* getSceneNodeFromRayBB(const core::line3d<f32> & ray,
s32 idBitMask=0, bool bNoDebugObjects = false) = 0; s32 idBitMask=0, bool bNoDebugObjects = false) = 0;
//! Get the scene node, which the overgiven camera is looking at and whose id matches the bitmask. //! Get the scene node, which the overgiven camera is looking at and whose id matches the bitmask.
......
...@@ -43,7 +43,7 @@ CSceneCollisionManager::~CSceneCollisionManager() ...@@ -43,7 +43,7 @@ CSceneCollisionManager::~CSceneCollisionManager()
//! Returns the scene node, which is currently visible under the overgiven //! Returns the scene node, which is currently visible under the overgiven
//! screencoordinates, viewed from the currently active camera. //! screencoordinates, viewed from the currently active camera.
ISceneNode* CSceneCollisionManager::getSceneNodeFromScreenCoordinatesBB( ISceneNode* CSceneCollisionManager::getSceneNodeFromScreenCoordinatesBB(
core::position2d<s32> pos, s32 idBitMask, bool bNoDebugObjects) const core::position2d<s32> & pos, s32 idBitMask, bool bNoDebugObjects)
{ {
core::line3d<f32> ln = getRayFromScreenCoordinates(pos, 0); core::line3d<f32> ln = getRayFromScreenCoordinates(pos, 0);
...@@ -57,14 +57,16 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromScreenCoordinatesBB( ...@@ -57,14 +57,16 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromScreenCoordinatesBB(
//! Returns the nearest scene node which collides with a 3d ray and //! Returns the nearest scene node which collides with a 3d ray and
//! which id matches a bitmask. //! which id matches a bitmask.
ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(core::line3d<f32> ray, ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(const core::line3d<f32> & ray,
s32 idBitMask, s32 idBitMask,
bool bNoDebugObjects) bool bNoDebugObjects)
{ {
ISceneNode* best = 0; ISceneNode* best = 0;
f32 dist = FLT_MAX; f32 dist = FLT_MAX;
getPickedNodeBB(SceneManager->getRootSceneNode(), ray, core::line3d<f32> truncatableRay(ray);
getPickedNodeBB(SceneManager->getRootSceneNode(), truncatableRay,
idBitMask, bNoDebugObjects, dist, best); idBitMask, bNoDebugObjects, dist, best);
return best; return best;
...@@ -73,14 +75,13 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(core::line3d<f32> ray, ...@@ -73,14 +75,13 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(core::line3d<f32> ray,
//! recursive method for going through all scene nodes //! recursive method for going through all scene nodes
void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root, void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
const core::line3df& ray, core::line3df& ray,
s32 bits, s32 bits,
bool bNoDebugObjects, bool bNoDebugObjects,
f32& outbestdistance, f32& outbestdistance,
ISceneNode*& outbestnode) ISceneNode*& outbestnode)
{ {
const core::list<ISceneNode*>& children = root->getChildren(); const core::list<ISceneNode*>& children = root->getChildren();
core::line3df truncatedRay(ray);
const core::vector3df rayVector = ray.getVector().normalize(); const core::vector3df rayVector = ray.getVector().normalize();
core::list<ISceneNode*>::ConstIterator it = children.begin(); core::list<ISceneNode*>::ConstIterator it = children.begin();
...@@ -99,7 +100,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root, ...@@ -99,7 +100,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
continue; continue;
// transform vector from world space to object space // transform vector from world space to object space
core::line3df objectRay(truncatedRay); core::line3df objectRay(ray);
worldToObject.transformVect(objectRay.start); worldToObject.transformVect(objectRay.start);
worldToObject.transformVect(objectRay.end); worldToObject.transformVect(objectRay.end);
...@@ -118,7 +119,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root, ...@@ -118,7 +119,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
outbestnode = current; outbestnode = current;
// And we can truncate the ray to stop us hitting further nodes. // And we can truncate the ray to stop us hitting further nodes.
truncatedRay.end = truncatedRay.start + (rayVector * sqrtf(toIntersectionSq)); ray.end = ray.start + (rayVector * sqrtf(toIntersectionSq));
} }
} }
else if (objectBox.intersectsWithLine(objectRay)) else if (objectBox.intersectsWithLine(objectRay))
...@@ -202,7 +203,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root, ...@@ -202,7 +203,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
// If we got a hit, we can now truncate the ray to stop us hitting further nodes. // If we got a hit, we can now truncate the ray to stop us hitting further nodes.
if(gotHit) if(gotHit)
truncatedRay.end = truncatedRay.start + (rayVector * sqrtf(outbestdistance)); ray.end = ray.start + (rayVector * sqrtf(outbestdistance));
} }
} }
...@@ -727,7 +728,7 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth, ...@@ -727,7 +728,7 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth,
//! Returns a 3d ray which would go through the 2d screen coodinates. //! Returns a 3d ray which would go through the 2d screen coodinates.
core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates( core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates(
core::position2d<s32> pos, ICameraSceneNode* camera) const core::position2d<s32> & pos, ICameraSceneNode* camera)
{ {
core::line3d<f32> ln(0,0,0,0,0,0); core::line3d<f32> ln(0,0,0,0,0,0);
...@@ -765,7 +766,7 @@ core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates( ...@@ -765,7 +766,7 @@ core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates(
//! Calculates 2d screen position from a 3d position. //! Calculates 2d screen position from a 3d position.
core::position2d<s32> CSceneCollisionManager::getScreenCoordinatesFrom3DPosition( core::position2d<s32> CSceneCollisionManager::getScreenCoordinatesFrom3DPosition(
core::vector3df pos3d, ICameraSceneNode* camera) const core::vector3df & pos3d, ICameraSceneNode* camera)
{ {
if (!SceneManager || !Driver) if (!SceneManager || !Driver)
return core::position2d<s32>(-1000,-1000); return core::position2d<s32>(-1000,-1000);
......
...@@ -27,12 +27,13 @@ namespace scene ...@@ -27,12 +27,13 @@ namespace scene
//! Returns the scene node, which is currently visible under the overgiven //! Returns the scene node, which is currently visible under the overgiven
//! screencoordinates, viewed from the currently active camera. //! screencoordinates, viewed from the currently active camera.
virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(core::position2d<s32> pos, virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(const core::position2d<s32> & pos,
s32 idBitMask=0, bool bNoDebugObjects = false); s32 idBitMask=0, bool bNoDebugObjects = false);
//! Returns the nearest scene node which collides with a 3d ray and //! Returns the nearest scene node which collides with a 3d ray and
//! which id matches a bitmask. //! which id matches a bitmask.
virtual ISceneNode* getSceneNodeFromRayBB(core::line3d<f32> ray, s32 idBitMask=0, virtual ISceneNode* getSceneNodeFromRayBB(const core::line3d<f32> & ray,
s32 idBitMask=0,
bool bNoDebugObjects = false); bool bNoDebugObjects = false);
//! Returns the scene node, at which the overgiven camera is looking at and //! Returns the scene node, at which the overgiven camera is looking at and
...@@ -49,7 +50,8 @@ namespace scene ...@@ -49,7 +50,8 @@ namespace scene
//! the resulting new position of the ellipsoid. //! the resulting new position of the ellipsoid.
virtual core::vector3df getCollisionResultPosition( virtual core::vector3df getCollisionResultPosition(
ITriangleSelector* selector, ITriangleSelector* selector,
const core::vector3df &ellipsoidPosition, const core::vector3df& ellipsoidRadius, const core::vector3df &ellipsoidPosition,
const core::vector3df& ellipsoidRadius,
const core::vector3df& ellipsoidDirectionAndSpeed, const core::vector3df& ellipsoidDirectionAndSpeed,
core::triangle3df& triout, core::triangle3df& triout,
core::vector3df& hitPosition, core::vector3df& hitPosition,
...@@ -59,17 +61,17 @@ namespace scene ...@@ -59,17 +61,17 @@ namespace scene
//! Returns a 3d ray which would go through the 2d screen coodinates. //! Returns a 3d ray which would go through the 2d screen coodinates.
virtual core::line3d<f32> getRayFromScreenCoordinates( virtual core::line3d<f32> getRayFromScreenCoordinates(
core::position2d<s32> pos, ICameraSceneNode* camera = 0); const core::position2d<s32> & pos, ICameraSceneNode* camera = 0);
//! Calculates 2d screen position from a 3d position. //! Calculates 2d screen position from a 3d position.
virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition( virtual core::position2d<s32> getScreenCoordinatesFrom3DPosition(
core::vector3df pos, ICameraSceneNode* camera=0); const core::vector3df & pos, ICameraSceneNode* camera=0);
private: private:
//! recursive method for going through all scene nodes //! recursive method for going through all scene nodes
void getPickedNodeBB(ISceneNode* root, void getPickedNodeBB(ISceneNode* root,
const core::line3df& ray, core::line3df& ray,
s32 bits, s32 bits,
bool bNoDebugObjects, bool bNoDebugObjects,
f32& outbestdistance, f32& outbestdistance,
......
Test suite pass at GMT Tue Jan 06 15:45:40 2009 Test suite pass at GMT Tue Jan 06 15:57:25 2009
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