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