ExhibitSlots and exhibit placement (initial)
[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 ExSelection ExSelection::null;
8
9
10 // selection
11 ExSelection::ExSelection(Exhibit *ex)
12 {
13         this->ex = ex;
14         obj = data = 0;
15         validmask = 0;
16 }
17
18 ExSelection::operator bool() const
19 {
20         return ex != 0;
21 }
22
23 // Exhibit data
24 ExData::ExData()
25 {
26         voice = 0;
27 }
28
29 ExData::~ExData()
30 {
31         delete voice;
32 }
33
34 // exhibit class
35 Exhibit::Exhibit()
36 {
37         orig_parent = 0;
38         prev_slot = 0;
39 }
40
41 Exhibit::~Exhibit()
42 {
43 }
44
45 void Exhibit::set_node(SceneNode *node)
46 {
47         this->node = node;
48         orig_parent = node->get_parent();
49 }
50
51 ExSelection Exhibit::select(const Ray &ray) const
52 {
53         ExSelection sel;
54         HitPoint hit;
55         if(get_aabox().intersect(ray, &hit)) {
56                 sel.ex = (Exhibit*)this;
57                 sel.selray = ray;
58                 sel.dist = hit.dist;
59                 sel.validmask = EXSEL_RAY;
60         }
61         return sel;
62 }
63
64 ExSelection Exhibit::select(const Sphere &sph) const
65 {
66         return ExSelection(0);  // TODO
67 }
68
69 void Exhibit::update(float dt)
70 {
71 }
72
73 void Exhibit::pre_draw() const
74 {
75         if(node) {
76                 glMatrixMode(GL_MODELVIEW);
77                 glPushMatrix();
78                 glMultMatrixf(node->get_matrix()[0]);
79         }
80 }
81
82 void Exhibit::draw() const
83 {
84 }
85
86 void Exhibit::post_draw() const
87 {
88         if(node) {
89                 glMatrixMode(GL_MODELVIEW);
90                 glPopMatrix();
91
92                 if(exsel_hover.ex == this) {
93                         const AABox &bvol = get_aabox();
94                         draw_geom_object(&bvol);
95                 }
96         }
97 }
98
99
100 const AABox &Exhibit::get_aabox() const
101 {
102         aabb = node->get_bounds();
103         return aabb;
104 }