1 // fragment.hxx -- routines to handle "atomic" display objects
3 // Written by Curtis Olson, started August 1998.
5 // Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
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>
48 #include <Bucket/bucketutils.h>
49 #include <Include/fg_constants.h>
50 #include <Math/mat3.h>
51 #include <Math/point3d.hxx>
55 // Maximum nodes per tile
56 #define MAX_NODES 2000
62 fgFACE( int a = 0, int b =0, int c =0 )
63 : n1(a), n2(b), n3(c) {}
65 fgFACE( const fgFACE & image )
66 : n1(image.n1), n2(image.n2), n3(image.n3) {}
68 fgFACE& operator= ( const fgFACE & image ) {
69 n1 = image.n1; n2 = image.n2; n3 = image.n3; return *this;
76 operator== ( const fgFACE& lhs, const fgFACE& rhs )
78 return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
81 // Forward declarations
85 // Object fragment data class
91 // culling data for this object fragment (fine grain culling)
93 double bounding_radius;
95 // variable offset data for this object fragment for this frame
96 // fgCartesianPoint3d tile_offset;
98 // saved transformation matrix for this fragment (used by renderer)
99 // GLfloat matrix[16];
101 // tile_ptr & material_ptr are set so that when we traverse the
102 // list of fragments we can quickly reference back the tile or
103 // material property this fragment is assigned to.
105 // material property pointer
106 fgMATERIAL *material_ptr;
111 // OpenGL display list for fragment data
114 // face list (this indexes into the master tile vertex list)
115 typedef vector < fgFACE > container;
116 typedef container::iterator iterator;
117 typedef container::const_iterator const_iterator;
123 // number of faces in this fragment
128 // Add a face to the face list
129 void add_face(int n1, int n2, int n3) {
130 faces.push_back( fgFACE(n1,n2,n3) );
133 // test if line intesects with this fragment. p0 and p1 are the
134 // two line end points of the line. If side_flag is true, check
135 // to see that end points are on opposite sides of face. Returns
136 // 1 if it intersection found, 0 otherwise. If it intesects,
137 // result is the point of intersection
138 int intersect( const Point3D& end0,
141 Point3D& result) const;
144 fgFRAGMENT () { /*faces.reserve(512);*/}
145 fgFRAGMENT ( const fgFRAGMENT &image );
148 ~fgFRAGMENT() { faces.erase( faces.begin(), faces.end() ); }
151 fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
153 bool operator < ( const fgFRAGMENT & rhs ) const {
154 // This is completely arbitrary. It satisfies RW's STL implementation
155 return bounding_radius < rhs.bounding_radius;
159 faces.erase( faces.begin(), faces.end() );
162 int deleteDisplayList() {
163 xglDeleteLists( display_list, 1 ); return 0;
166 friend bool operator== ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs );
170 operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
171 return lhs.center == rhs.center;
175 #endif // _FRAGMENT_HXX
179 // Revision 1.10 1999/03/15 17:59:12 curt
180 // MSVC++ portability tweaks contributed by Bernie Bright.
181 // Un-nested struct fgFace.
182 // Made fgFragment::deleteDisplayList() a non-const member.
184 // Revision 1.9 1999/03/02 01:03:23 curt
185 // Tweaks for building with native SGI compilers.
187 // Revision 1.8 1999/02/26 22:09:57 curt
188 // Added initial support for native SGI compilers.
190 // Revision 1.7 1998/11/02 18:29:00 curt
191 // Portability changes for the Borland compiler.
193 // Revision 1.6 1998/10/16 00:54:38 curt
194 // Converted to Point3D class.
196 // Revision 1.5 1998/09/15 01:35:04 curt
197 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
198 // duplicating work.)
199 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
200 // removed some unneeded stuff from fgTileMgrCurElev()
202 // Revision 1.4 1998/09/10 19:07:09 curt
203 // /Simulator/Objects/fragment.hxx
204 // Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
206 // ./Simulator/Objects/material.cxx
207 // ./Simulator/Objects/material.hxx
208 // Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
209 // data members - that should keep the rabble happy :)
211 // ./Simulator/Scenery/tilemgr.cxx
212 // In viewable() delay evaluation of eye[0] and eye[1] in until they're
214 // Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
217 // ./Include/fg_stl_config.h
218 // ./Include/auto_ptr.hxx
219 // Added support for g++ 2.7.
220 // Further changes to other files are forthcoming.
222 // Brief summary of changes required for g++ 2.7.
223 // operator->() not supported by iterators: use (*i).x instead of i->x
224 // default template arguments not supported,
225 // <functional> doesn't have mem_fun_ref() needed by callbacks.
226 // some std include files have different names.
227 // template member functions not supported.
229 // Revision 1.3 1998/09/08 21:40:44 curt
230 // Updates from Bernie Bright.
232 // Revision 1.2 1998/09/01 19:03:08 curt
233 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
234 // - The new classes in libmisc.tgz define a stream interface into zlib.
235 // I've put these in a new directory, Lib/Misc. Feel free to rename it
236 // to something more appropriate. However you'll have to change the
237 // include directives in all the other files. Additionally you'll have
238 // add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
240 // The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
241 // test so I've included the required changes in config.tgz.
243 // There are a fair few changes to Simulator/Objects as I've moved
244 // things around. Loading tiles is quicker but thats not where the delay
245 // is. Tile loading takes a few tenths of a second per file on a P200
246 // but it seems to be the post-processing that leads to a noticeable
247 // blip in framerate. I suppose its time to start profiling to see where
250 // I've included a brief description of each archives contents.
255 // C++ stream interface into zlib.
256 // Taken from zlib-1.1.3/contrib/iostream/.
257 // Minor mods for STL compatibility.
258 // There's no copyright associated with these so I assume they're
259 // covered by zlib's.
263 // FlightGear input stream using gz_ifstream. Tries to open the
264 // given filename. If that fails then filename is examined and a
265 // ".gz" suffix is removed or appended and that file is opened.
268 // A simple timer for benchmarking. Not used in production code.
269 // Taken from the Blitz++ project. Covered by GPL.
273 // Some simple string manipulation routines.
275 // Simulator/Airports/
276 // Load airports database using fgstream.
277 // Changed fgAIRPORTS to use set<> instead of map<>.
278 // Added bool fgAIRPORTS::search() as a neater way doing the lookup.
279 // Returns true if found.
282 // Modified fgStarsInit() to load stars database using fgstream.
284 // Simulator/Objects/
285 // Modified fgObjLoad() to use fgstream.
286 // Modified fgMATERIAL_MGR::load_lib() to use fgstream.
287 // Many changes to fgMATERIAL.
288 // Some changes to fgFRAGMENT but I forget what!
290 // Revision 1.1 1998/08/25 16:51:23 curt
291 // Moved from ../Scenery