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 #if defined ( __sun__ )
45 extern "C" void *memmove(void *, const void *, size_t);
46 extern "C" void *memset(void *, int, size_t);
49 #include <list> // STL list
51 #include <Bucket/bucketutils.h>
52 #include <Include/fg_types.h>
53 #include <Math/mat3.h>
55 #ifdef NEEDNAMESPACESTD
60 // Maximum nodes per tile
61 #define MAX_NODES 2000
64 // Forward declarations
75 fgFACE( const fgFACE & image );
76 bool operator < ( const fgFACE & rhs );
77 bool operator == ( const fgFACE & rhs );
81 // Object fragment data class
85 // culling data for this object fragment (fine grain culling)
87 double bounding_radius;
89 // variable offset data for this object fragment for this frame
90 // fgCartesianPoint3d tile_offset;
92 // saved transformation matrix for this fragment (used by renderer)
93 // GLfloat matrix[16];
95 // tile_ptr & material_ptr are set so that when we traverse the
96 // list of fragments we can quickly reference back the tile or
97 // material property this fragment is assigned to.
99 // material property pointer
100 fgMATERIAL *material_ptr;
105 // OpenGL display list for fragment data
108 // face list (this indexes into the master tile vertex list)
109 list < fgFACE > faces;
111 // number of faces in this fragment
114 // Add a face to the face list
115 void add_face(int n1, int n2, int n3);
117 // test if line intesects with this fragment. p0 and p1 are the
118 // two line end points of the line. If side_flag is true, check
119 // to see that end points are on opposite sides of face. Returns
120 // 1 if it intersection found, 0 otherwise. If it intesects,
121 // result is the point of intersection
122 int intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
127 fgFRAGMENT ( const fgFRAGMENT &image );
133 fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
134 bool operator == ( const fgFRAGMENT & rhs );
135 bool operator < ( const fgFRAGMENT & rhs );
139 // Scenery tile class
144 // node list (the per fragment face lists reference this node list)
148 // culling data for whole tile (course grain culling)
150 double bounding_radius;
152 GLdouble model_view[16];
154 // this tile's official location in the world
155 fgBUCKET tile_bucket;
157 // the tile cache will mark here if the tile is being used
160 list < fgFRAGMENT > fragment_list;
174 // Revision 1.17 1998/08/22 14:49:58 curt
175 // Attempting to iron out seg faults and crashes.
176 // Did some shuffling to fix a initialization order problem between view
177 // position, scenery elevation.
179 // Revision 1.16 1998/08/22 02:01:34 curt
180 // increased fragment list size.
182 // Revision 1.15 1998/08/20 15:12:06 curt
183 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
184 // the need for "void" pointers and casts.
185 // Quick hack to count the number of scenery polygons that are being drawn.
187 // Revision 1.14 1998/08/12 21:13:06 curt
188 // material.cxx: don't load textures if they are disabled
189 // obj.cxx: optimizations from Norman Vine
190 // tile.cxx: minor tweaks
191 // tile.hxx: addition of num_faces
192 // tilemgr.cxx: minor tweaks
194 // Revision 1.13 1998/07/24 21:42:08 curt
195 // material.cxx: whups, double method declaration with no definition.
196 // obj.cxx: tweaks to avoid errors in SGI's CC.
197 // tile.cxx: optimizations by Norman Vine.
198 // tilemgr.cxx: optimizations by Norman Vine.
200 // Revision 1.12 1998/07/22 21:41:42 curt
201 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
202 // intersect optimization from Norman Vine.
204 // Revision 1.11 1998/07/12 03:18:28 curt
205 // Added ground collision detection. This involved:
206 // - saving the entire vertex list for each tile with the tile records.
207 // - saving the face list for each fragment with the fragment records.
208 // - code to intersect the current vertical line with the proper face in
209 // an efficient manner as possible.
210 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
212 // Revision 1.10 1998/07/08 14:47:22 curt
213 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
214 // polare3d.h renamed to polar3d.hxx
215 // fg{Cartesian,Polar}Point3d consolodated.
216 // Added some initial support for calculating local current ground elevation.
218 // Revision 1.9 1998/07/06 21:34:34 curt
219 // Added using namespace std for compilers that support this.
221 // Revision 1.8 1998/07/04 00:54:30 curt
222 // Added automatic mipmap generation.
224 // When rendering fragments, use saved model view matrix from associated tile
225 // rather than recalculating it with push() translate() pop().
227 // Revision 1.7 1998/06/12 00:58:05 curt
228 // Build only static libraries.
229 // Declare memmove/memset for Sloaris.
231 // Revision 1.6 1998/06/08 17:57:54 curt
232 // Working first pass at material proporty sorting.
234 // Revision 1.5 1998/06/06 01:09:32 curt
235 // I goofed on the log message in the last commit ... now fixed.
237 // Revision 1.4 1998/06/06 01:07:18 curt
238 // Increased per material fragment list size from 100 to 400.
239 // Now correctly draw viewable fragments in per material order.
241 // Revision 1.3 1998/06/05 22:39:54 curt
242 // Working on sorting by, and rendering by material properties.
244 // Revision 1.2 1998/06/03 00:47:50 curt
245 // No .h for STL includes.
246 // Minor view culling optimizations.
248 // Revision 1.1 1998/05/23 14:09:21 curt
249 // Added tile.cxx and tile.hxx.
250 // Working on rewriting the tile management system so a tile is just a list
251 // fragments, and the fragment record contains the display list for that fragment.