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>
54 #include <Math/point3d.hxx>
55 #include <Objects/fragment.hxx>
57 #ifdef NEEDNAMESPACESTD
67 // node list (the per fragment face lists reference this node list)
71 // culling data for whole tile (course grain culling)
73 double bounding_radius;
75 GLdouble model_view[16];
77 // this tile's official location in the world
80 // the tile cache will mark here if the tile is being used
83 list < fgFRAGMENT > fragment_list;
91 // Calculate this tile's offset
93 fgTILE::SetOffset( const Point3D& off)
95 offset = center - off;
99 // Calculate the model_view transformation matrix for this tile
101 fgTILE::UpdateViewMatrix(GLdouble *MODEL_VIEW)
105 memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
107 bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
110 // This is equivalent to doing a glTranslatef(x, y, z);
111 model_view[12] += (model_view[0]*offset.x() + model_view[4]*offset.y() +
112 model_view[8]*offset.z());
113 model_view[13] += (model_view[1]*offset.x() + model_view[5]*offset.y() +
114 model_view[9]*offset.z());
115 model_view[14] += (model_view[2]*offset.x() + model_view[6]*offset.y() +
116 model_view[10]*offset.z() );
117 // m[15] += (m[3]*x + m[7]*y + m[11]*z);
118 // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
119 // so m[15] is unchanged
129 // Revision 1.20 1998/10/16 00:55:46 curt
130 // Converted to Point3D class.
132 // Revision 1.19 1998/09/17 18:36:17 curt
133 // Tweaks and optimizations by Norman Vine.
135 // Revision 1.18 1998/08/25 16:52:42 curt
136 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
139 // Revision 1.17 1998/08/22 14:49:58 curt
140 // Attempting to iron out seg faults and crashes.
141 // Did some shuffling to fix a initialization order problem between view
142 // position, scenery elevation.
144 // Revision 1.16 1998/08/22 02:01:34 curt
145 // increased fragment list size.
147 // Revision 1.15 1998/08/20 15:12:06 curt
148 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
149 // the need for "void" pointers and casts.
150 // Quick hack to count the number of scenery polygons that are being drawn.
152 // Revision 1.14 1998/08/12 21:13:06 curt
153 // material.cxx: don't load textures if they are disabled
154 // obj.cxx: optimizations from Norman Vine
155 // tile.cxx: minor tweaks
156 // tile.hxx: addition of num_faces
157 // tilemgr.cxx: minor tweaks
159 // Revision 1.13 1998/07/24 21:42:08 curt
160 // material.cxx: whups, double method declaration with no definition.
161 // obj.cxx: tweaks to avoid errors in SGI's CC.
162 // tile.cxx: optimizations by Norman Vine.
163 // tilemgr.cxx: optimizations by Norman Vine.
165 // Revision 1.12 1998/07/22 21:41:42 curt
166 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
167 // intersect optimization from Norman Vine.
169 // Revision 1.11 1998/07/12 03:18:28 curt
170 // Added ground collision detection. This involved:
171 // - saving the entire vertex list for each tile with the tile records.
172 // - saving the face list for each fragment with the fragment records.
173 // - code to intersect the current vertical line with the proper face in
174 // an efficient manner as possible.
175 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
177 // Revision 1.10 1998/07/08 14:47:22 curt
178 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
179 // polare3d.h renamed to polar3d.hxx
180 // fg{Cartesian,Polar}Point3d consolodated.
181 // Added some initial support for calculating local current ground elevation.
183 // Revision 1.9 1998/07/06 21:34:34 curt
184 // Added using namespace std for compilers that support this.
186 // Revision 1.8 1998/07/04 00:54:30 curt
187 // Added automatic mipmap generation.
189 // When rendering fragments, use saved model view matrix from associated tile
190 // rather than recalculating it with push() translate() pop().
192 // Revision 1.7 1998/06/12 00:58:05 curt
193 // Build only static libraries.
194 // Declare memmove/memset for Sloaris.
196 // Revision 1.6 1998/06/08 17:57:54 curt
197 // Working first pass at material proporty sorting.
199 // Revision 1.5 1998/06/06 01:09:32 curt
200 // I goofed on the log message in the last commit ... now fixed.
202 // Revision 1.4 1998/06/06 01:07:18 curt
203 // Increased per material fragment list size from 100 to 400.
204 // Now correctly draw viewable fragments in per material order.
206 // Revision 1.3 1998/06/05 22:39:54 curt
207 // Working on sorting by, and rendering by material properties.
209 // Revision 1.2 1998/06/03 00:47:50 curt
210 // No .h for STL includes.
211 // Minor view culling optimizations.
213 // Revision 1.1 1998/05/23 14:09:21 curt
214 // Added tile.cxx and tile.hxx.
215 // Working on rewriting the tile management system so a tile is just a list
216 // fragments, and the fragment record contains the display list for that fragment.