~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/include/OgrePagingLandScapeOcclusionSorter.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _PagingLandScapeOcclusionSorterH
 
2
#define _PagingLandScapeOcclusionSorterH
 
3
 
 
4
#include "OgrePagingLandScapePrerequisites.h"
 
5
#include "OgrePagingLandScapeOcclusionElement.h"
 
6
 
 
7
namespace Ogre
 
8
{
 
9
   
 
10
    //comparator for priority queue
 
11
    class FrontToBackNodeSorterOperator 
 
12
    {
 
13
 
 
14
            public:
 
15
                        FrontToBackNodeSorterOperator(const Vector3& position) :   pos(position) {};
 
16
                        //-----------------------------------------------------------------------
 
17
                    inline bool operator()(OcclusionElement*& a, OcclusionElement*& b) const 
 
18
            {
 
19
                // could check if both distance == 0 then order visible first// ?
 
20
                        return vectorToBoxDistance (*a, pos) > vectorToBoxDistance (*b, pos);
 
21
                        }       
 
22
                        //-----------------------------------------------------------------------
 
23
                        inline bool operator()(const OcclusionElement*& a, const OcclusionElement*& b) const 
 
24
                        {
 
25
                                // could check if both distance == 0 then order visible first ?
 
26
                                return vectorToBoxDistance (*a, pos) > vectorToBoxDistance (*b, pos);
 
27
                        }       
 
28
                        //-----------------------------------------------------------------------
 
29
            Real vectorToBoxDistance(const OcclusionElement &a, const Vector3& point)  const
 
30
                {
 
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++)
 
38
                {
 
39
                    const Real kClosest = kDiff[i];
 
40
                    const Real khalfSize = halfSize[i];
 
41
                    if (kClosest < -khalfSize)
 
42
                    {
 
43
                        const Real fDelta = kClosest + khalfSize;
 
44
                        fSqrDistance += fDelta * fDelta;
 
45
                    }
 
46
                    else if (kClosest > khalfSize)
 
47
                    {
 
48
                        const Real fDelta = kClosest - khalfSize;
 
49
                        fSqrDistance += fDelta * fDelta;
 
50
                    }
 
51
                }
 
52
                return fSqrDistance;
 
53
            }
 
54
 
 
55
        private:
 
56
                    const Vector3 pos;
 
57
    };
 
58
}//namespace Ogre
 
59
 
 
60
#endif //_PagingLandScapeOcclusionSorterH