]> git.mxchange.org Git - flightgear.git/blob - Scenery/tile.hxx
Converted fgFLIGHT to a class.
[flightgear.git] / 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 // (Log is kept at end of this file)
23
24
25 #ifndef _TILE_HXX
26 #define _TILE_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42 #include <XGL/xgl.h>
43
44 #include <vector>
45 #include <string>
46
47 #include "Include/compiler.h"
48 #include STL_FUNCTIONAL
49 #include STL_ALGORITHM
50 FG_USING_NAMESPACE(std);
51 // FG_USING_STD(string);
52 // FG_USING_STD(vector);
53
54 #include <Bucket/bucketutils.h>
55 #include <Math/mat3.h>
56 #include <Math/point3d.hxx>
57 #include <Objects/fragment.hxx>
58
59
60 // Scenery tile class
61 class fgTILE {
62
63 public:
64
65     typedef vector < fgFRAGMENT > container;
66     typedef container::iterator FragmentIterator;
67     typedef container::const_iterator FragmentConstIterator;
68
69 public:
70     // node list (the per fragment face lists reference this node list)
71     double (*nodes)[3];
72     int ncount;
73
74     // culling data for whole tile (course grain culling)
75     Point3D center;
76     double bounding_radius;
77     Point3D offset;
78     GLdouble model_view[16];
79
80     // this tile's official location in the world
81     fgBUCKET tile_bucket;
82
83     // the tile cache will mark here if the tile is being used
84     bool used;
85
86     container fragment_list;
87
88 public:
89
90     FragmentIterator begin() { return fragment_list.begin(); }
91     FragmentConstIterator begin() const { return fragment_list.begin(); }
92
93     FragmentIterator end() { return fragment_list.end(); }
94     FragmentConstIterator end() const { return fragment_list.end(); }
95
96     void add_fragment( fgFRAGMENT& frag ) {
97         frag.tile_ptr = this;
98         fragment_list.push_back( frag );
99     }
100
101     //
102     size_t num_fragments() const {
103         return fragment_list.size();
104     }
105
106     // Step through the fragment list, deleting the display list, then
107     // the fragment, until the list is empty.
108     void release_fragments();
109
110 //     int ObjLoad( const string& path, const fgBUCKET& p );
111
112     // Constructor
113     fgTILE ( void );
114
115     // Destructor
116     ~fgTILE ( void );
117
118     // Calculate this tile's offset
119     void SetOffset( const Point3D& off)
120     {
121         offset = center - off;
122     }
123
124
125     // Calculate the model_view transformation matrix for this tile
126     inline void
127     UpdateViewMatrix(GLdouble *MODEL_VIEW)
128     {
129
130 #if defined( USE_MEM ) || defined( WIN32 )
131         memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
132 #else 
133         bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
134 #endif
135         
136         // This is equivalent to doing a glTranslatef(x, y, z);
137         model_view[12] += (model_view[0]*offset.x() +
138                            model_view[4]*offset.y() +
139                            model_view[8]*offset.z());
140         model_view[13] += (model_view[1]*offset.x() +
141                            model_view[5]*offset.y() +
142                            model_view[9]*offset.z());
143         model_view[14] += (model_view[2]*offset.x() +
144                            model_view[6]*offset.y() +
145                            model_view[10]*offset.z() );
146         // m[15] += (m[3]*x + m[7]*y + m[11]*z);
147         // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
148         // so m[15] is unchanged
149     }
150
151 private:
152
153     // not defined
154     fgTILE( const fgTILE& );
155     fgTILE& operator = ( const fgTILE& );
156 };
157
158
159 #endif // _TILE_HXX 
160
161
162 // $Log$
163 // Revision 1.22  1998/12/03 01:18:16  curt
164 // Converted fgFLIGHT to a class.
165 // Tweaks for Sun Portability.
166 // Tweaked current terrain elevation code as per NHV.
167 //
168 // Revision 1.21  1998/11/09 23:40:47  curt
169 // Bernie Bright <bbright@c031.aone.net.au> writes:
170 // I've made some changes to the Scenery handling.  Basically just tidy ups.
171 // The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
172 // vector<fgFRAGMENT>.  Studying our usage patterns this seems reasonable.
173 // Lists are good if you need to insert/delete elements randomly but we
174 // don't do that.  All access seems to be sequential.  Two additional
175 // benefits are smaller memory usage - each list element requires pointers
176 // to the next and previous elements, and faster access - vector iterators
177 // are smaller and faster than list iterators.  This should also help
178 // Charlie Hotchkiss' problem when compiling with Borland and STLport.
179 //
180 // ./Lib/Bucket/bucketutils.hxx
181 //   Convenience functions for fgBUCKET.
182 //
183 // ./Simulator/Scenery/tile.cxx
184 // ./Simulator/Scenery/tile.hxx
185 //   Changed fragment list to a vector.
186 //   Added some convenience member functions.
187 //
188 // ./Simulator/Scenery/tilecache.cxx
189 // ./Simulator/Scenery/tilecache.hxx
190 //   use const fgBUCKET& instead of fgBUCKET* where appropriate.
191 //
192 // ./Simulator/Scenery/tilemgr.cxx
193 // ./Simulator/Scenery/tilemgr.hxx
194 //   uses all the new convenience functions.
195 //
196 // Revision 1.20  1998/10/16 00:55:46  curt
197 // Converted to Point3D class.
198 //
199 // Revision 1.19  1998/09/17 18:36:17  curt
200 // Tweaks and optimizations by Norman Vine.
201 //
202 // Revision 1.18  1998/08/25 16:52:42  curt
203 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
204 //   ../Objects
205 //
206 // Revision 1.17  1998/08/22  14:49:58  curt
207 // Attempting to iron out seg faults and crashes.
208 // Did some shuffling to fix a initialization order problem between view
209 // position, scenery elevation.
210 //
211 // Revision 1.16  1998/08/22 02:01:34  curt
212 // increased fragment list size.
213 //
214 // Revision 1.15  1998/08/20 15:12:06  curt
215 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
216 // the need for "void" pointers and casts.
217 // Quick hack to count the number of scenery polygons that are being drawn.
218 //
219 // Revision 1.14  1998/08/12 21:13:06  curt
220 // material.cxx: don't load textures if they are disabled
221 // obj.cxx: optimizations from Norman Vine
222 // tile.cxx: minor tweaks
223 // tile.hxx: addition of num_faces
224 // tilemgr.cxx: minor tweaks
225 //
226 // Revision 1.13  1998/07/24 21:42:08  curt
227 // material.cxx: whups, double method declaration with no definition.
228 // obj.cxx: tweaks to avoid errors in SGI's CC.
229 // tile.cxx: optimizations by Norman Vine.
230 // tilemgr.cxx: optimizations by Norman Vine.
231 //
232 // Revision 1.12  1998/07/22 21:41:42  curt
233 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
234 // intersect optimization from Norman Vine.
235 //
236 // Revision 1.11  1998/07/12 03:18:28  curt
237 // Added ground collision detection.  This involved:
238 // - saving the entire vertex list for each tile with the tile records.
239 // - saving the face list for each fragment with the fragment records.
240 // - code to intersect the current vertical line with the proper face in
241 //   an efficient manner as possible.
242 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
243 //
244 // Revision 1.10  1998/07/08 14:47:22  curt
245 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
246 // polare3d.h renamed to polar3d.hxx
247 // fg{Cartesian,Polar}Point3d consolodated.
248 // Added some initial support for calculating local current ground elevation.
249 //
250 // Revision 1.9  1998/07/06 21:34:34  curt
251 // Added using namespace std for compilers that support this.
252 //
253 // Revision 1.8  1998/07/04 00:54:30  curt
254 // Added automatic mipmap generation.
255 //
256 // When rendering fragments, use saved model view matrix from associated tile
257 // rather than recalculating it with push() translate() pop().
258 //
259 // Revision 1.7  1998/06/12 00:58:05  curt
260 // Build only static libraries.
261 // Declare memmove/memset for Sloaris.
262 //
263 // Revision 1.6  1998/06/08 17:57:54  curt
264 // Working first pass at material proporty sorting.
265 //
266 // Revision 1.5  1998/06/06 01:09:32  curt
267 // I goofed on the log message in the last commit ... now fixed.
268 //
269 // Revision 1.4  1998/06/06 01:07:18  curt
270 // Increased per material fragment list size from 100 to 400.
271 // Now correctly draw viewable fragments in per material order.
272 //
273 // Revision 1.3  1998/06/05 22:39:54  curt
274 // Working on sorting by, and rendering by material properties.
275 //
276 // Revision 1.2  1998/06/03 00:47:50  curt
277 // No .h for STL includes.
278 // Minor view culling optimizations.
279 //
280 // Revision 1.1  1998/05/23 14:09:21  curt
281 // Added tile.cxx and tile.hxx.
282 // Working on rewriting the tile management system so a tile is just a list
283 // fragments, and the fragment record contains the display list for that fragment.
284 //