~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to render/occlusion.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2002, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Declares the hierarchical occlusion culling class.
 
23
                \author Andy Gill (billybobjimboy@users.sf.net)
 
24
*/
 
25
 
 
26
//? Is .h included already?
 
27
#ifndef OCCLUSION_H_INCLUDED
 
28
#define OCCLUSION_H_INCLUDED 1
 
29
 
 
30
#include "aqsis.h"
 
31
 
 
32
START_NAMESPACE( Aqsis )
 
33
 
 
34
class CqBound;
 
35
class CqBucket;
 
36
 
 
37
 
 
38
class CqOcclusionBox
 
39
{
 
40
public:
 
41
    static void CreateHierarchy( TqInt bucketXSize, TqInt bucketYSize, TqInt XFWidth, TqInt YFWidth );
 
42
    static void DeleteHierarchy();
 
43
    static void SetupHierarchy( CqBucket* bucket, TqInt xMin, TqInt yMin, TqInt xMax, TqInt yMax );
 
44
    static void Update()
 
45
    {
 
46
        UpdateLevel( m_HierarchyLevels - 1 );
 
47
    }
 
48
 
 
49
    static TqBool CanCull( CqBound* bound )
 
50
    {
 
51
        return m_Hierarchy[ 0 ].IsCullable( bound );
 
52
    }
 
53
    static void MarkForUpdate( TqInt id )
 
54
    {
 
55
        assert( id >= 0 && id < m_TotalBoxes );
 
56
        m_Hierarchy[ id ].MarkForUpdate();
 
57
    }
 
58
 
 
59
protected:
 
60
    CqOcclusionBox();
 
61
    ~CqOcclusionBox();
 
62
 
 
63
    void SetupChildren();
 
64
    static void UpdateLevel( TqInt level );
 
65
    TqBool UpdateZValues(); // returns true if we changed anything
 
66
    void Clear();
 
67
 
 
68
    void SetBounds( TqInt x0, TqInt y0, TqInt x1, TqInt y1 );
 
69
    bool Overlaps( CqBound* bound );
 
70
 
 
71
    TqBool IsCullable( CqBound* bound );
 
72
    TqBool NeedsUpdating()
 
73
    {
 
74
        return m_NeedsUpdating;
 
75
    }
 
76
    void MarkForUpdate()
 
77
    {
 
78
        m_NeedsUpdating = TqTrue;
 
79
    }
 
80
 
 
81
    TqInt m_MinX; // pixel positions of box boundary
 
82
    TqInt m_MinY;
 
83
    TqInt m_MaxX;
 
84
    TqInt m_MaxY;
 
85
 
 
86
    TqFloat m_MinZ;
 
87
    TqFloat m_MaxZ;
 
88
 
 
89
    TqInt m_Id;
 
90
 
 
91
    /*
 
92
        m_Hierarchy is a tree but implemented as an array for speed.
 
93
        Each box has exactly 4 children apart from the leaves (obviously).
 
94
        For reference:
 
95
        this = m_Hierarchy[m_Id];
 
96
        parent = m_Hierarchy[m_Id/4]; (integer divide, rounds down)
 
97
        first child = m_Hierarchy[m_Id*4 + 1]; (if we are a leaf this will be >= m_TotalBoxes)
 
98
        next sibling = m_Hierarchy[m_Id + 1];
 
99
    */
 
100
 
 
101
    static CqBucket* m_Bucket;
 
102
    static CqOcclusionBox* m_Hierarchy; // tree of OcclusionBoxes
 
103
    static TqInt m_HierarchyLevels; // the depth of the tree
 
104
    static TqInt m_TotalBoxes;
 
105
    static TqInt* m_LevelStartId; // the id for the start of each level, ie 0,1,5,21... etc
 
106
 
 
107
    TqBool m_NeedsUpdating;
 
108
};
 
109
 
 
110
END_NAMESPACE( Aqsis )
 
111
 
 
112
 
 
113
#endif // OCCLUSION_H_INCLUDED
 
114