]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/hitlist.hxx
Fix line endings
[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 SG_USING_STD(vector);
16
17 #include <plib/ssg.h>
18
19 class ssgEntity;
20 class ssgBranch;
21
22 class FGHitRec {
23
24 private:
25     ssgEntity *ent;
26     int index;
27     sgdVec3 point;
28     sgdVec3 normal;
29
30 public:
31
32     FGHitRec( ssgEntity *e, int idx, sgdVec3 p, sgdVec3 n ) {
33         ent = e;
34         index = idx;
35         sgdSetVec3(point,p[0],p[1],p[2]);
36         sgdSetVec3(normal,n[0],n[1],n[2]);
37     }
38
39     ssgEntity *get_entity(void) { return ent; }
40     int get_face(void)          { return index; }
41     double *get_point(void)     { return point; }
42     double *get_normal(void)    { return normal; }
43 };
44
45
46 class FGHitList {
47
48 private:
49
50     ssgEntity *last;
51     vector < FGHitRec > list;
52     double test_dist;
53
54 public:
55
56     FGHitList();
57     ~FGHitList();
58
59     void init(void) { list.clear(); test_dist=DBL_MAX; }
60     void clear(void) { init(); last = NULL; }
61     void add( ssgEntity *ent, int idx, sgdVec3 point, sgdVec3 normal ) {
62         list.push_back( FGHitRec( ent,idx,point,normal) );
63         last = ent;
64     }
65     int num_hits(void) { return list.size(); }
66     ssgEntity *get_entity(int i)  { return list[i].get_entity(); }
67     ssgEntity *last_hit(void)     { return last; }
68     int get_face(int i)           { return list[i].get_face(); }
69     double *get_point(int i)      { return list[i].get_point(); }
70     double *get_normal(int i)     { return list[i].get_normal(); }
71
72     void Intersect( ssgBranch *branch, sgdVec3 orig, sgdVec3 dir );
73     void Intersect( ssgBranch *scene, sgdMat4 m, sgdVec3 orig, sgdVec3 dir );
74
75     void IntersectBranch( ssgBranch *branch, sgdMat4 m, sgdVec3 orig, sgdVec3 dir);
76
77     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
78                        sgdVec3 orig, sgdVec3 dir );
79
80     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
81                        sgdVec3 orig, sgdVec3 dir,
82                        GLenum primType );
83 };
84
85
86 // Associated functions, assuming a wgs84 world with 0,0,0 at the
87 // center, find the current terrain intersection elevation for the
88 // point specified.
89 bool fgCurrentElev( sgdVec3 abs_view_pos,
90                     double max_alt_m,
91                     sgdVec3 scenery_center,
92                     ssgTransform *terra_transform,
93                     FGHitList *hit_list,
94                     double *terrain_elev,
95                     double *radius,
96                     double *normal );
97
98 bool fgCurrentElev( sgdVec3 abs_view_pos,
99                     double max_alt_m,
100                     sgdVec3 scenery_center,
101                     FGHitList *hit_list,
102                     double *terrain_elev,
103                     double *radius,
104                     double *normal );
105
106 #endif // _HITLIST_HXX