1
#ifndef _PagingLandScapeOcclusionSorterH
2
#define _PagingLandScapeOcclusionSorterH
4
#include "OgrePagingLandScapePrerequisites.h"
5
#include "OgrePagingLandScapeOcclusionElement.h"
10
//comparator for priority queue
11
class FrontToBackNodeSorterOperator
15
FrontToBackNodeSorterOperator(const Vector3& position) : pos(position) {};
16
//-----------------------------------------------------------------------
17
inline bool operator()(OcclusionElement*& a, OcclusionElement*& b) const
19
// could check if both distance == 0 then order visible first// ?
20
return vectorToBoxDistance (*a, pos) > vectorToBoxDistance (*b, pos);
22
//-----------------------------------------------------------------------
23
inline bool operator()(const OcclusionElement*& a, const OcclusionElement*& b) const
25
// could check if both distance == 0 then order visible first ?
26
return vectorToBoxDistance (*a, pos) > vectorToBoxDistance (*b, pos);
28
//-----------------------------------------------------------------------
29
Real vectorToBoxDistance(const OcclusionElement &a, const Vector3& point) const
31
const Vector3 &boxMin = a.getCullBoundingBox ().getMinimum ();
32
const Vector3 halfSize ((a.getCullBoundingBox ().getMaximum () - boxMin) * 0.5);
33
// work in the box's coordinate system
34
const Vector3 kDiff (point - (halfSize + boxMin));
35
// compute squared distance and closest point on box
36
Real fSqrDistance (0.0);
37
for (unsigned int i = 0; i < 3; i++)
39
const Real kClosest = kDiff[i];
40
const Real khalfSize = halfSize[i];
41
if (kClosest < -khalfSize)
43
const Real fDelta = kClosest + khalfSize;
44
fSqrDistance += fDelta * fDelta;
46
else if (kClosest > khalfSize)
48
const Real fDelta = kClosest - khalfSize;
49
fSqrDistance += fDelta * fDelta;
60
#endif //_PagingLandScapeOcclusionSorterH