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