]> git.mxchange.org Git - flightgear.git/blob - src/Scenery/hitlist.hxx
Continuing work on cleanups.
[flightgear.git] / src / Scenery / hitlist.hxx
1 #ifndef _HITLIST_HXX
2 #define _HITLIST_HXX
3
4 #ifndef __cplusplus                                                          
5 # error This library requires C++
6 #endif                                   
7
8 #include <simgear/compiler.h>
9
10 #include <vector>
11
12 #include <plib/ssg.h>
13
14 FG_USING_STD(vector);
15
16
17 class FGHitRec {
18
19 private:
20     ssgEntity *ent;
21     int index;
22     sgdVec3 point;
23     sgdVec3 normal;
24
25 public:
26
27     FGHitRec( ssgEntity *e, int idx, sgdVec3 p, sgdVec3 n ) {
28         ent = e;
29         index = idx;
30         sgdSetVec3(point,p[0],p[1],p[2]);
31         sgdSetVec3(normal,n[0],n[1],n[2]);
32     }
33
34     ssgEntity *get_entity(void) { return ent; }
35     int get_face(void)          { return index; }
36     double *get_point(void)     { return point; }
37     double *get_normal(void)    { return normal; }
38 };
39
40
41 class FGHitList {
42
43 private:
44
45     ssgEntity *last;
46     vector < FGHitRec > list;
47
48 public:
49
50     FGHitList() { last = NULL; }
51     void init(void) { list.clear(); }
52     void clear(void) { init(); last = NULL; }
53     void add( ssgEntity *ent, int idx, sgdVec3 point, sgdVec3 normal ) {
54         list.push_back( FGHitRec( ent,idx,point,normal) );
55         last = ent;
56     }
57     int num_hits(void) { return list.size(); }
58     ssgEntity *get_entity(int i)  { return list[i].get_entity(); }
59     ssgEntity *last_hit(void)     { return last; }
60     int get_face(int i)           { return list[i].get_face(); }
61     double *get_point(int i)      { return list[i].get_point(); }
62     double *get_normal(int i)     { return list[i].get_normal(); }
63                 
64     void Intersect( ssgBranch *branch,
65                     sgdVec3 orig, sgdVec3 dir );
66                 
67     void IntersectBranch( ssgBranch *branch, sgdMat4 m,
68                           sgdVec3 orig, sgdVec3 dir);
69                 
70     void IntersectCachedLeaf( sgdMat4 m,
71                               sgdVec3 orig, sgdVec3 dir);
72                 
73     int IntersectLeaf( ssgLeaf *leaf, sgdMat4 m,
74                        sgdVec3 orig, sgdVec3 dir );
75 };
76
77
78 inline void FGHitList::Intersect( ssgBranch *scene,
79                                   sgdVec3 orig, sgdVec3 dir )
80 {
81     sgdMat4 m;
82
83     init();
84
85     if( last_hit() ) {
86         sgdMakeIdentMat4 ( m ) ;
87         IntersectCachedLeaf(m, orig, dir);
88     }
89     if( ! num_hits() ) {
90         clear();
91         sgdMakeIdentMat4 ( m ) ;
92         IntersectBranch( scene, m, orig, dir);
93     }
94 }
95
96 #endif // _HITLIST_HXX