]> git.mxchange.org Git - flightgear.git/blob - Objects/fragment.hxx
Removed an extraneous output message.
[flightgear.git] / Objects / fragment.hxx
1 // fragment.hxx -- routines to handle "atomic" display objects
2 //
3 // Written by Curtis Olson, started August 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifndef _FRAGMENT_HXX
26 #define _FRAGMENT_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <GL/glut.h>
42 #include <XGL/xgl.h>
43
44 #if defined ( __sun__ )
45 extern "C" void *memmove(void *, const void *, size_t);
46 extern "C" void *memset(void *, int, size_t);
47 #endif
48
49 #include <vector>
50
51 #include <Bucket/bucketutils.h>
52 // #include <Include/fg_types.h>
53 #include "Include/fg_constants.h"
54 #include <Math/mat3.h>
55 #include <Math/point3d.hxx>
56
57 #ifdef NEEDNAMESPACESTD
58 using namespace std;
59 #endif
60
61
62 // Maximum nodes per tile
63 #define MAX_NODES 2000
64
65
66 // Forward declarations
67 class fgTILE;
68 class fgMATERIAL;
69
70 // Object fragment data class
71 class fgFRAGMENT {
72
73 private:
74     struct fgFACE {
75         int n1, n2, n3;
76
77         fgFACE( int a = 0, int b =0, int c =0 )
78             : n1(a), n2(b), n3(c) {}
79
80         fgFACE( const fgFACE & image )
81             : n1(image.n1), n2(image.n2), n3(image.n3) {}
82
83         ~fgFACE() {}
84     };
85
86 public:
87     // culling data for this object fragment (fine grain culling)
88     Point3D center;
89     double bounding_radius;
90
91     // variable offset data for this object fragment for this frame
92     // fgCartesianPoint3d tile_offset;
93
94     // saved transformation matrix for this fragment (used by renderer)
95     // GLfloat matrix[16];
96     
97     // tile_ptr & material_ptr are set so that when we traverse the
98     // list of fragments we can quickly reference back the tile or
99     // material property this fragment is assigned to.
100
101     // material property pointer
102     fgMATERIAL *material_ptr;
103
104     // tile pointer
105     fgTILE *tile_ptr;
106
107     // OpenGL display list for fragment data
108     GLint display_list;
109
110     // face list (this indexes into the master tile vertex list)
111     typedef vector < fgFACE > container;
112     typedef container::iterator iterator;
113     typedef container::const_iterator const_iterator;
114
115     container faces;
116
117     // number of faces in this fragment
118     int num_faces() {
119         return faces.size();
120     }
121
122     // Add a face to the face list
123     void add_face(int n1, int n2, int n3) {
124         faces.push_back( fgFACE(n1,n2,n3) );
125     }
126
127     // test if line intesects with this fragment.  p0 and p1 are the
128     // two line end points of the line.  If side_flag is true, check
129     // to see that end points are on opposite sides of face.  Returns
130     // 1 if it intersection found, 0 otherwise.  If it intesects,
131     // result is the point of intersection
132     int intersect( const Point3D& end0,
133                    const Point3D& end1,
134                    int side_flag,
135                    Point3D& result) const;
136
137     // Constructors
138     fgFRAGMENT () { /*faces.reserve(512);*/}
139     fgFRAGMENT ( const fgFRAGMENT &image );
140
141     // Destructor
142     ~fgFRAGMENT() { faces.erase( faces.begin(), faces.end() ); }
143
144     // operators
145     fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
146
147     bool operator <  ( const fgFRAGMENT & rhs ) const {
148         // This is completely arbitrary. It satisfies RW's STL implementation
149         return bounding_radius < rhs.bounding_radius;
150     }
151
152     void init() {
153         faces.erase( faces.begin(), faces.end() );
154     }
155
156     int deleteDisplayList() {
157         xglDeleteLists( display_list, 1 ); return 0;
158     }
159 };
160
161 inline bool
162 operator == ( const fgFRAGMENT::fgFACE& lhs,
163               const fgFRAGMENT::fgFACE& rhs )
164 {
165     return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
166 }
167
168 inline bool
169 operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
170     return lhs.center == rhs.center;
171 }
172
173
174 #endif // _FRAGMENT_HXX 
175
176
177 // $Log$
178 // Revision 1.6  1998/10/16 00:54:38  curt
179 // Converted to Point3D class.
180 //
181 // Revision 1.5  1998/09/15 01:35:04  curt
182 // cleaned up my fragment.num_faces hack :-) to use the STL (no need in
183 // duplicating work.)
184 // Tweaked fgTileMgrRender() do not calc tile matrix unless necessary.
185 // removed some unneeded stuff from fgTileMgrCurElev()
186 //
187 // Revision 1.4  1998/09/10 19:07:09  curt
188 // /Simulator/Objects/fragment.hxx
189 //   Nested fgFACE inside fgFRAGMENT since its not used anywhere else.
190 //
191 // ./Simulator/Objects/material.cxx
192 // ./Simulator/Objects/material.hxx
193 //   Made fgMATERIAL and fgMATERIAL_MGR bona fide classes with private
194 //   data members - that should keep the rabble happy :)
195 //
196 // ./Simulator/Scenery/tilemgr.cxx
197 //   In viewable() delay evaluation of eye[0] and eye[1] in until they're
198 //   actually needed.
199 //   Change to fgTileMgrRender() to call fgMATERIAL_MGR::render_fragments()
200 //   method.
201 //
202 // ./Include/fg_stl_config.h
203 // ./Include/auto_ptr.hxx
204 //   Added support for g++ 2.7.
205 //   Further changes to other files are forthcoming.
206 //
207 // Brief summary of changes required for g++ 2.7.
208 //   operator->() not supported by iterators: use (*i).x instead of i->x
209 //   default template arguments not supported,
210 //   <functional> doesn't have mem_fun_ref() needed by callbacks.
211 //   some std include files have different names.
212 //   template member functions not supported.
213 //
214 // Revision 1.3  1998/09/08 21:40:44  curt
215 // Updates from Bernie Bright.
216 //
217 // Revision 1.2  1998/09/01 19:03:08  curt
218 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
219 //  - The new classes in libmisc.tgz define a stream interface into zlib.
220 //    I've put these in a new directory, Lib/Misc.  Feel free to rename it
221 //    to something more appropriate.  However you'll have to change the
222 //    include directives in all the other files.  Additionally you'll have
223 //    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
224 //
225 //    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
226 //    test so I've included the required changes in config.tgz.
227 //
228 //    There are a fair few changes to Simulator/Objects as I've moved
229 //    things around.  Loading tiles is quicker but thats not where the delay
230 //    is.  Tile loading takes a few tenths of a second per file on a P200
231 //    but it seems to be the post-processing that leads to a noticeable
232 //    blip in framerate.  I suppose its time to start profiling to see where
233 //    the delays are.
234 //
235 //    I've included a brief description of each archives contents.
236 //
237 // Lib/Misc/
238 //   zfstream.cxx
239 //   zfstream.hxx
240 //     C++ stream interface into zlib.
241 //     Taken from zlib-1.1.3/contrib/iostream/.
242 //     Minor mods for STL compatibility.
243 //     There's no copyright associated with these so I assume they're
244 //     covered by zlib's.
245 //
246 //   fgstream.cxx
247 //   fgstream.hxx
248 //     FlightGear input stream using gz_ifstream.  Tries to open the
249 //     given filename.  If that fails then filename is examined and a
250 //     ".gz" suffix is removed or appended and that file is opened.
251 //
252 //   stopwatch.hxx
253 //     A simple timer for benchmarking.  Not used in production code.
254 //     Taken from the Blitz++ project.  Covered by GPL.
255 //
256 //   strutils.cxx
257 //   strutils.hxx
258 //     Some simple string manipulation routines.
259 //
260 // Simulator/Airports/
261 //   Load airports database using fgstream.
262 //   Changed fgAIRPORTS to use set<> instead of map<>.
263 //   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
264 //   Returns true if found.
265 //
266 // Simulator/Astro/
267 //   Modified fgStarsInit() to load stars database using fgstream.
268 //
269 // Simulator/Objects/
270 //   Modified fgObjLoad() to use fgstream.
271 //   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
272 //   Many changes to fgMATERIAL.
273 //   Some changes to fgFRAGMENT but I forget what!
274 //
275 // Revision 1.1  1998/08/25 16:51:23  curt
276 // Moved from ../Scenery
277 //
278 //