select and move exhibits
[laserbrain_demo] / src / exman.cc
index 6517b65..21e0074 100644 (file)
@@ -1,3 +1,4 @@
+#include <float.h>
 #include <algorithm>
 #include "exman.h"
 #include "exhibit.h"
@@ -103,13 +104,18 @@ bool ExhibitManager::load(MetaScene *mscn, const char *fname)
 
 ExSelection ExhibitManager::select(const Ray &ray) const
 {
-       ExSelection sel;
-       if(!items.empty()) {
-               sel.ex = items[0];
-               sel.selray = ray;
-               sel.validmask = EXSEL_RAY;
+       ExSelection nearest;
+       nearest.dist = FLT_MAX;
+
+       int nitems = items.size();
+       for(int i=0; i<nitems; i++) {
+               ExSelection sel = items[i]->select(ray);
+               if(sel && sel.dist < nearest.dist) {
+                       nearest = sel;
+               }
        }
-       return sel;     // TODO
+
+       return nearest;
 }
 
 ExSelection ExhibitManager::select(const Sphere &sph) const