]> git.mxchange.org Git - flightgear.git/blob - Objects/fragment.hxx
Fixed a serious bug caused by not-quite-correct comment/white space eating
[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 <list>         // STL list
50
51 #include <Bucket/bucketutils.h>
52 #include <Include/fg_types.h>
53 #include "Include/fg_constants.h"
54 #include <Math/mat3.h>
55
56 #ifdef NEEDNAMESPACESTD
57 using namespace std;
58 #endif
59
60
61 // Maximum nodes per tile
62 #define MAX_NODES 2000
63
64
65 // Forward declarations
66 class fgTILE;
67 class fgMATERIAL;
68
69
70 class fgFACE {
71 public:
72     int n1, n2, n3;
73
74     explicit fgFACE( int a = 0, int b =0, int c =0 )
75         : n1(a), n2(b), n3(c) {}
76
77     fgFACE( const fgFACE & image )
78         : n1(image.n1), n2(image.n2), n3(image.n3) {}
79
80     ~fgFACE() {}
81
82     bool operator < ( const fgFACE & rhs ) { return n1 < rhs.n1; }
83 };
84
85 inline bool
86 operator == ( const fgFACE& lhs, const fgFACE & rhs )
87 {
88     return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
89 }
90
91 // Object fragment data class
92 class fgFRAGMENT {
93
94 public:
95     // culling data for this object fragment (fine grain culling)
96     fgPoint3d center;
97     double bounding_radius;
98
99     // variable offset data for this object fragment for this frame
100     // fgCartesianPoint3d tile_offset;
101
102     // saved transformation matrix for this fragment (used by renderer)
103     // GLfloat matrix[16];
104     
105     // tile_ptr & material_ptr are set so that when we traverse the
106     // list of fragments we can quickly reference back the tile or
107     // material property this fragment is assigned to.
108
109     // material property pointer
110     fgMATERIAL *material_ptr;
111
112     // tile pointer
113     fgTILE *tile_ptr;
114
115     // OpenGL display list for fragment data
116     GLint display_list;
117
118     // face list (this indexes into the master tile vertex list)
119     typedef list < fgFACE > container;
120     typedef container::iterator iterator;
121     typedef container::const_iterator const_iterator;
122
123     container faces;
124
125     // number of faces in this fragment
126     int num_faces;
127
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) );
131         num_faces++;
132     }
133
134     // test if line intesects with this fragment.  p0 and p1 are the
135     // two line end points of the line.  If side_flag is true, check
136     // to see that end points are on opposite sides of face.  Returns
137     // 1 if it intersection found, 0 otherwise.  If it intesects,
138     // result is the point of intersection
139     int intersect( const fgPoint3d *end0,
140                    const fgPoint3d *end1,
141                    int side_flag,
142                    fgPoint3d *result) const;
143
144     // Constructors
145     fgFRAGMENT () {}
146     fgFRAGMENT ( const fgFRAGMENT &image );
147
148     // Destructor
149     ~fgFRAGMENT() { faces.erase( faces.begin(), faces.end() ); }
150
151     // operators
152     fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
153
154     bool operator <  ( const fgFRAGMENT & rhs ) {
155         // This is completely arbitrary. It satisfies RW's STL implementation
156         return bounding_radius < rhs.bounding_radius;
157     }
158
159     void init() {
160         faces.erase( faces.begin(), faces.end() );
161         num_faces = 0;
162     }
163
164     void deleteDisplayList() {
165         xglDeleteLists( display_list, 1 );
166     }
167 };
168
169 inline bool
170 operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
171     return (( lhs.center.x - rhs.center.x ) < FG_EPSILON &&
172             ( lhs.center.y - rhs.center.y ) < FG_EPSILON &&
173             ( lhs.center.z - rhs.center.z ) < FG_EPSILON    );
174 }
175
176
177 #endif // _FRAGMENT_HXX 
178
179
180 // $Log$
181 // Revision 1.2  1998/09/01 19:03:08  curt
182 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
183 //  - The new classes in libmisc.tgz define a stream interface into zlib.
184 //    I've put these in a new directory, Lib/Misc.  Feel free to rename it
185 //    to something more appropriate.  However you'll have to change the
186 //    include directives in all the other files.  Additionally you'll have
187 //    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
188 //
189 //    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
190 //    test so I've included the required changes in config.tgz.
191 //
192 //    There are a fair few changes to Simulator/Objects as I've moved
193 //    things around.  Loading tiles is quicker but thats not where the delay
194 //    is.  Tile loading takes a few tenths of a second per file on a P200
195 //    but it seems to be the post-processing that leads to a noticeable
196 //    blip in framerate.  I suppose its time to start profiling to see where
197 //    the delays are.
198 //
199 //    I've included a brief description of each archives contents.
200 //
201 // Lib/Misc/
202 //   zfstream.cxx
203 //   zfstream.hxx
204 //     C++ stream interface into zlib.
205 //     Taken from zlib-1.1.3/contrib/iostream/.
206 //     Minor mods for STL compatibility.
207 //     There's no copyright associated with these so I assume they're
208 //     covered by zlib's.
209 //
210 //   fgstream.cxx
211 //   fgstream.hxx
212 //     FlightGear input stream using gz_ifstream.  Tries to open the
213 //     given filename.  If that fails then filename is examined and a
214 //     ".gz" suffix is removed or appended and that file is opened.
215 //
216 //   stopwatch.hxx
217 //     A simple timer for benchmarking.  Not used in production code.
218 //     Taken from the Blitz++ project.  Covered by GPL.
219 //
220 //   strutils.cxx
221 //   strutils.hxx
222 //     Some simple string manipulation routines.
223 //
224 // Simulator/Airports/
225 //   Load airports database using fgstream.
226 //   Changed fgAIRPORTS to use set<> instead of map<>.
227 //   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
228 //   Returns true if found.
229 //
230 // Simulator/Astro/
231 //   Modified fgStarsInit() to load stars database using fgstream.
232 //
233 // Simulator/Objects/
234 //   Modified fgObjLoad() to use fgstream.
235 //   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
236 //   Many changes to fgMATERIAL.
237 //   Some changes to fgFRAGMENT but I forget what!
238 //
239 // Revision 1.1  1998/08/25 16:51:23  curt
240 // Moved from ../Scenery
241 //
242 //