]> git.mxchange.org Git - flightgear.git/blob - Scenery/tile.hxx
Tweaks and optimizations by Norman Vine.
[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 #include <Objects/fragment.hxx>
55
56 #ifdef NEEDNAMESPACESTD
57 using namespace std;
58 #endif
59
60
61 // Scenery tile class
62 class fgTILE {
63
64 public:
65
66     // node list (the per fragment face lists reference this node list)
67     double (*nodes)[3];
68     int ncount;
69
70     // culling data for whole tile (course grain culling)
71     fgPoint3d center;
72     double bounding_radius;
73     fgPoint3d offset;
74     GLdouble model_view[16];
75
76     // this tile's official location in the world
77     fgBUCKET tile_bucket;
78
79     // the tile cache will mark here if the tile is being used
80     int used;
81
82     list < fgFRAGMENT > fragment_list;
83
84     // Constructor
85     fgTILE ( void );
86
87     // Destructor
88     ~fgTILE ( void );
89
90     // Calculate this tile's offset
91     void
92     fgTILE::SetOffset( fgPoint3d *off)
93     {
94         offset.x = center.x - off->x;
95         offset.y = center.y - off->y;
96         offset.z = center.z - off->z;
97     }
98
99
100     // Calculate the model_view transformation matrix for this tile
101     inline void
102     fgTILE::UpdateViewMatrix(GLdouble *MODEL_VIEW)
103     {
104
105 #ifdef WIN32
106         memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
107 #else
108         bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
109 #endif
110         
111         // This is equivalent to doing a glTranslatef(x, y, z);
112         model_view[12] += (model_view[0]*offset.x + model_view[4]*offset.y +
113                            model_view[8]*offset.z);
114         model_view[13] += (model_view[1]*offset.x + model_view[5]*offset.y +
115                            model_view[9]*offset.z);
116         model_view[14] += (model_view[2]*offset.x + model_view[6]*offset.y +
117                            model_view[10]*offset.z);
118         // m[15] += (m[3]*x + m[7]*y + m[11]*z);
119         // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
120         // so m[15] is unchanged
121     }
122
123 };
124
125
126 #endif // _TILE_HXX 
127
128
129 // $Log$
130 // Revision 1.19  1998/09/17 18:36:17  curt
131 // Tweaks and optimizations by Norman Vine.
132 //
133 // Revision 1.18  1998/08/25 16:52:42  curt
134 // material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
135 //   ../Objects
136 //
137 // Revision 1.17  1998/08/22  14:49:58  curt
138 // Attempting to iron out seg faults and crashes.
139 // Did some shuffling to fix a initialization order problem between view
140 // position, scenery elevation.
141 //
142 // Revision 1.16  1998/08/22 02:01:34  curt
143 // increased fragment list size.
144 //
145 // Revision 1.15  1998/08/20 15:12:06  curt
146 // Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
147 // the need for "void" pointers and casts.
148 // Quick hack to count the number of scenery polygons that are being drawn.
149 //
150 // Revision 1.14  1998/08/12 21:13:06  curt
151 // material.cxx: don't load textures if they are disabled
152 // obj.cxx: optimizations from Norman Vine
153 // tile.cxx: minor tweaks
154 // tile.hxx: addition of num_faces
155 // tilemgr.cxx: minor tweaks
156 //
157 // Revision 1.13  1998/07/24 21:42:08  curt
158 // material.cxx: whups, double method declaration with no definition.
159 // obj.cxx: tweaks to avoid errors in SGI's CC.
160 // tile.cxx: optimizations by Norman Vine.
161 // tilemgr.cxx: optimizations by Norman Vine.
162 //
163 // Revision 1.12  1998/07/22 21:41:42  curt
164 // Add basic fgFACE methods contributed by Charlie Hotchkiss.
165 // intersect optimization from Norman Vine.
166 //
167 // Revision 1.11  1998/07/12 03:18:28  curt
168 // Added ground collision detection.  This involved:
169 // - saving the entire vertex list for each tile with the tile records.
170 // - saving the face list for each fragment with the fragment records.
171 // - code to intersect the current vertical line with the proper face in
172 //   an efficient manner as possible.
173 // Fixed a bug where the tiles weren't being shifted to "near" (0,0,0)
174 //
175 // Revision 1.10  1998/07/08 14:47:22  curt
176 // Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen.
177 // polare3d.h renamed to polar3d.hxx
178 // fg{Cartesian,Polar}Point3d consolodated.
179 // Added some initial support for calculating local current ground elevation.
180 //
181 // Revision 1.9  1998/07/06 21:34:34  curt
182 // Added using namespace std for compilers that support this.
183 //
184 // Revision 1.8  1998/07/04 00:54:30  curt
185 // Added automatic mipmap generation.
186 //
187 // When rendering fragments, use saved model view matrix from associated tile
188 // rather than recalculating it with push() translate() pop().
189 //
190 // Revision 1.7  1998/06/12 00:58:05  curt
191 // Build only static libraries.
192 // Declare memmove/memset for Sloaris.
193 //
194 // Revision 1.6  1998/06/08 17:57:54  curt
195 // Working first pass at material proporty sorting.
196 //
197 // Revision 1.5  1998/06/06 01:09:32  curt
198 // I goofed on the log message in the last commit ... now fixed.
199 //
200 // Revision 1.4  1998/06/06 01:07:18  curt
201 // Increased per material fragment list size from 100 to 400.
202 // Now correctly draw viewable fragments in per material order.
203 //
204 // Revision 1.3  1998/06/05 22:39:54  curt
205 // Working on sorting by, and rendering by material properties.
206 //
207 // Revision 1.2  1998/06/03 00:47:50  curt
208 // No .h for STL includes.
209 // Minor view culling optimizations.
210 //
211 // Revision 1.1  1998/05/23 14:09:21  curt
212 // Added tile.cxx and tile.hxx.
213 // Working on rewriting the tile management system so a tile is just a list
214 // fragments, and the fragment record contains the display list for that fragment.
215 //