]> git.mxchange.org Git - flightgear.git/blob - Simulator/Scenery/tile.hxx
Removed in-src cvs logs.
[flightgear.git] / Simulator / Scenery / tile.hxx
1 // tile.hxx -- routines to handle a scenery tile
2 //
3 // Written by Curtis Olson, started May 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifndef _TILE_HXX
25 #define _TILE_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #ifdef HAVE_WINDOWS_H
37 #  include <windows.h>
38 #endif
39
40 #include <GL/glut.h>
41 #include <XGL/xgl.h>
42
43 #include <Include/compiler.h>
44
45 #include <vector>
46 #include STL_STRING
47
48 #include <Bucket/newbucket.hxx>
49 #include <Math/mat3.h>
50 #include <Math/point3d.hxx>
51 #include <Objects/fragment.hxx>
52
53 #ifdef FG_HAVE_NATIVE_SGI_COMPILERS
54 #include <strings.h>
55 #endif
56
57 FG_USING_STD(string);
58 FG_USING_STD(vector);
59
60
61 // Scenery tile class
62 class fgTILE {
63
64 public:
65
66     typedef vector < fgFRAGMENT > container;
67     typedef container::iterator FragmentIterator;
68     typedef container::const_iterator FragmentConstIterator;
69
70 public:
71     // node list (the per fragment face lists reference this node list)
72     double (*nodes)[3];
73     int ncount;
74
75     // culling data for whole tile (course grain culling)
76     Point3D center;
77     double bounding_radius;
78     Point3D offset;
79     GLdouble model_view[16];
80
81     // this tile's official location in the world
82     FGBucket tile_bucket;
83
84     // the tile cache will mark here if the tile is being used
85     bool used;
86
87     container fragment_list;
88
89 public:
90
91     FragmentIterator begin() { return fragment_list.begin(); }
92     FragmentConstIterator begin() const { return fragment_list.begin(); }
93
94     FragmentIterator end() { return fragment_list.end(); }
95     FragmentConstIterator end() const { return fragment_list.end(); }
96
97     void add_fragment( fgFRAGMENT& frag ) {
98         frag.tile_ptr = this;
99         fragment_list.push_back( frag );
100     }
101
102     //
103     size_t num_fragments() const {
104         return fragment_list.size();
105     }
106
107     // Step through the fragment list, deleting the display list, then
108     // the fragment, until the list is empty.
109     void release_fragments();
110
111 //     int ObjLoad( const string& path, const fgBUCKET& p );
112
113     // Constructor
114     fgTILE ( void );
115
116     // Destructor
117     ~fgTILE ( void );
118
119     // Calculate this tile's offset
120     void SetOffset( const Point3D& off)
121     {
122         offset = center - off;
123     }
124
125
126     // Calculate the model_view transformation matrix for this tile
127     inline void
128     UpdateViewMatrix(GLdouble *MODEL_VIEW)
129     {
130
131 #if defined( USE_MEM ) || defined( WIN32 )
132         memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
133 #else 
134         bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
135 #endif
136         
137         // This is equivalent to doing a glTranslatef(x, y, z);
138         model_view[12] += (model_view[0]*offset.x() +
139                            model_view[4]*offset.y() +
140                            model_view[8]*offset.z());
141         model_view[13] += (model_view[1]*offset.x() +
142                            model_view[5]*offset.y() +
143                            model_view[9]*offset.z());
144         model_view[14] += (model_view[2]*offset.x() +
145                            model_view[6]*offset.y() +
146                            model_view[10]*offset.z() );
147         // m[15] += (m[3]*x + m[7]*y + m[11]*z);
148         // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
149         // so m[15] is unchanged
150     }
151
152 private:
153
154     // not defined
155     fgTILE( const fgTILE& );
156     fgTILE& operator = ( const fgTILE& );
157 };
158
159
160 #endif // _TILE_HXX 
161
162