select and move exhibits
[laserbrain_demo] / src / exhibit.cc
index e98a2ba..266a583 100644 (file)
@@ -1,13 +1,20 @@
 #include "exhibit.h"
 #include "snode.h"
+#include "scene.h"
+#include "geomdraw.h"
+#include "app.h"
 
 class ExhibitPriv {
 public:
        Vec3 orig_pos;
        Quat orig_rot;
        SceneNode *orig_node;
+
+       ExhibitPriv();
 };
 
+
+// selection
 ExSelection::ExSelection(Exhibit *ex)
 {
        this->ex = ex;
@@ -20,10 +27,27 @@ ExSelection::operator bool() const
        return ex != 0;
 }
 
+// Exhibit data
+ExData::ExData()
+{
+       voice = 0;
+}
+
+ExData::~ExData()
+{
+       delete voice;
+}
+
+// private data for each exhibit type
+ExhibitPriv::ExhibitPriv()
+{
+       orig_node = 0;
+}
+
+// exhibit class
 Exhibit::Exhibit()
 {
        priv = new ExhibitPriv;
-       priv->orig_node = 0;
 }
 
 Exhibit::~Exhibit()
@@ -31,14 +55,29 @@ Exhibit::~Exhibit()
        delete priv;
 }
 
+void Exhibit::set_node(SceneNode *node)
+{
+       this->node = priv->orig_node = node;
+       priv->orig_pos = node->get_position();
+       priv->orig_rot = node->get_rotation();
+}
+
 ExSelection Exhibit::select(const Ray &ray) const
 {
-       return ExSelection(0);
+       ExSelection sel;
+       HitPoint hit;
+       if(get_aabox().intersect(ray, &hit)) {
+               sel.ex = (Exhibit*)this;
+               sel.selray = ray;
+               sel.dist = hit.dist;
+               sel.validmask = EXSEL_RAY;
+       }
+       return sel;
 }
 
 ExSelection Exhibit::select(const Sphere &sph) const
 {
-       return ExSelection(0);
+       return ExSelection(0);  // TODO
 }
 
 void Exhibit::update(float dt)
@@ -63,5 +102,17 @@ void Exhibit::post_draw() const
        if(node) {
                glMatrixMode(GL_MODELVIEW);
                glPopMatrix();
+
+               if(exsel_hover.ex == this) {
+                       const AABox &bvol = get_aabox();
+                       draw_geom_object(&bvol);
+               }
        }
 }
+
+
+const AABox &Exhibit::get_aabox() const
+{
+       aabb = node->get_bounds();
+       return aabb;
+}