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