X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fblob_exhibit.cc;h=3d133961159302e12c92e7a344b348dbc3bac9cd;hp=1dcc80e3d0a906750e4066b77b2daf78f594a43d;hb=b75b6703809abf0dc02f2e557ba73e9efbefa4d1;hpb=004eca3966c8cc7bed607311a90d56eecab1752f diff --git a/src/blob_exhibit.cc b/src/blob_exhibit.cc index 1dcc80e..3d13396 100644 --- a/src/blob_exhibit.cc +++ b/src/blob_exhibit.cc @@ -1,6 +1,7 @@ #include "blob_exhibit.h" #include "blobs/metasurf.h" #include "app.h" +#include struct Metaball { Vec3 pos; @@ -27,10 +28,6 @@ struct BlobPriv { Texture *tex; }; -static void vertex(struct metasurface *ms, float x, float y, float z); -static float eval(struct metasurface *ms, float x, float y, float z); - - BlobExhibit::BlobExhibit() { priv = new BlobPriv; @@ -41,6 +38,7 @@ BlobExhibit::BlobExhibit() BlobExhibit::~BlobExhibit() { + destroy(); delete priv; } @@ -49,12 +47,10 @@ bool BlobExhibit::init() if(!(priv->msurf = msurf_create())) { return false; } - msurf_set_user_data(priv->msurf, priv); 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_eval_func(priv->msurf, eval); - msurf_vertex_func(priv->msurf, vertex); + msurf_enable(priv->msurf, MSURF_NORMALIZE); priv->tex = texman.get_texture("data/sphmap.jpg"); return true; @@ -62,32 +58,78 @@ bool BlobExhibit::init() void BlobExhibit::destroy() { - msurf_free(priv->msurf); - priv->msurf = 0; + if(priv->msurf) { + msurf_free(priv->msurf); + priv->msurf = 0; + } } void BlobExhibit::update(float dt) { double sec = time_msec / 1000.0; + float xmin, xmax, ymin, ymax, zmin, zmax; + int xres, yres, zres; + + msurf_get_bounds(priv->msurf, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax); + msurf_get_resolution(priv->msurf, &xres, &yres, &zres); + + float xstep = (xmax - xmin) / xres; + float ystep = (ymax - ymin) / yres; + float zstep = (zmax - zmin) / zres; + for(int i=0; imballs[i].speed + priv->mballs[i].phase_offset, M_PI * 2.0); priv->mballs[i].pos.x = cos(t) * priv->mballs[i].path_scale.x + priv->mballs[i].path_offset.x; priv->mballs[i].pos.y = sin(t) * priv->mballs[i].path_scale.y + priv->mballs[i].path_offset.y; 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 + for(int i=0; imsurf, i); + if(!voxptr) break; + + for(int j=0; jmballs[n].pos.x; + float dy = y - priv->mballs[n].pos.y; + float dz = z - priv->mballs[n].pos.z; + float dsq = dx * dx + dy * dy + dz * dz; + + sum += priv->mballs[n].energy / dsq; + } + *voxptr++ = sum; + if(sum > max_energy) max_energy = sum; + } + } + } + + msurf_polygonize(priv->msurf); } void BlobExhibit::draw() const { - pre_draw(); - glPushAttrib(GL_ENABLE_BIT); glUseProgram(0); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); + glEnable(GL_NORMALIZE); priv->tex->bind(); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); @@ -95,43 +137,49 @@ void BlobExhibit::draw() const glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glScalef(1, -1, 1); + glFrontFace(GL_CW); + + + int nverts = msurf_vertex_count(priv->msurf); + float *varr = msurf_vertices(priv->msurf); + float *narr = msurf_normals(priv->msurf); + glBegin(GL_TRIANGLES); glColor3f(1, 1, 1); - msurf_polygonize(priv->msurf); + for(int i=0; imsurf); + narr = msurf_normals(priv->msurf); - glNormal3f(dfdx, dfdy, dfdz); - glVertex3f(x, y, z); -} + glBegin(GL_LINES); + glColor3f(0, 1, 0); -static float eval(struct metasurface *ms, float x, float y, float z) -{ - float sum = 0.0f; - BlobPriv *priv = (BlobPriv*)msurf_get_user_data(ms); + float nscale = 0.2; + for(int i=0; imballs[i].pos.x; - float dy = y - priv->mballs[i].pos.y; - float dz = z - priv->mballs[i].pos.z; - float dsq = dx * dx + dy * dy + dz * dz; + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); - sum += priv->mballs[i].energy / dsq; - } - return sum; + glPopAttrib(); }