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