aboutsummaryrefslogtreecommitdiff
path: root/src/shared/vmap/TreeNode.h
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:35:07 -0700
committermaximius <none@none>2009-10-17 15:35:07 -0700
commit26b5e033ffde3d161382fc9addbfa99738379641 (patch)
treea344f369ca32945f787a02dee35c3dbe342bed7e /src/shared/vmap/TreeNode.h
parentf21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff)
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
Diffstat (limited to 'src/shared/vmap/TreeNode.h')
-rw-r--r--src/shared/vmap/TreeNode.h34
1 files changed, 0 insertions, 34 deletions
diff --git a/src/shared/vmap/TreeNode.h b/src/shared/vmap/TreeNode.h
index 1b9532001e5..2b14de9ac33 100644
--- a/src/shared/vmap/TreeNode.h
+++ b/src/shared/vmap/TreeNode.h
@@ -17,18 +17,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#ifndef _TREENODE_H
#define _TREENODE_H
-
#include "ShortVector.h"
#include "ShortBox.h"
#include "NodeValueAccess.h"
#include "VMapTools.h"
-
#include <G3D/Vector3.h>
#include <G3D/AABox.h>
-
namespace VMAP
{
/**
@@ -36,9 +32,7 @@ namespace VMAP
It is the node within our static BSP-Trees.
It does not use pointers but indexes to access the values and other nodes.
*/
-
//=====================================================
-
class TreeNode
{
private:
@@ -60,30 +54,19 @@ namespace VMAP
iStartPosition = pStartPosition;
iNumberOfValues = pNValues;
}
-
bool hasChilds() const { return(iChilds[0] >= 0 || iChilds[1] >= 0); }
-
TreeNode const* getChild(TreeNode const* pValueArray, int pNo) const;
// pChildNo = 0 or 1
inline void setChildPos(int pChildNo, int pChildPosInTreeNodeArray) { iChilds[pChildNo] = pChildPosInTreeNodeArray; }
-
inline G3D::Vector3::Axis getSplitAxis() const { return(iSplitAxis); }
-
inline void setSplitAxis(G3D::Vector3::Axis a) { iSplitAxis = a; }
inline void setSplitLocation(float l) { iSplitLocation = l; }
-
inline void setBounds(const G3D::AABox& pBox) { iBounds = pBox; }
-
inline void setBounds(const G3D::Vector3& lo, const G3D::Vector3& hi) { iBounds.set(lo,hi); }
-
inline void getBounds(G3D::AABox& pBox) const { pBox.set(iBounds.low(),iBounds.high()); }
-
inline float getSplitLocation() const { return(iSplitLocation); }
-
inline unsigned short getNValues() const { return (iNumberOfValues); }
-
inline unsigned int getStartPosition() const { return(iStartPosition); }
-
inline bool operator==(const TreeNode& n) const
{
return ((iSplitLocation == n.iSplitLocation) &&
@@ -93,7 +76,6 @@ namespace VMAP
(iBounds == n.iBounds) &&
(iNumberOfValues == n.iNumberOfValues));
}
-
inline bool operator!=(const TreeNode& n) const
{
return !((iSplitLocation == n.iSplitLocation) &&
@@ -103,7 +85,6 @@ namespace VMAP
(iBounds == n.iBounds) &&
(iNumberOfValues == n.iNumberOfValues));
}
-
/** Returns true if the ray intersects this node */
bool intersects(const G3D::Ray& ray, float distance) const {
// See if the ray will ever hit this node or its children
@@ -112,13 +93,10 @@ namespace VMAP
bool rayWillHitBounds =
MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
ray.origin, ray.direction, iBounds, location, alreadyInsideBounds);
-
bool canHitThisNode = (alreadyInsideBounds ||
(rayWillHitBounds && ((location - ray.origin).squaredLength() < (distance*distance))));
-
return canHitThisNode;
}
-
template<typename RayCallback, typename TNode, typename TValue>
void intersectRay(
const G3D::Ray& ray,
@@ -132,7 +110,6 @@ namespace VMAP
// The ray doesn't hit this node, so it can't hit the children of the node.
return;
}
-
// Test for intersection against every object at this node.
for (unsigned int v = iStartPosition; v < (iNumberOfValues+iStartPosition); ++v) {
const TValue& nodeValue = pNodeValueAccess.getValue(v);
@@ -145,11 +122,9 @@ namespace VMAP
bool rayWillHitBounds =
MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
ray.origin, ray.direction, bounds, location, alreadyInsideBounds);
-
canHitThisObject = (alreadyInsideBounds ||
(rayWillHitBounds && ((location - ray.origin).squaredLength() < (distance*distance))));
}
-
if (canHitThisObject) {
// It is possible that this ray hits this object. Look for the intersection using the
// callback.
@@ -158,32 +133,24 @@ namespace VMAP
if(pStopAtFirstHit && distance < enterDistance)
return;
}
-
// There are three cases to consider next:
//
// 1. the ray can start on one side of the splitting plane and never enter the other,
// 2. the ray can start on one side and enter the other, and
// 3. the ray can travel exactly down the splitting plane
-
enum {NONE = -1};
int firstChild = NONE;
int secondChild = NONE;
-
if (ray.origin[iSplitAxis] < iSplitLocation) {
-
// The ray starts on the small side
firstChild = 0;
-
if (ray.direction[iSplitAxis] > 0) {
// The ray will eventually reach the other side
secondChild = 1;
}
-
} else if (ray.origin[iSplitAxis] > iSplitLocation) {
-
// The ray starts on the large side
firstChild = 1;
-
if (ray.direction[iSplitAxis] < 0) {
secondChild = 0;
}
@@ -197,7 +164,6 @@ namespace VMAP
firstChild = 1;
}
}
-
// Test on the side closer to the ray origin.
if ((firstChild != NONE) && iChilds[firstChild]>0) {
getChild(pNodeValueAccess.getNodePtr() , firstChild)->intersectRay(ray, intersectCallback, distance, pNodeValueAccess, pStopAtFirstHit,intersectCallbackIsFast);