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