From 5ce504b61cdb88166133d5977a2faad1664c850f Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 13 Mar 2018 12:11:50 +0200 Subject: [PATCH] adding mirror plane options other than auto --- src/app.cc | 7 +++---- src/dataset.h | 2 +- src/dataset.inl | 3 ++- src/geom.h | 1 + src/material.h | 13 ++++++++++++- src/metascene.cc | 21 +++++++++++++-------- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/app.cc b/src/app.cc index 7b4280d..b61b0e7 100644 --- a/src/app.cc +++ b/src/app.cc @@ -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; diff --git a/src/dataset.h b/src/dataset.h index 38fec6b..2ea13eb 100644 --- a/src/dataset.h +++ b/src/dataset.h @@ -49,7 +49,7 @@ public: ~DataSet(); void clear(); - void update(); + void update(long timeslice = 20); T get(const char *name) const; diff --git a/src/dataset.inl b/src/dataset.inl index 41277a1..f348709 100644 --- a/src/dataset.inl +++ b/src/dataset.inl @@ -32,8 +32,9 @@ void DataSet::clear() } template -void DataSet::update() +void DataSet::update(long timeslice) { + resman_setopt(rman, RESMAN_OPT_TIMESLICE, timeslice); resman_poll(rman); } diff --git a/src/geom.h b/src/geom.h index f9b88e5..5de6a62 100644 --- a/src/geom.h +++ b/src/geom.h @@ -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; diff --git a/src/material.h b/src/material.h index 3d0b566..a1244d4 100644 --- a/src/material.h +++ b/src/material.h @@ -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 textures; diff --git a/src/metascene.cc b/src/metascene.cc index c467420..09527e9 100644 --- a/src/metascene.cc +++ b/src/metascene.cc @@ -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) { -- 1.7.10.4