]> git.mxchange.org Git - flightgear.git/blob - Scenery/tile.hxx
material.cxx: don't load textures if they are disabled
[flightgear.git] / Scenery / tile.hxx
1 // tile.hxx -- routines to handle a scenery tile
2 //
3 // Written by Curtis Olson, started May 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - curt@infoplane.com
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 _TILE_HXX
26 #define _TILE_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 <Math/mat3.h>
54
55 #ifdef NEEDNAMESPACESTD
56 using namespace std;
57 #endif
58
59
60 // Maximum nodes per tile
61 #define MAX_NODES 1000
62
63
64 class fgFACE {
65 public:
66     int n1, n2, n3;
67
68     fgFACE();
69     ~fgFACE();
70     fgFACE( const fgFACE & image );
71     bool operator < ( const fgFACE & rhs );
72     bool operator == ( const fgFACE & rhs );
73 };
74
75
76 // Object fragment data class
77 class fgFRAGMENT {
78
79 public:
80     // culling data for this object fragment (fine grain culling)
81     fgPoint3d center;
82     double bounding_radius;
83
84     // variable offset data for this object fragment for this frame
85     // fgCartesianPoint3d tile_offset;
86
87     // saved transformation matrix for this fragment (used by renderer)
88     // GLfloat matrix[16];
89     
90     // tile_ptr & material_ptr are set so that when we traverse the
91     // list of fragments we can quickly reference back the tile or
92     // material property this fragment is assigned to.
93
94     // material property pointer
95     void *material_ptr;
96
97     // tile pointer
98     void *tile_ptr;
99
100     // OpenGL display list for fragment data
101     GLint display_list;
102
103     // face list (this indexes into the master tile vertex list)
104     list < fgFACE > faces;
105
106     // number of faces in this fragment
107     int num_faces;
108
109     // Add a face to the face list
110     void add_face(int n1, int n2, int n3);
111
112     // test if line intesects with this fragment.  p0 and p1 are the
113     // two line end points of the line.  If side_flag is true, check
114     // to see that end points are on opposite sides of face.  Returns
115     // 1 if it does, 0 otherwise.  If it intesects, result is the
116     // point of intersection
117     int intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
118                    fgPoint3d *result);
119
120     // Constructors
121     fgFRAGMENT ();
122     fgFRAGMENT ( const fgFRAGMENT &image );
123
124     // Destructor
125     ~fgFRAGMENT ( );
126
127     // operators
128     fgFRAGMENT & operator = ( const fgFRAGMENT & rhs );
129     bool operator == ( const fgFRAGMENT & rhs );
130     bool operator <  ( const fgFRAGMENT & rhs );
131 };
132
133
134 // Scenery tile class
135 class fgTILE {
136
137 public:
138
139     // node list (the per fragment face lists reference this node list)
140     double (*nodes)[3];
141     int ncount;
142
143     // culling data for whole tile (course grain culling)
144     fgPoint3d center;
145     double bounding_radius;
146     fgPoint3d offset;
147     GLdouble model_view[16];
148
149     // this tile's official location in the world
150     fgBUCKET tile_bucket;
151
152     // the tile cache will mark here if the tile is being used
153     int used;
154
155     list < fgFRAGMENT > fragment_list;
156
157     // Constructor
158     fgTILE ( void );
159
160     // Destructor
161     ~fgTILE ( void );
162 };
163
164
165 #endif // _TILE_HXX 
166
167
168 // $Log$
169 // Revision 1.14  1998/08/12 21:13:06  curt
170 // material.cxx: don't load textures if they are disabled
171 // obj.cxx: optimizations from Norman Vine
172 // tile.cxx: minor tweaks
173 // tile.hxx: addition of num_faces
174 // tilemgr.cxx: minor tweaks
175 //
176 // Revision 1.13  1998/07/24 21:42:08  curt
177 // material.cxx: whups, double method declaration with no definition.
178 // obj.cxx: tweaks to avoid errors in SGI's CC.
179 // tile.cxx: optimizations by Norman Vine.
180 // tilemgr.cxx: optimizations by Norman Vine.
181 //
182 // Revision 1.12  1998/07/22 21:41:42  curt
183 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
184 // intersect optimization from Norman Vine.
185 //
186 // Revision 1.11  1998/07/12 03:18:28  curt
187 // Added ground collision detection.  This involved:
188 // - saving the entire vertex list for each tile with the tile records.
189 // - saving the face list for each fragment with the fragment records.
190 // - code to intersect the current vertical line with the proper face in
191 //   an efficient manner as possible.
192 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
193 //
194 // Revision 1.10  1998/07/08 14:47:22  curt
195 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
196 // polare3d.h renamed to polar3d.hxx
197 // fg{Cartesian,Polar}Point3d consolodated.
198 // Added some initial support for calculating local current ground elevation.
199 //
200 // Revision 1.9  1998/07/06 21:34:34  curt
201 // Added using namespace std for compilers that support this.
202 //
203 // Revision 1.8  1998/07/04 00:54:30  curt
204 // Added automatic mipmap generation.
205 //
206 // When rendering fragments, use saved model view matrix from associated tile
207 // rather than recalculating it with push() translate() pop().
208 //
209 // Revision 1.7  1998/06/12 00:58:05  curt
210 // Build only static libraries.
211 // Declare memmove/memset for Sloaris.
212 //
213 // Revision 1.6  1998/06/08 17:57:54  curt
214 // Working first pass at material proporty sorting.
215 //
216 // Revision 1.5  1998/06/06 01:09:32  curt
217 // I goofed on the log message in the last commit ... now fixed.
218 //
219 // Revision 1.4  1998/06/06 01:07:18  curt
220 // Increased per material fragment list size from 100 to 400.
221 // Now correctly draw viewable fragments in per material order.
222 //
223 // Revision 1.3  1998/06/05 22:39:54  curt
224 // Working on sorting by, and rendering by material properties.
225 //
226 // Revision 1.2  1998/06/03 00:47:50  curt
227 // No .h for STL includes.
228 // Minor view culling optimizations.
229 //
230 // Revision 1.1  1998/05/23 14:09:21  curt
231 // Added tile.cxx and tile.hxx.
232 // Working on rewriting the tile management system so a tile is just a list
233 // fragments, and the fragment record contains the display list for that fragment.
234 //