d7d64fa861b0c3437109a1be8c1eaf76b35f44b9
[laserbrain_demo] / src / exman.h
1 #ifndef EXMAN_H_
2 #define EXMAN_H_
3
4 #include <vector>
5 #include "exhibit.h"
6 #include "metascene.h"
7
8 //! argument to ExhibitSlot::attach
9 enum ExSlotAttachMode {
10         EXSLOT_ATTACH_PERMANENT,
11         EXSLOT_ATTACH_TRANSIENT
12 };
13
14 //! slot which can hold a single exhibit
15 class ExhibitSlot {
16 private:
17         Exhibit *ex;
18
19 public:
20         Quat rotation;
21         SceneNode node;
22
23         ExhibitSlot(Exhibit *ex = 0);
24         ~ExhibitSlot();
25
26         void init(Exhibit *ex);
27
28         bool empty() const;
29         Exhibit *get_exhibit() const;
30
31         bool attach_exhibit(Exhibit *ex, ExSlotAttachMode mode = EXSLOT_ATTACH_PERMANENT);
32         bool detach_exhibit();
33 };
34
35
36 class ExhibitManager {
37 private:
38         std::vector<Exhibit*> items, stashed;
39         std::vector<ExhibitSlot*> exslots;
40         // TODO kdtree of slots for quick nearest queries
41
42         Scene *own_scn; // scene to manage all exhibits not taken from an existing scene
43
44 public:
45         ExhibitManager();
46         ~ExhibitManager();
47
48         void clear();
49
50         void add(Exhibit *ex);
51         bool remove(Exhibit *ex);
52
53         bool load(MetaScene *mscn, const char *fname);
54
55         ExSelection select(const Ray &ray) const;
56         ExSelection select(const Sphere &sph) const;
57
58         ExhibitSlot *nearest_empty_slot(const Vec3 &pos, float max_dist = 10) const;
59
60         void stash_exhibit(Exhibit *ex);
61
62         void update(float dt = 0.0f);
63         void draw() const;
64 };
65
66 #endif  // EXMAN_H_