]> git.mxchange.org Git - flightgear.git/blob - src/Objects/fragment.hxx
Changes contributed by Tony Peden to put wind data "on the bus".
[flightgear.git] / src / 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
23
24 #ifndef _FRAGMENT_HXX
25 #define _FRAGMENT_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #ifdef HAVE_WINDOWS_H
37 #  include <windows.h>
38 #endif
39
40 #include <GL/glut.h>
41 #include <simgear/xgl/xgl.h>
42
43 #include <simgear/compiler.h>
44
45 #include <vector>
46
47 #include <simgear/constants.h>
48 #include <simgear/math/point3d.hxx>
49
50 FG_USING_STD(vector);
51
52
53 struct fgFACE {
54     int n1, n2, n3;
55
56     fgFACE( int a = 0, int b =0, int c =0 )
57         : n1(a), n2(b), n3(c) {}
58
59     fgFACE( const fgFACE & image )
60         : n1(image.n1), n2(image.n2), n3(image.n3) {}
61
62     fgFACE& operator= ( const fgFACE & image ) {
63         n1 = image.n1; n2 = image.n2; n3 = image.n3; return *this;
64     }
65
66     ~fgFACE() {}
67 };
68
69 inline bool
70 operator== ( const fgFACE& lhs, const fgFACE& rhs )
71 {
72     return (lhs.n1 == rhs.n1) && (lhs.n2 == rhs.n2) && (lhs.n3 == rhs.n3);
73 }
74
75 // Forward declarations
76 class FGTileEntry;
77 class FGMaterialSlot;
78
79 // Object fragment data class
80 class fgFRAGMENT {
81
82 private:
83
84 public:
85     // culling data for this object fragment (fine grain culling)
86     Point3D center;
87     double bounding_radius;
88
89     // variable offset data for this object fragment for this frame
90     // fgCartesianPoint3d tile_offset;
91
92     // saved transformation matrix for this fragment (used by renderer)
93     // GLfloat matrix[16];
94     
95     // tile_ptr & material_ptr are set so that when we traverse the
96     // list of fragments we can quickly reference back the tile or
97     // material property this fragment is assigned to.
98
99     // material property pointer
100     FGMaterialSlot *material_ptr;
101
102     // tile pointer
103     FGTileEntry *tile_ptr;
104
105     // OpenGL display list for fragment data
106     // GLint display_list;
107
108     // face list (this indexes into the master tile vertex list)
109     typedef vector < fgFACE > container;
110     typedef container::iterator iterator;
111     typedef container::const_iterator const_iterator;
112
113     container faces;
114
115 public:
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.clear();
154     }
155
156     // int deleteDisplayList() {
157     //    xglDeleteLists( display_list, 1 ); return 0;
158     // }
159
160     friend bool operator== ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs );
161 };
162
163 inline bool
164 operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) {
165     return lhs.center == rhs.center;
166 }
167
168
169 #endif // _FRAGMENT_HXX 
170
171