266a5835da32100a90b95028c14842cfbc8e06ff
[laserbrain_demo] / src / exhibit.cc
1 #include "exhibit.h"
2 #include "snode.h"
3 #include "scene.h"
4 #include "geomdraw.h"
5 #include "app.h"
6
7 class ExhibitPriv {
8 public:
9         Vec3 orig_pos;
10         Quat orig_rot;
11         SceneNode *orig_node;
12
13         ExhibitPriv();
14 };
15
16
17 // selection
18 ExSelection::ExSelection(Exhibit *ex)
19 {
20         this->ex = ex;
21         obj = data = 0;
22         validmask = 0;
23 }
24
25 ExSelection::operator bool() const
26 {
27         return ex != 0;
28 }
29
30 // Exhibit data
31 ExData::ExData()
32 {
33         voice = 0;
34 }
35
36 ExData::~ExData()
37 {
38         delete voice;
39 }
40
41 // private data for each exhibit type
42 ExhibitPriv::ExhibitPriv()
43 {
44         orig_node = 0;
45 }
46
47 // exhibit class
48 Exhibit::Exhibit()
49 {
50         priv = new ExhibitPriv;
51 }
52
53 Exhibit::~Exhibit()
54 {
55         delete priv;
56 }
57
58 void Exhibit::set_node(SceneNode *node)
59 {
60         this->node = priv->orig_node = node;
61         priv->orig_pos = node->get_position();
62         priv->orig_rot = node->get_rotation();
63 }
64
65 ExSelection Exhibit::select(const Ray &ray) const
66 {
67         ExSelection sel;
68         HitPoint hit;
69         if(get_aabox().intersect(ray, &hit)) {
70                 sel.ex = (Exhibit*)this;
71                 sel.selray = ray;
72                 sel.dist = hit.dist;
73                 sel.validmask = EXSEL_RAY;
74         }
75         return sel;
76 }
77
78 ExSelection Exhibit::select(const Sphere &sph) const
79 {
80         return ExSelection(0);  // TODO
81 }
82
83 void Exhibit::update(float dt)
84 {
85 }
86
87 void Exhibit::pre_draw() const
88 {
89         if(node) {
90                 glMatrixMode(GL_MODELVIEW);
91                 glPushMatrix();
92                 glMultMatrixf(node->get_matrix()[0]);
93         }
94 }
95
96 void Exhibit::draw() const
97 {
98 }
99
100 void Exhibit::post_draw() const
101 {
102         if(node) {
103                 glMatrixMode(GL_MODELVIEW);
104                 glPopMatrix();
105
106                 if(exsel_hover.ex == this) {
107                         const AABox &bvol = get_aabox();
108                         draw_geom_object(&bvol);
109                 }
110         }
111 }
112
113
114 const AABox &Exhibit::get_aabox() const
115 {
116         aabb = node->get_bounds();
117         return aabb;
118 }