You need to sign in or sign up before continuing.
Commit ca07a704 authored by hybrid's avatar hybrid

Constification for line3df paramater and reindentation.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2308 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c2d6da34
...@@ -42,9 +42,8 @@ namespace scene ...@@ -42,9 +42,8 @@ namespace scene
the scene node associated with the triangle that was hit. 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, core::triangle3df& outTriangle, const ISceneNode*& outNode) =0;
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
...@@ -132,8 +131,8 @@ namespace scene ...@@ -132,8 +131,8 @@ namespace scene
\return Returns the scene node nearest to ray.start, which collides with the \return Returns the scene node nearest to ray.start, which collides with the
ray and matches the idBitMask, if the mask is not null. If no scene ray and matches the idBitMask, if the mask is not null. If no scene
node is found, 0 is returned. */ node is found, 0 is returned. */
virtual ISceneNode* getSceneNodeFromRayBB(const 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 given camera is looking at and whose id matches the bitmask. //! Get the scene node, which the given camera is looking at and whose id matches the bitmask.
/** A ray is simply casted from the position of the camera to /** A ray is simply casted from the position of the camera to
......
...@@ -30,7 +30,6 @@ CSceneCollisionManager::CSceneCollisionManager(ISceneManager* smanager, video::I ...@@ -30,7 +30,6 @@ CSceneCollisionManager::CSceneCollisionManager(ISceneManager* smanager, video::I
} }
//! destructor //! destructor
CSceneCollisionManager::~CSceneCollisionManager() CSceneCollisionManager::~CSceneCollisionManager()
{ {
...@@ -39,13 +38,12 @@ CSceneCollisionManager::~CSceneCollisionManager() ...@@ -39,13 +38,12 @@ 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(
const core::position2d<s32> & pos, s32 idBitMask, bool bNoDebugObjects) const core::position2d<s32> & pos, s32 idBitMask, bool bNoDebugObjects)
{ {
core::line3d<f32> ln = getRayFromScreenCoordinates(pos, 0); const core::line3d<f32> ln = getRayFromScreenCoordinates(pos, 0);
if ( ln.start == ln.end ) if ( ln.start == ln.end )
return 0; return 0;
...@@ -54,12 +52,10 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromScreenCoordinatesBB( ...@@ -54,12 +52,10 @@ 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(const 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;
...@@ -74,143 +70,140 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(const core::line3d<f32 ...@@ -74,143 +70,140 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(const core::line3d<f32
//! 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, core::line3df& ray,
core::line3df& ray, s32 bits, bool bNoDebugObjects,
s32 bits, f32& outbestdistance, ISceneNode*& outbestnode)
bool bNoDebugObjects,
f32& outbestdistance,
ISceneNode*& outbestnode)
{ {
const core::list<ISceneNode*>& children = root->getChildren(); const core::list<ISceneNode*>& children = root->getChildren();
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();
for (; it != children.end(); ++it) for (; it != children.end(); ++it)
{ {
ISceneNode* current = *it; ISceneNode* current = *it;
if (current->isVisible()) if (current->isVisible())
{ {
if((bNoDebugObjects ? !current->isDebugObject() : true) && if((bNoDebugObjects ? !current->isDebugObject() : true) &&
(bits==0 || (bits != 0 && (current->getID() & bits)))) (bits==0 || (bits != 0 && (current->getID() & bits))))
{ {
// get world to object space transform // get world to object space transform
core::matrix4 worldToObject; core::matrix4 worldToObject;
if (!current->getAbsoluteTransformation().getInverse(worldToObject)) if (!current->getAbsoluteTransformation().getInverse(worldToObject))
continue; continue;
// transform vector from world space to object space // transform vector from world space to object space
core::line3df objectRay(ray); core::line3df objectRay(ray);
worldToObject.transformVect(objectRay.start); worldToObject.transformVect(objectRay.start);
worldToObject.transformVect(objectRay.end); worldToObject.transformVect(objectRay.end);
const core::aabbox3df & objectBox = current->getBoundingBox(); const core::aabbox3df & objectBox = current->getBoundingBox();
// Do the initial intersection test in object space, since the // Do the initial intersection test in object space, since the
// object space box test is more accurate. // object space box test is more accurate.
if(objectBox.isPointInside(objectRay.start)) if(objectBox.isPointInside(objectRay.start))
{
// If the line starts inside the box, then consider the distance as being
// to the centre of the box.
const f32 toIntersectionSq = objectRay.start.getDistanceFromSQ(objectBox.getCenter());
if(toIntersectionSq < outbestdistance)
{ {
outbestdistance = toIntersectionSq; // If the line starts inside the box, then consider the distance as being
outbestnode = current; // to the centre of the box.
const f32 toIntersectionSq = objectRay.start.getDistanceFromSQ(objectBox.getCenter());
if(toIntersectionSq < outbestdistance)
{
outbestdistance = toIntersectionSq;
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.
ray.end = ray.start + (rayVector * sqrtf(toIntersectionSq)); ray.end = ray.start + (rayVector * sqrtf(toIntersectionSq));
}
} }
} else if (objectBox.intersectsWithLine(objectRay))
else if (objectBox.intersectsWithLine(objectRay))
{
// Now transform into world space, since we need to use world space
// scales and distances.
core::aabbox3df worldBox(objectBox);
current->getAbsoluteTransformation().transformBox(worldBox);
core::vector3df edges[8];
worldBox.getEdges(edges);
/* We need to check against each of 6 faces, composed of these corners:
/3--------/7
/ | / |
/ | / |
1---------5 |
| 2- - -| -6
| / | /
|/ | /
0---------4/
Note that we define them as opposite pairs of faces.
*/
static const s32 faceEdges[6][3] =
{ {
{ 0, 1, 5 }, // Front // Now transform into world space, since we need to use world space
{ 6, 7, 3 }, // Back // scales and distances.
{ 2, 3, 1 }, // Left core::aabbox3df worldBox(objectBox);
{ 4, 5, 7 }, // Right current->getAbsoluteTransformation().transformBox(worldBox);
{ 1, 3, 7 }, // Top
{ 2, 0, 4 } // Bottom core::vector3df edges[8];
}; worldBox.getEdges(edges);
core::vector3df intersection; /* We need to check against each of 6 faces, composed of these corners:
core::plane3df facePlane; /3--------/7
/ | / |
bool gotHit = false; / | / |
for(s32 face = 0; face < 6 && !gotHit; ++face) 1---------5 |
{ | 2- - -| -6
facePlane.setPlane(edges[faceEdges[face][0]], | / | /
edges[faceEdges[face][1]], |/ | /
edges[faceEdges[face][2]]); 0---------4/
// Only consider lines that might be entering through this face, since we Note that we define them as opposite pairs of faces.
// already know that the start point is outside the box. */
if(facePlane.classifyPointRelation(ray.start) != core::ISREL3D_FRONT) static const s32 faceEdges[6][3] =
continue; {
{ 0, 1, 5 }, // Front
// Don't bother using a limited ray, since we already know that it should be long { 6, 7, 3 }, // Back
// enough to intersect with the box. { 2, 3, 1 }, // Left
if(facePlane.getIntersectionWithLine(ray.start, rayVector, intersection)) { 4, 5, 7 }, // Right
{ 1, 3, 7 }, // Top
{ 2, 0, 4 } // Bottom
};
core::vector3df intersection;
core::plane3df facePlane;
bool gotHit = false;
for(s32 face = 0; face < 6 && !gotHit; ++face)
{ {
const f32 toIntersectionSq = ray.start.getDistanceFromSQ(intersection); facePlane.setPlane(edges[faceEdges[face][0]],
if(toIntersectionSq < outbestdistance) edges[faceEdges[face][1]],
edges[faceEdges[face][2]]);
// Only consider lines that might be entering through this face, since we
// already know that the start point is outside the box.
if(facePlane.classifyPointRelation(ray.start) != core::ISREL3D_FRONT)
continue;
// Don't bother using a limited ray, since we already know that it should be long
// enough to intersect with the box.
if(facePlane.getIntersectionWithLine(ray.start, rayVector, intersection))
{ {
// We have to check that the intersection with this plane is actually const f32 toIntersectionSq = ray.start.getDistanceFromSQ(intersection);
// on the box, so need to go back to object space again. We also if(toIntersectionSq < outbestdistance)
// need to move the intersection very slightly closer to the centre of
// the box to take into account fp precision losses, since the intersection
// will axiomatically be on the very edge of the box.
worldToObject.transformVect(intersection);
intersection *= 0.99f;
if(objectBox.isPointInside(intersection))
{ {
outbestdistance = toIntersectionSq; // We have to check that the intersection with this plane is actually
outbestnode = current; // on the box, so need to go back to object space again. We also
// need to move the intersection very slightly closer to the centre of
// We can only hit one face, so stop checking now. // the box to take into account fp precision losses, since the intersection
gotHit = true; // will axiomatically be on the very edge of the box.
worldToObject.transformVect(intersection);
intersection *= 0.99f;
if(objectBox.isPointInside(intersection))
{
outbestdistance = toIntersectionSq;
outbestnode = current;
// We can only hit one face, so stop checking now.
gotHit = true;
}
} }
} }
// If the ray could be entering through the first face of a pair, then it can't
// also be entering through the opposite face, and so we can skip that face.
if(0 == (face % 2))
++face;
} }
// If the ray could be entering through the first face of a pair, then it can't // If we got a hit, we can now truncate the ray to stop us hitting further nodes.
// also be entering through the opposite face, and so we can skip that face. if (gotHit)
if(0 == (face % 2)) ray.end = ray.start + (rayVector * sqrtf(outbestdistance));
++face;
} }
}
// If we got a hit, we can now truncate the ray to stop us hitting further nodes. // Only check the children if this node is visible.
if(gotHit) getPickedNodeBB(current, ray, bits, bNoDebugObjects, outbestdistance, outbestnode);
ray.end = ray.start + (rayVector * sqrtf(outbestdistance)); }
} }
}
// Only check the children if this node is visible.
getPickedNodeBB(current, ray, bits, bNoDebugObjects, outbestdistance, outbestnode);
}
}
} }
...@@ -224,14 +217,14 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay( ...@@ -224,14 +217,14 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay(
{ {
ISceneNode* bestNode = 0; ISceneNode* bestNode = 0;
f32 bestDistanceSquared = FLT_MAX; f32 bestDistanceSquared = FLT_MAX;
if(0 == collisionRootNode) if(0 == collisionRootNode)
collisionRootNode = SceneManager->getRootSceneNode(); collisionRootNode = SceneManager->getRootSceneNode();
// We don't try to do anything too clever, like sorting the candidate // We don't try to do anything too clever, like sorting the candidate
// nodes by distance to bounding-box. In the example below, we could do the // nodes by distance to bounding-box. In the example below, we could do the
// triangle collision check with node A first, but we'd have to check node B // triangle collision check with node A first, but we'd have to check node B
// anyway, as the actual collision point could be (and is) closer than the // anyway, as the actual collision point could be (and is) closer than the
// collision point in node A. // collision point in node A.
// //
// ray end // ray end
...@@ -248,22 +241,16 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay( ...@@ -248,22 +241,16 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay(
// ray start // ray start
// //
// We therefore have to do a full BB and triangle collision on every scene // We therefore have to do a full BB and triangle collision on every scene
// node in order to find the nearest collision point, so sorting them by // node in order to find the nearest collision point, so sorting them by
// bounding box would be pointless. // bounding box would be pointless.
getPickedNodeFromBBAndSelector(collisionRootNode, getPickedNodeFromBBAndSelector(collisionRootNode, ray, idBitMask,
ray, noDebugObjects, bestDistanceSquared, bestNode,
idBitMask, outCollisionPoint, outTriangle);
noDebugObjects,
bestDistanceSquared,
bestNode,
outCollisionPoint,
outTriangle);
return bestNode; return bestNode;
} }
void CSceneCollisionManager::getPickedNodeFromBBAndSelector( void CSceneCollisionManager::getPickedNodeFromBBAndSelector(
ISceneNode * root, ISceneNode * root,
const core::line3df & ray, const core::line3df & ray,
...@@ -274,60 +261,54 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector( ...@@ -274,60 +261,54 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector(
core::vector3df & outBestCollisionPoint, core::vector3df & outBestCollisionPoint,
core::triangle3df & outBestTriangle) core::triangle3df & outBestTriangle)
{ {
const core::list<ISceneNode*>& children = root->getChildren(); const core::list<ISceneNode*>& children = root->getChildren();
core::list<ISceneNode*>::ConstIterator it = children.begin(); core::list<ISceneNode*>::ConstIterator it = children.begin();
for (; it != children.end(); ++it) for (; it != children.end(); ++it)
{ {
ISceneNode* current = *it; ISceneNode* current = *it;
ITriangleSelector * selector = current->getTriangleSelector(); ITriangleSelector * selector = current->getTriangleSelector();
if (selector && current->isVisible() && if (selector && current->isVisible() &&
(noDebugObjects ? !current->isDebugObject() : true) && (noDebugObjects ? !current->isDebugObject() : true) &&
(bits==0 || (bits != 0 && (current->getID() & bits)))) (bits==0 || (bits != 0 && (current->getID() & bits))))
{ {
// get world to object space transform // get world to object space transform
core::matrix4 mat; core::matrix4 mat;
if (!current->getAbsoluteTransformation().getInverse(mat)) if (!current->getAbsoluteTransformation().getInverse(mat))
continue; continue;
// transform vector from world space to object space // transform vector from world space to object space
core::line3df line(ray); core::line3df line(ray);
mat.transformVect(line.start); mat.transformVect(line.start);
mat.transformVect(line.end); mat.transformVect(line.end);
const core::aabbox3df& box = current->getBoundingBox(); const core::aabbox3df& box = current->getBoundingBox();
core::vector3df candidateCollisionPoint; core::vector3df candidateCollisionPoint;
core::triangle3df candidateTriangle; core::triangle3df candidateTriangle;
// do intersection test in object space // do intersection test in object space
const ISceneNode * hitNode = 0; const ISceneNode * hitNode = 0;
if (box.intersectsWithLine(line) if (box.intersectsWithLine(line) &&
&& getCollisionPoint(ray, selector, candidateCollisionPoint, candidateTriangle, hitNode))
getCollisionPoint(ray, selector, candidateCollisionPoint, candidateTriangle, hitNode)) {
{ const f32 distanceSquared = (candidateCollisionPoint - ray.start).getLengthSQ();
const f32 distanceSquared = (candidateCollisionPoint - ray.start).getLengthSQ();
if(distanceSquared < outBestDistanceSquared)
if(distanceSquared < outBestDistanceSquared) {
{ outBestDistanceSquared = distanceSquared;
outBestDistanceSquared = distanceSquared; outBestNode = current;
outBestNode = current; outBestCollisionPoint = candidateCollisionPoint;
outBestCollisionPoint = candidateCollisionPoint; outBestTriangle = candidateTriangle;
outBestTriangle = candidateTriangle; }
} }
} }
}
getPickedNodeFromBBAndSelector(current, ray, bits, noDebugObjects,
getPickedNodeFromBBAndSelector(current, outBestDistanceSquared, outBestNode,
ray, outBestCollisionPoint, outBestTriangle);
bits, }
noDebugObjects,
outBestDistanceSquared,
outBestNode,
outBestCollisionPoint,
outBestTriangle);
}
} }
...@@ -339,22 +320,20 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromCameraBB( ...@@ -339,22 +320,20 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromCameraBB(
if (!camera) if (!camera)
return 0; return 0;
core::vector3df start = camera->getAbsolutePosition(); const core::vector3df start = camera->getAbsolutePosition();
core::vector3df end = camera->getTarget(); core::vector3df end = camera->getTarget();
end = start + ((end - start).normalize() * camera->getFarValue()); end = start + ((end - start).normalize() * camera->getFarValue());
core::line3d<f32> line(start, end);
return getSceneNodeFromRayBB(line, idBitMask, bNoDebugObjects); return getSceneNodeFromRayBB(core::line3d<f32>(start, end), idBitMask, bNoDebugObjects);
} }
//! 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) const ISceneNode*& outNode)
{ {
if (!selector) if (!selector)
{ {
...@@ -419,19 +398,18 @@ bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray, ...@@ -419,19 +398,18 @@ bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray,
} }
//! 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.
core::vector3df CSceneCollisionManager::getCollisionResultPosition( core::vector3df CSceneCollisionManager::getCollisionResultPosition(
ITriangleSelector* selector, ITriangleSelector* selector,
const core::vector3df &position, const core::vector3df& radius, const core::vector3df &position, const core::vector3df& radius,
const core::vector3df& direction, const core::vector3df& direction,
core::triangle3df& triout, core::triangle3df& triout,
core::vector3df& hitPosition, core::vector3df& hitPosition,
bool& outFalling, bool& outFalling,
const ISceneNode*& outNode, const ISceneNode*& outNode,
f32 slidingSpeed, f32 slidingSpeed,
const core::vector3df& gravity) const core::vector3df& gravity)
{ {
return collideEllipsoidWithWorld(selector, position, return collideEllipsoidWithWorld(selector, position,
radius, direction, slidingSpeed, gravity, triout, hitPosition, outFalling, outNode); radius, direction, slidingSpeed, gravity, triout, hitPosition, outFalling, outNode);
...@@ -687,18 +665,17 @@ bool CSceneCollisionManager::testTriangleIntersection(SCollisionData* colData, ...@@ -687,18 +665,17 @@ bool CSceneCollisionManager::testTriangleIntersection(SCollisionData* colData,
} }
//! 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.
core::vector3df CSceneCollisionManager::collideEllipsoidWithWorld( core::vector3df CSceneCollisionManager::collideEllipsoidWithWorld(
ITriangleSelector* selector, const core::vector3df &position, ITriangleSelector* selector, const core::vector3df &position,
const core::vector3df& radius, const core::vector3df& velocity, const core::vector3df& radius, const core::vector3df& velocity,
f32 slidingSpeed, f32 slidingSpeed,
const core::vector3df& gravity, const core::vector3df& gravity,
core::triangle3df& triout, core::triangle3df& triout,
core::vector3df& hitPosition, core::vector3df& hitPosition,
bool& outFalling, bool& outFalling,
const ISceneNode*& outNode) const ISceneNode*& outNode)
{ {
if (!selector || radius.X == 0.0f || radius.Y == 0.0f || radius.Z == 0.0f) if (!selector || radius.X == 0.0f || radius.Y == 0.0f || radius.Z == 0.0f)
return position; return position;
...@@ -756,6 +733,7 @@ core::vector3df CSceneCollisionManager::collideEllipsoidWithWorld( ...@@ -756,6 +733,7 @@ core::vector3df CSceneCollisionManager::collideEllipsoidWithWorld(
return finalPos; return finalPos;
} }
core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth, core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth,
SCollisionData &colData, core::vector3df pos, core::vector3df vel) SCollisionData &colData, core::vector3df pos, core::vector3df vel)
{ {
...@@ -784,10 +762,9 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth, ...@@ -784,10 +762,9 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth,
core::matrix4 scaleMatrix; core::matrix4 scaleMatrix;
scaleMatrix.setScale( scaleMatrix.setScale(
core::vector3df(1.0f / colData.eRadius.X, core::vector3df(1.0f / colData.eRadius.X,
1.0f / colData.eRadius.Y, 1.0f / colData.eRadius.Y,
1.0f / colData.eRadius.Z) 1.0f / colData.eRadius.Z));
);
s32 triangleCnt = 0; s32 triangleCnt = 0;
colData.selector->getTriangles(Triangles.pointer(), totalTriangleCnt, triangleCnt, box, &scaleMatrix); colData.selector->getTriangles(Triangles.pointer(), totalTriangleCnt, triangleCnt, box, &scaleMatrix);
...@@ -959,4 +936,3 @@ inline bool CSceneCollisionManager::getLowestRoot(f32 a, f32 b, f32 c, f32 maxR, ...@@ -959,4 +936,3 @@ inline bool CSceneCollisionManager::getLowestRoot(f32 a, f32 b, f32 c, f32 maxR,
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
#ifndef __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
#define __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
// Copyright (C) 2002-2009 Nikolaus Gebhardt // Copyright (C) 2002-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
#define __C_SCENE_COLLISION_MANAGER_H_INCLUDED__
#include "ISceneCollisionManager.h" #include "ISceneCollisionManager.h"
#include "ISceneManager.h" #include "ISceneManager.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
...@@ -14,7 +14,7 @@ namespace irr ...@@ -14,7 +14,7 @@ namespace irr
namespace scene namespace scene
{ {
//! The Scene Collision Manager provides methods for performing collision tests and picking on scene nodes. //! The Scene Collision Manager provides methods for performing collision tests and picking on scene nodes.
class CSceneCollisionManager : public ISceneCollisionManager class CSceneCollisionManager : public ISceneCollisionManager
{ {
public: public:
...@@ -25,20 +25,20 @@ namespace scene ...@@ -25,20 +25,20 @@ namespace scene
//! destructor //! destructor
virtual ~CSceneCollisionManager(); virtual ~CSceneCollisionManager();
//! Returns the scene node, which is currently visible under the overgiven //! Returns the scene node, which is currently visible at the given
//! screencoordinates, viewed from the currently active camera. //! screen coordinates, viewed from the currently active camera.
virtual ISceneNode* getSceneNodeFromScreenCoordinatesBB(const 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(const core::line3d<f32> ray, virtual ISceneNode* getSceneNodeFromRayBB(const core::line3d<f32>& ray,
s32 idBitMask=0, bool bNoDebugObjects = false); s32 idBitMask=0, 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
//! which id matches the bitmask. //! which id matches the bitmask.
virtual ISceneNode* getSceneNodeFromCameraBB(ICameraSceneNode* camera, s32 idBitMask=0, virtual ISceneNode* getSceneNodeFromCameraBB(ICameraSceneNode* camera,
bool bNoDebugObjects = false); s32 idBitMask=0, bool bNoDebugObjects = false);
//! 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,
...@@ -47,11 +47,11 @@ namespace scene ...@@ -47,11 +47,11 @@ namespace scene
const ISceneNode* & outNode); 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.
virtual core::vector3df getCollisionResultPosition( virtual core::vector3df getCollisionResultPosition(
ITriangleSelector* selector, ITriangleSelector* selector,
const core::vector3df &ellipsoidPosition, const core::vector3df &ellipsoidPosition,
const core::vector3df& ellipsoidRadius, const core::vector3df& ellipsoidRadius,
const core::vector3df& ellipsoidDirectionAndSpeed, const core::vector3df& ellipsoidDirectionAndSpeed,
core::triangle3df& triout, core::triangle3df& triout,
core::vector3df& hitPosition, core::vector3df& hitPosition,
...@@ -82,12 +82,9 @@ namespace scene ...@@ -82,12 +82,9 @@ namespace scene
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, core::line3df& ray, s32 bits,
core::line3df& ray, bool bNoDebugObjects,
s32 bits, f32& outbestdistance, ISceneNode*& outbestnode);
bool bNoDebugObjects,
f32& outbestdistance,
ISceneNode*& outbestnode);
//! recursive method for going through all scene nodes //! recursive method for going through all scene nodes
void getPickedNodeFromBBAndSelector(ISceneNode * root, void getPickedNodeFromBBAndSelector(ISceneNode * root,
...@@ -104,7 +101,7 @@ namespace scene ...@@ -104,7 +101,7 @@ namespace scene
{ {
core::vector3df eRadius; core::vector3df eRadius;
core::vector3df R3Velocity; core::vector3df R3Velocity;
core::vector3df R3Position; core::vector3df R3Position;
core::vector3df velocity; core::vector3df velocity;
...@@ -129,11 +126,11 @@ namespace scene ...@@ -129,11 +126,11 @@ namespace scene
\param colData: the collision data. \param colData: the collision data.
\param triangle: the triangle to test against. \param triangle: the triangle to test against.
\return true if the triangle is hit (and is the closest hit), false otherwise */ \return true if the triangle is hit (and is the closest hit), false otherwise */
bool testTriangleIntersection(SCollisionData* colData, bool testTriangleIntersection(SCollisionData* colData,
const core::triangle3df& triangle); const core::triangle3df& triangle);
//! recursive method for doing collision response //! recursive method for doing collision response
core::vector3df collideEllipsoidWithWorld(ITriangleSelector* selector, core::vector3df collideEllipsoidWithWorld(ITriangleSelector* selector,
const core::vector3df &position, const core::vector3df &position,
const core::vector3df& radius, const core::vector3df& velocity, const core::vector3df& radius, const core::vector3df& velocity,
f32 slidingSpeed, f32 slidingSpeed,
...@@ -149,7 +146,7 @@ namespace scene ...@@ -149,7 +146,7 @@ namespace scene
ISceneManager* SceneManager; ISceneManager* SceneManager;
video::IVideoDriver* Driver; video::IVideoDriver* Driver;
core::array<core::triangle3df> Triangles; // triangle buffer core::array<core::triangle3df> Triangles; // triangle buffer
}; };
......
...@@ -1161,8 +1161,8 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE ...@@ -1161,8 +1161,8 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE
switch(time) switch(time)
{ {
// take camera if it doesn't exists // take camera if it is not already registered
case ESNRP_CAMERA: case ESNRP_CAMERA:
{ {
taken = 1; taken = 1;
for ( u32 i = 0; i != CameraList.size(); ++i ) for ( u32 i = 0; i != CameraList.size(); ++i )
...@@ -1177,11 +1177,12 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE ...@@ -1177,11 +1177,12 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE
{ {
CameraList.push_back(node); CameraList.push_back(node);
} }
}break; }
break;
case ESNRP_LIGHT: case ESNRP_LIGHT:
// TODO: Point Light culling.. // TODO: Point Light culling..
// Lighting modell in irrlicht has to be redone.. // Lighting model in irrlicht has to be redone..
//if (!isCulled(node)) //if (!isCulled(node))
{ {
LightList.push_back(static_cast<ILightSceneNode*>(node)); LightList.push_back(static_cast<ILightSceneNode*>(node));
...@@ -1268,6 +1269,7 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE ...@@ -1268,6 +1269,7 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE
return taken; return taken;
} }
//! This method is called just before the rendering process of the whole scene. //! This method is called just before the rendering process of the whole scene.
//! draws all scene nodes //! draws all scene nodes
void CSceneManager::drawAll() void CSceneManager::drawAll()
......
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