]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/hitlist.hxx
Check for the plib version when using display lists, just to be sure.
[flightgear.git] / src / Scenery / hitlist.hxx
1 // hitlist.hxx
2 // Height Over Terrain and Assosciated Routines for FlightGear based Scenery
3 // Written by Norman Vine, started 2000.
4
5 #ifndef _HITLIST_HXX
6 #define _HITLIST_HXX
7
8 #ifndef __cplusplus                                                          
9 # error This library requires C++
10 #endif                                   
11
12 #include <simgear/compiler.h>
13
14 #include <vector>
15
16 SG_USING_STD(vector);
17
18 class ssgEntity;
19 class ssgBranch;
20
21 class FGHitRec {
22
23 private:
24     ssgEntity *ent;
25     int index;
26     sgdVec3 point;
27     sgdVec3 normal;
28
29 public:
30
31     FGHitRec( ssgEntity *e, int idx, sgdVec3 p, sgdVec3 n ) {
32         ent = e;
33         index = idx;
34         sgdSetVec3(point,p[0],p[1],p[2]);
35         sgdSetVec3(normal,n[0],n[1],n[2]);
36     }
37
38     ssgEntity *get_entity(void) { return ent; }
39     int get_face(void)          { return index; }
40     double *get_point(void)     { return point; }
41     double *get_normal(void)    { return normal; }
42 };
43
44
45 class FGHitList {
46
47 private:
48
49     ssgEntity *last;
50     vector < FGHitRec > list;
51     double test_dist;
52
53 public:
54
55     FGHitList();
56     ~FGHitList();
57
58     void init(void) { list.clear(); test_dist=DBL_MAX; }
59     void clear(void) { init(); last = NULL; }
60     void add( ssgEntity *ent, int idx, sgdVec3 point, sgdVec3 normal ) {
61         list.push_back( FGHitRec( ent,idx,point,normal) );
62         last = ent;
63     }
64     int num_hits(void) { return list.size(); }
65     ssgEntity *get_entity(int i)  { return list[i].get_entity(); }
66     ssgEntity *last_hit(void)     { return last; }
67     int get_face(int i)           { return list[i].get_face(); }
68     double *get_point(int i)      { return list[i].get_point(); }
69     double *get_normal(int i)     { return list[i].get_normal(); }
70
71     void Intersect( ssgBranch *branch, sgdVec3 orig, sgdVec3 dir );
72     void Intersect( ssgBranch *scene, sgdMat4 m, sgdVec3 orig, sgdVec3 dir );
73
74     void IntersectBranch( ssgBranch *branch, sgdMat4 m, sgdVec3 orig, sgdVec3 dir);
75
76     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
77                        sgdVec3 orig, sgdVec3 dir );
78
79     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
80                        sgdVec3 orig, sgdVec3 dir,
81                        GLenum primType );
82 };
83
84
85 // Associated functions, assuming a wgs84 world with 0,0,0 at the
86 // center, find the current terrain intersection elevation for the
87 // point specified.
88 bool fgCurrentElev( sgdVec3 abs_view_pos,
89                     double max_alt_m,
90                     sgdVec3 scenery_center,
91                     ssgTransform *terra_transform,
92                     FGHitList *hit_list,
93                     double *terrain_elev,
94                     double *radius,
95                     double *normal );
96
97 bool fgCurrentElev( sgdVec3 abs_view_pos,
98                     double max_alt_m,
99                     sgdVec3 scenery_center,
100                     FGHitList *hit_list,
101                     double *terrain_elev,
102                     double *radius,
103                     double *normal );
104
105 #endif // _HITLIST_HXX