1 // tile.hxx -- routines to handle a scenery tile
3 // Written by Curtis Olson, started May 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
22 // (Log is kept at end of this file)
30 # error This library requires C++
44 #include <Include/compiler.h>
49 #include <Bucket/newbucket.hxx>
50 #include <Math/mat3.h>
51 #include <Math/point3d.hxx>
52 #include <Objects/fragment.hxx>
54 #ifdef FG_HAVE_NATIVE_SGI_COMPILERS
67 typedef vector < fgFRAGMENT > container;
68 typedef container::iterator FragmentIterator;
69 typedef container::const_iterator FragmentConstIterator;
72 // node list (the per fragment face lists reference this node list)
76 // culling data for whole tile (course grain culling)
78 double bounding_radius;
80 GLdouble model_view[16];
82 // this tile's official location in the world
85 // the tile cache will mark here if the tile is being used
88 container fragment_list;
92 FragmentIterator begin() { return fragment_list.begin(); }
93 FragmentConstIterator begin() const { return fragment_list.begin(); }
95 FragmentIterator end() { return fragment_list.end(); }
96 FragmentConstIterator end() const { return fragment_list.end(); }
98 void add_fragment( fgFRAGMENT& frag ) {
100 fragment_list.push_back( frag );
104 size_t num_fragments() const {
105 return fragment_list.size();
108 // Step through the fragment list, deleting the display list, then
109 // the fragment, until the list is empty.
110 void release_fragments();
112 // int ObjLoad( const string& path, const fgBUCKET& p );
120 // Calculate this tile's offset
121 void SetOffset( const Point3D& off)
123 offset = center - off;
127 // Calculate the model_view transformation matrix for this tile
129 UpdateViewMatrix(GLdouble *MODEL_VIEW)
132 #if defined( USE_MEM ) || defined( WIN32 )
133 memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
135 bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
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
156 fgTILE( const fgTILE& );
157 fgTILE& operator = ( const fgTILE& );
165 // Revision 1.26 1999/03/25 19:03:25 curt
166 // Converted to use new bucket routines.
168 // Revision 1.25 1999/03/02 01:03:30 curt
169 // Tweaks for building with native SGI compilers.
171 // Revision 1.24 1999/02/26 22:10:02 curt
172 // Added initial support for native SGI compilers.
174 // Revision 1.23 1999/02/02 20:13:41 curt
175 // MSVC++ portability changes by Bernie Bright:
177 // Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
178 // Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
179 // Simulator/Cockpit/hud.cxx: Added Standard headers
180 // Simulator/Cockpit/panel.cxx: Redefinition of default parameter
181 // Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
182 // Simulator/Main/fg_init.cxx:
183 // Simulator/Main/GLUTmain.cxx:
184 // Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
185 // Simulator/Objects/material.hxx:
186 // Simulator/Time/timestamp.hxx: VC++ friend kludge
187 // Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
188 // Simulator/Main/views.hxx: Added a constant
190 // Revision 1.22 1998/12/03 01:18:16 curt
191 // Converted fgFLIGHT to a class.
192 // Tweaks for Sun Portability.
193 // Tweaked current terrain elevation code as per NHV.
195 // Revision 1.21 1998/11/09 23:40:47 curt
196 // Bernie Bright <bbright@c031.aone.net.au> writes:
197 // I've made some changes to the Scenery handling. Basically just tidy ups.
198 // The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
199 // vector<fgFRAGMENT>. Studying our usage patterns this seems reasonable.
200 // Lists are good if you need to insert/delete elements randomly but we
201 // don't do that. All access seems to be sequential. Two additional
202 // benefits are smaller memory usage - each list element requires pointers
203 // to the next and previous elements, and faster access - vector iterators
204 // are smaller and faster than list iterators. This should also help
205 // Charlie Hotchkiss' problem when compiling with Borland and STLport.
207 // ./Lib/Bucket/bucketutils.hxx
208 // Convenience functions for fgBUCKET.
210 // ./Simulator/Scenery/tile.cxx
211 // ./Simulator/Scenery/tile.hxx
212 // Changed fragment list to a vector.
213 // Added some convenience member functions.
215 // ./Simulator/Scenery/tilecache.cxx
216 // ./Simulator/Scenery/tilecache.hxx
217 // use const fgBUCKET& instead of fgBUCKET* where appropriate.
219 // ./Simulator/Scenery/tilemgr.cxx
220 // ./Simulator/Scenery/tilemgr.hxx
221 // uses all the new convenience functions.
223 // Revision 1.20 1998/10/16 00:55:46 curt
224 // Converted to Point3D class.
226 // Revision 1.19 1998/09/17 18:36:17 curt
227 // Tweaks and optimizations by Norman Vine.
229 // Revision 1.18 1998/08/25 16:52:42 curt
230 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
233 // Revision 1.17 1998/08/22 14:49:58 curt
234 // Attempting to iron out seg faults and crashes.
235 // Did some shuffling to fix a initialization order problem between view
236 // position, scenery elevation.
238 // Revision 1.16 1998/08/22 02:01:34 curt
239 // increased fragment list size.
241 // Revision 1.15 1998/08/20 15:12:06 curt
242 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
243 // the need for "void" pointers and casts.
244 // Quick hack to count the number of scenery polygons that are being drawn.
246 // Revision 1.14 1998/08/12 21:13:06 curt
247 // material.cxx: don't load textures if they are disabled
248 // obj.cxx: optimizations from Norman Vine
249 // tile.cxx: minor tweaks
250 // tile.hxx: addition of num_faces
251 // tilemgr.cxx: minor tweaks
253 // Revision 1.13 1998/07/24 21:42:08 curt
254 // material.cxx: whups, double method declaration with no definition.
255 // obj.cxx: tweaks to avoid errors in SGI's CC.
256 // tile.cxx: optimizations by Norman Vine.
257 // tilemgr.cxx: optimizations by Norman Vine.
259 // Revision 1.12 1998/07/22 21:41:42 curt
260 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
261 // intersect optimization from Norman Vine.
263 // Revision 1.11 1998/07/12 03:18:28 curt
264 // Added ground collision detection. This involved:
265 // - saving the entire vertex list for each tile with the tile records.
266 // - saving the face list for each fragment with the fragment records.
267 // - code to intersect the current vertical line with the proper face in
268 // an efficient manner as possible.
269 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
271 // Revision 1.10 1998/07/08 14:47:22 curt
272 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
273 // polare3d.h renamed to polar3d.hxx
274 // fg{Cartesian,Polar}Point3d consolodated.
275 // Added some initial support for calculating local current ground elevation.
277 // Revision 1.9 1998/07/06 21:34:34 curt
278 // Added using namespace std for compilers that support this.
280 // Revision 1.8 1998/07/04 00:54:30 curt
281 // Added automatic mipmap generation.
283 // When rendering fragments, use saved model view matrix from associated tile
284 // rather than recalculating it with push() translate() pop().
286 // Revision 1.7 1998/06/12 00:58:05 curt
287 // Build only static libraries.
288 // Declare memmove/memset for Sloaris.
290 // Revision 1.6 1998/06/08 17:57:54 curt
291 // Working first pass at material proporty sorting.
293 // Revision 1.5 1998/06/06 01:09:32 curt
294 // I goofed on the log message in the last commit ... now fixed.
296 // Revision 1.4 1998/06/06 01:07:18 curt
297 // Increased per material fragment list size from 100 to 400.
298 // Now correctly draw viewable fragments in per material order.
300 // Revision 1.3 1998/06/05 22:39:54 curt
301 // Working on sorting by, and rendering by material properties.
303 // Revision 1.2 1998/06/03 00:47:50 curt
304 // No .h for STL includes.
305 // Minor view culling optimizations.
307 // Revision 1.1 1998/05/23 14:09:21 curt
308 // Added tile.cxx and tile.hxx.
309 // Working on rewriting the tile management system so a tile is just a list
310 // fragments, and the fragment record contains the display list for that fragment.