fixed div/zero in blob exhibit
authorJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 12 Jan 2018 04:43:25 +0000 (06:43 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Fri, 12 Jan 2018 04:43:25 +0000 (06:43 +0200)
src/app.cc
src/blob_exhibit.cc

index dcfd3f3..869af78 100644 (file)
@@ -79,6 +79,12 @@ bool app_init(int argc, char **argv)
 {
        set_log_file("demo.log");
 
 {
        set_log_file("demo.log");
 
+       char *env = getenv("FPEXCEPT");
+       if(env && atoi(env)) {
+               info_log("enabling floating point exceptions\n");
+               enable_fpexcept();
+       }
+
        if(init_opengl() == -1) {
                return false;
        }
        if(init_opengl() == -1) {
                return false;
        }
index 58522d9..c92ac7a 100644 (file)
@@ -23,6 +23,7 @@ static Metaball def_mball_data[] = {
 };
 
 struct BlobPriv {
 };
 
 struct BlobPriv {
+       AABox vol;
        metasurface *msurf;
        Metaball mballs[NUM_MBALLS];
        Texture *tex;
        metasurface *msurf;
        Metaball mballs[NUM_MBALLS];
        Texture *tex;
@@ -34,6 +35,7 @@ BlobExhibit::BlobExhibit()
        for(int i=0; i<NUM_MBALLS; i++) {
                priv->mballs[i] = def_mball_data[i];
        }
        for(int i=0; i<NUM_MBALLS; i++) {
                priv->mballs[i] = def_mball_data[i];
        }
+       priv->vol = AABox(Vec3(-3.5, -3.5, -3.5), Vec3(3.5, 3.5, 3.5));
 }
 
 BlobExhibit::~BlobExhibit()
 }
 
 BlobExhibit::~BlobExhibit()
@@ -49,7 +51,8 @@ bool BlobExhibit::init()
        }
        msurf_set_threshold(priv->msurf, 8);
        msurf_set_inside(priv->msurf, MSURF_GREATER);
        }
        msurf_set_threshold(priv->msurf, 8);
        msurf_set_inside(priv->msurf, MSURF_GREATER);
-       msurf_set_bounds(priv->msurf, -3.5, -3.5, -3.5, 3.5, 3.5, 3.5);
+       msurf_set_bounds(priv->msurf, priv->vol.min.x, priv->vol.min.y, priv->vol.min.z,
+                       priv->vol.max.x, priv->vol.max.y, priv->vol.max.z);
        msurf_enable(priv->msurf, MSURF_NORMALIZE);
 
        priv->tex = texman.get_texture("data/sphmap.jpg");
        msurf_enable(priv->msurf, MSURF_NORMALIZE);
 
        priv->tex = texman.get_texture("data/sphmap.jpg");
@@ -72,6 +75,10 @@ void BlobExhibit::update(float dt)
        float xmin, xmax, ymin, ymax, zmin, zmax;
        int xres, yres, zres;
 
        float xmin, xmax, ymin, ymax, zmin, zmax;
        int xres, yres, zres;
 
+       if(!msurf_voxels(priv->msurf)) {
+               return;
+       }
+
        msurf_get_bounds(priv->msurf, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax);
        msurf_get_resolution(priv->msurf, &xres, &yres, &zres);
 
        msurf_get_bounds(priv->msurf, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax);
        msurf_get_resolution(priv->msurf, &xres, &yres, &zres);
 
@@ -86,10 +93,6 @@ void BlobExhibit::update(float dt)
                priv->mballs[i].pos.z = -cos(t) * priv->mballs[i].path_scale.z + priv->mballs[i].path_offset.z;
        }
 
                priv->mballs[i].pos.z = -cos(t) * priv->mballs[i].path_scale.z + priv->mballs[i].path_offset.z;
        }
 
-       if(!msurf_voxels(priv->msurf)) {
-               return;
-       }
-
        float max_energy = 0.0f;
 
 #pragma omp parallel for
        float max_energy = 0.0f;
 
 #pragma omp parallel for
@@ -183,3 +186,10 @@ void BlobExhibit::draw() const
 
        glPopAttrib();
 }
 
        glPopAttrib();
 }
+
+const AABox &BlobExhibit::get_aabox() const
+{
+       Box box = Box(priv->vol, node->get_matrix());
+       calc_bounding_aabox(&aabb, &box);
+       return aabb;
+}