]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/hitlist.hxx
Incorporated Norman's optimized line/geometry intersection code.
[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 #define FAST_HITLIST__TEST 1
19
20 SG_USING_STD(vector);
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() { last = NULL; test_dist=DBL_MAX; }
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,
71                     sgdVec3 orig, sgdVec3 dir );
72     void Intersect( ssgBranch *scene, sgdMat4 m,
73                     sgdVec3 orig, sgdVec3 dir );
74                 
75     void IntersectBranch( ssgBranch *branch, sgdMat4 m,
76                           sgdVec3 orig, sgdVec3 dir);
77                 
78     void IntersectCachedLeaf( sgdVec3 orig, sgdVec3 dir);
79                 
80     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
81                        sgdVec3 orig, sgdVec3 dir );
82
83     int IntersectPolyOrFanLeaf( ssgLeaf *leaf, sgdMat4 m,
84                                 sgdVec3 orig, sgdVec3 dir );
85
86     int IntersectTriLeaf( ssgLeaf *leaf, sgdMat4 m,
87                           sgdVec3 orig, sgdVec3 dir );
88         
89     int IntersectStripLeaf( ssgLeaf *leaf, sgdMat4 m,
90                             sgdVec3 orig, sgdVec3 dir );
91
92     int IntersectQuadsLeaf( ssgLeaf *leaf, sgdMat4 m,
93                             sgdVec3 orig, sgdVec3 dir );
94 };
95
96
97 // Associated function, assuming a wgs84 world with 0,0,0 at the
98 // center, find the current terrain intersection elevation for the
99 // point specified.
100 bool fgCurrentElev( sgdVec3 abs_view_pos,
101                     sgdVec3 scenery_center,
102                     ssgTransform *terra_transform,
103                     FGHitList *hit_list,
104                     double *terrain_elev,
105                     double *radius,
106                     double *normal );
107
108 bool fgCurrentElev( sgdVec3 abs_view_pos,
109                     sgdVec3 scenery_center,
110                     FGHitList *hit_list,
111                     double *terrain_elev,
112                     double *radius,
113                     double *normal );
114
115 #endif // _HITLIST_HXX