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