adding mirror plane options other than auto
authorJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 13 Mar 2018 10:11:50 +0000 (12:11 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 13 Mar 2018 10:11:50 +0000 (12:11 +0200)
src/app.cc
src/dataset.h
src/dataset.inl
src/geom.h
src/material.h
src/metascene.cc

index 7b4280d..b61b0e7 100644 (file)
@@ -210,6 +210,9 @@ bool app_init(int argc, char **argv)
 
 static void post_scene_init()
 {
+       int num_mir = mscn->calc_mirror_planes();
+       info_log("found %d mirror planes\n", num_mir);
+
        exman->load(mscn, "data/exhibits");
 }
 
@@ -641,10 +644,6 @@ void app_keyboard(int key, bool pressed)
                        show_message("VR recenter\n");
                        break;
 
-               case 'x':
-                       exman->load(mscn, "data/exhibits");
-                       break;
-
                case KEY_UP:
                        exui_scroll(-1);
                        break;
index 38fec6b..2ea13eb 100644 (file)
@@ -49,7 +49,7 @@ public:
        ~DataSet();
 
        void clear();
-       void update();
+       void update(long timeslice = 20);
 
        T get(const char *name) const;
 
index 41277a1..f348709 100644 (file)
@@ -32,8 +32,9 @@ void DataSet<T>::clear()
 }
 
 template <typename T>
-void DataSet<T>::update()
+void DataSet<T>::update(long timeslice)
 {
+       resman_setopt(rman, RESMAN_OPT_TIMESLICE, timeslice);
        resman_poll(rman);
 }
 
index f9b88e5..5de6a62 100644 (file)
@@ -76,6 +76,7 @@ public:
        virtual void invalidate();
 
        virtual Vec3 get_corner(int idx) const;
+       virtual Plane get_plane(int pidx) const;
 
        virtual bool intersect(const Ray &ray, HitPoint *hit = 0) const;
        virtual bool contains(const Vec3 &pt) const;
index 3d0b566..a1244d4 100644 (file)
@@ -16,6 +16,17 @@ enum {
        MTL_TEX_UNKNOWN
 };
 
+enum {
+       MTL_MIRROR_NONE,
+       MTL_MIRROR_AUTO,                // determine mirror plane automatically
+       MTL_MIRROR_AABB_PX,             // plane = AABB +X side
+       MTL_MIRROR_AABB_NX,             // plane = AABB -X side
+       MTL_MIRROR_AABB_PY,             // plane = AABB +Y side
+       MTL_MIRROR_AABB_NY,             // plane = AABB -Y side
+       MTL_MIRROR_AABB_PZ,             // plane = AABB +Z side
+       MTL_MIRROR_AABB_NZ              // plane = AABB -Z side
+};
+
 #define NUM_MTL_TEXTURES       MTL_TEX_UNKNOWN
 
 class Material {
@@ -26,7 +37,7 @@ public:
        float alpha;
 
        float reflect;
-       bool flat_mirror;
+       int flat_mirror;        // see MTL_MIRROR_* enumerations above
 
        Texture *stdtex[NUM_MTL_TEXTURES];
        std::vector<Texture*> textures;
index c467420..09527e9 100644 (file)
@@ -223,25 +223,30 @@ int MetaScene::calc_mirror_planes()
                                const Mesh *mesh = ((ObjMesh*)obj)->mesh;
                                if(!mesh) continue;
 
-                               // assume the object is actually flat, so grab the first triangle and make a plane
-                               Triangle face = Triangle(0, (const Vec3*)mesh->get_attrib_data(MESH_ATTR_VERTEX),
-                                               mesh->get_index_data());
-                               face.calc_normal();
-
                                FlatMirror *mir = new FlatMirror;
-                               mir->plane.pt = face.v[0];
-                               mir->plane.normal = face.normal;
                                mir->reflect = obj->mtl.reflect;
 
+                               if(obj->mtl.flat_mirror == MTL_MIRROR_AUTO) {
+                                       // assume the object is actually flat, so grab the first triangle and make a plane
+                                       Triangle face = Triangle(0, (const Vec3*)mesh->get_attrib_data(MESH_ATTR_VERTEX),
+                                                       mesh->get_index_data());
+                                       face.calc_normal();
+
+                                       mir->plane.pt = face.v[0];
+                                       mir->plane.normal = face.normal;
+                               } else {
+                               }
+
                                // check to see if we have found this mirror plane already
                                bool found = false;
                                FlatMirror *node = mirrors;
                                while(node) {
-                                       if(fabs(dot(mir->plane.normal, node->plane.normal)) < 1e-4 &&
+                                       if(1.0f - dot(mir->plane.normal, node->plane.normal) < 1e-4f &&
                                                        fabs(dot(mir->plane.normal, normalize(mir->plane.pt - node->plane.pt))) < 1e-4) {
                                                found = true;
                                                break;
                                        }
+                                       node = node->next;
                                }
 
                                if(!found) {