]> git.mxchange.org Git - flightgear.git/blob - Simulator/Scenery/tile.hxx
Initial revision
[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 // (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/newbucket.hxx>
50 #include <Math/mat3.h>
51 #include <Math/point3d.hxx>
52 #include <Objects/fragment.hxx>
53
54 #ifdef FG_HAVE_NATIVE_SGI_COMPILERS
55 #include <strings.h>
56 #endif
57
58 FG_USING_STD(string);
59 FG_USING_STD(vector);
60
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.1  1999/04/05 21:32:49  curt
166 // Initial revision
167 //
168 // Revision 1.26  1999/03/25 19:03:25  curt
169 // Converted to use new bucket routines.
170 //
171 // Revision 1.25  1999/03/02 01:03:30  curt
172 // Tweaks for building with native SGI compilers.
173 //
174 // Revision 1.24  1999/02/26 22:10:02  curt
175 // Added initial support for native SGI compilers.
176 //
177 // Revision 1.23  1999/02/02 20:13:41  curt
178 // MSVC++ portability changes by Bernie Bright:
179 //
180 // Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
181 // Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
182 // Simulator/Cockpit/hud.cxx: Added Standard headers
183 // Simulator/Cockpit/panel.cxx: Redefinition of default parameter
184 // Simulator/Flight/flight.cxx: Replaced cout with FG_LOG.  Deleted <stdio.h>
185 // Simulator/Main/fg_init.cxx:
186 // Simulator/Main/GLUTmain.cxx:
187 // Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
188 // Simulator/Objects/material.hxx:
189 // Simulator/Time/timestamp.hxx: VC++ friend kludge
190 // Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
191 // Simulator/Main/views.hxx: Added a constant
192 //
193 // Revision 1.22  1998/12/03 01:18:16  curt
194 // Converted fgFLIGHT to a class.
195 // Tweaks for Sun Portability.
196 // Tweaked current terrain elevation code as per NHV.
197 //
198 // Revision 1.21  1998/11/09 23:40:47  curt
199 // Bernie Bright <bbright@c031.aone.net.au> writes:
200 // I've made some changes to the Scenery handling.  Basically just tidy ups.
201 // The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
202 // vector<fgFRAGMENT>.  Studying our usage patterns this seems reasonable.
203 // Lists are good if you need to insert/delete elements randomly but we
204 // don't do that.  All access seems to be sequential.  Two additional
205 // benefits are smaller memory usage - each list element requires pointers
206 // to the next and previous elements, and faster access - vector iterators
207 // are smaller and faster than list iterators.  This should also help
208 // Charlie Hotchkiss' problem when compiling with Borland and STLport.
209 //
210 // ./Lib/Bucket/bucketutils.hxx
211 //   Convenience functions for fgBUCKET.
212 //
213 // ./Simulator/Scenery/tile.cxx
214 // ./Simulator/Scenery/tile.hxx
215 //   Changed fragment list to a vector.
216 //   Added some convenience member functions.
217 //
218 // ./Simulator/Scenery/tilecache.cxx
219 // ./Simulator/Scenery/tilecache.hxx
220 //   use const fgBUCKET& instead of fgBUCKET* where appropriate.
221 //
222 // ./Simulator/Scenery/tilemgr.cxx
223 // ./Simulator/Scenery/tilemgr.hxx
224 //   uses all the new convenience functions.
225 //
226 // Revision 1.20  1998/10/16 00:55:46  curt
227 // Converted to Point3D class.
228 //
229 // Revision 1.19  1998/09/17 18:36:17  curt
230 // Tweaks and optimizations by Norman Vine.
231 //
232 // Revision 1.18  1998/08/25 16:52:42  curt
233 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
234 //   ../Objects
235 //
236 // Revision 1.17  1998/08/22  14:49:58  curt
237 // Attempting to iron out seg faults and crashes.
238 // Did some shuffling to fix a initialization order problem between view
239 // position, scenery elevation.
240 //
241 // Revision 1.16  1998/08/22 02:01:34  curt
242 // increased fragment list size.
243 //
244 // Revision 1.15  1998/08/20 15:12:06  curt
245 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
246 // the need for "void" pointers and casts.
247 // Quick hack to count the number of scenery polygons that are being drawn.
248 //
249 // Revision 1.14  1998/08/12 21:13:06  curt
250 // material.cxx: don't load textures if they are disabled
251 // obj.cxx: optimizations from Norman Vine
252 // tile.cxx: minor tweaks
253 // tile.hxx: addition of num_faces
254 // tilemgr.cxx: minor tweaks
255 //
256 // Revision 1.13  1998/07/24 21:42:08  curt
257 // material.cxx: whups, double method declaration with no definition.
258 // obj.cxx: tweaks to avoid errors in SGI's CC.
259 // tile.cxx: optimizations by Norman Vine.
260 // tilemgr.cxx: optimizations by Norman Vine.
261 //
262 // Revision 1.12  1998/07/22 21:41:42  curt
263 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
264 // intersect optimization from Norman Vine.
265 //
266 // Revision 1.11  1998/07/12 03:18:28  curt
267 // Added ground collision detection.  This involved:
268 // - saving the entire vertex list for each tile with the tile records.
269 // - saving the face list for each fragment with the fragment records.
270 // - code to intersect the current vertical line with the proper face in
271 //   an efficient manner as possible.
272 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
273 //
274 // Revision 1.10  1998/07/08 14:47:22  curt
275 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
276 // polare3d.h renamed to polar3d.hxx
277 // fg{Cartesian,Polar}Point3d consolodated.
278 // Added some initial support for calculating local current ground elevation.
279 //
280 // Revision 1.9  1998/07/06 21:34:34  curt
281 // Added using namespace std for compilers that support this.
282 //
283 // Revision 1.8  1998/07/04 00:54:30  curt
284 // Added automatic mipmap generation.
285 //
286 // When rendering fragments, use saved model view matrix from associated tile
287 // rather than recalculating it with push() translate() pop().
288 //
289 // Revision 1.7  1998/06/12 00:58:05  curt
290 // Build only static libraries.
291 // Declare memmove/memset for Sloaris.
292 //
293 // Revision 1.6  1998/06/08 17:57:54  curt
294 // Working first pass at material proporty sorting.
295 //
296 // Revision 1.5  1998/06/06 01:09:32  curt
297 // I goofed on the log message in the last commit ... now fixed.
298 //
299 // Revision 1.4  1998/06/06 01:07:18  curt
300 // Increased per material fragment list size from 100 to 400.
301 // Now correctly draw viewable fragments in per material order.
302 //
303 // Revision 1.3  1998/06/05 22:39:54  curt
304 // Working on sorting by, and rendering by material properties.
305 //
306 // Revision 1.2  1998/06/03 00:47:50  curt
307 // No .h for STL includes.
308 // Minor view culling optimizations.
309 //
310 // Revision 1.1  1998/05/23 14:09:21  curt
311 // Added tile.cxx and tile.hxx.
312 // Working on rewriting the tile management system so a tile is just a list
313 // fragments, and the fragment record contains the display list for that fragment.
314 //