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
...@@ -43,8 +43,7 @@ namespace scene ...@@ -43,8 +43,7 @@ namespace scene
\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,12 +70,9 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromRayBB(const core::line3d<f32 ...@@ -74,12 +70,9 @@ 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();
...@@ -202,7 +195,7 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root, ...@@ -202,7 +195,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)
ray.end = ray.start + (rayVector * sqrtf(outbestdistance)); ray.end = ray.start + (rayVector * sqrtf(outbestdistance));
} }
} }
...@@ -251,19 +244,13 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay( ...@@ -251,19 +244,13 @@ ISceneNode* CSceneCollisionManager::getSceneNodeAndCollisionPointFromRay(
// 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,
...@@ -303,8 +290,7 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector( ...@@ -303,8 +290,7 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector(
// 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();
...@@ -319,14 +305,9 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector( ...@@ -319,14 +305,9 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector(
} }
} }
getPickedNodeFromBBAndSelector(current, getPickedNodeFromBBAndSelector(current, ray, bits, noDebugObjects,
ray, outBestDistanceSquared, outBestNode,
bits, outBestCollisionPoint, outBestTriangle);
noDebugObjects,
outBestDistanceSquared,
outBestNode,
outBestCollisionPoint,
outBestTriangle);
} }
} }
...@@ -339,17 +320,15 @@ ISceneNode* CSceneCollisionManager::getSceneNodeFromCameraBB( ...@@ -339,17 +320,15 @@ 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,
...@@ -419,7 +398,6 @@ bool CSceneCollisionManager::getCollisionPoint(const core::line3d<f32>& ray, ...@@ -419,7 +398,6 @@ 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(
...@@ -687,7 +665,6 @@ bool CSceneCollisionManager::testTriangleIntersection(SCollisionData* colData, ...@@ -687,7 +665,6 @@ 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(
...@@ -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)
{ {
...@@ -786,8 +764,7 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth, ...@@ -786,8 +764,7 @@ core::vector3df CSceneCollisionManager::collideWithWorld(s32 recursionDepth,
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"
...@@ -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,
...@@ -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,
s32 bits,
bool bNoDebugObjects, bool bNoDebugObjects,
f32& outbestdistance, f32& outbestdistance, ISceneNode*& outbestnode);
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,
......
...@@ -1161,7 +1161,7 @@ u32 CSceneManager::registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDE ...@@ -1161,7 +1161,7 @@ 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;
...@@ -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