# HG changeset patch # User John Tsiombikas # Date 1399545825 -10800 # Node ID 9785847d52d4e780f3aa60a19847bfa281d364ad # Parent 76dea247f75cef29930c4053d3ba083ae443f813 bounding boxes calculation (untested) and automatic camera placement in goatview diff -r 76dea247f75c -r 9785847d52d4 goat3d.vcxproj --- a/goat3d.vcxproj Thu May 08 00:50:16 2014 +0300 +++ b/goat3d.vcxproj Thu May 08 13:43:45 2014 +0300 @@ -31,6 +31,7 @@ + @@ -55,6 +56,7 @@ + diff -r 76dea247f75c -r 9785847d52d4 goat3d.vcxproj.filters --- a/goat3d.vcxproj.filters Thu May 08 00:50:16 2014 +0300 +++ b/goat3d.vcxproj.filters Thu May 08 13:43:45 2014 +0300 @@ -3,7 +3,7 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h {bbf568eb-077e-4cb6-8607-e6a016ab7360} @@ -88,6 +88,9 @@ libs\openctm\liblzma + + src + @@ -165,5 +168,8 @@ src + + src + \ No newline at end of file diff -r 76dea247f75c -r 9785847d52d4 goatview/goatview.vcxproj --- a/goatview/goatview.vcxproj Thu May 08 00:50:16 2014 +0300 +++ b/goatview/goatview.vcxproj Thu May 08 13:43:45 2014 +0300 @@ -98,11 +98,12 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)\src Console true - goat3d-x64.lib;qtmaind.lib;Qt5Cored.lib;Qt5Widgetsd.lib;Qt5OpenGLd.lib;opengl32.lib;libvmath-x64-dbg.lib;libanim-x64-dbg.lib;pthreadVC2_x64.lib;%(AdditionalDependencies) + goat3d-x64.lib;qtmaind.lib;Qt5Cored.lib;Qt5Widgetsd.lib;Qt5OpenGLd.lib;opengl32.lib;glu32.lib;libvmath-x64-dbg.lib;libanim-x64-dbg.lib;pthreadVC2_x64.lib;%(AdditionalDependencies) $(OutDir);%(AdditionalLibraryDirectories) @@ -148,13 +149,14 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir)\src Console true true true - goat3d-x64.lib;qtmain.lib;Qt5Widgets.lib;Qt5OpenGL.lib;opengl32.lib;libvmath-x64.lib;libanim-x64.lib;pthreadVC2_x64.lib;%(AdditionalDependencies) + goat3d-x64.lib;qtmain.lib;Qt5Widgets.lib;Qt5OpenGL.lib;opengl32.lib;glu32.lib;libvmath-x64.lib;libanim-x64.lib;pthreadVC2_x64.lib;%(AdditionalDependencies) $(OutDir) diff -r 76dea247f75c -r 9785847d52d4 goatview/src/goatview.cc --- a/goatview/src/goatview.cc Thu May 08 00:50:16 2014 +0300 +++ b/goatview/src/goatview.cc Thu May 08 13:43:45 2014 +0300 @@ -1,4 +1,6 @@ +#include #include +#include #include "goatview.h" #include "goat3d.h" @@ -7,7 +9,25 @@ static long anim_time; static float cam_theta, cam_phi, cam_dist = 8; +static float fov = 60.0; +bool load_scene(const char *fname) +{ + if(scene) { + goat3d_free(scene); + } + if(!(scene = goat3d_create()) || goat3d_load(scene, fname) == -1) { + return false; + } + + float bmin[3], bmax[3]; + goat3d_get_bounds(scene, bmin, bmax); + float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length(); + cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0) + bsize; + + printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist); + return true; +} GoatView::GoatView() { @@ -101,12 +121,8 @@ return; } - if(scene) { - goat3d_free(scene); - } - statusBar()->showMessage("opening scene file"); - if(!(scene = goat3d_create()) || goat3d_load(scene, fname.c_str()) == -1) { + if(!load_scene(fname.c_str())) { statusBar()->showMessage("failed to load scene file"); } } @@ -207,6 +223,4 @@ for(int i=0; iscn->get_ambient().x; } +GOAT3DAPI void goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax) +{ + AABox bbox = g->scn->get_bounds(); + for(int i=0; i<3; i++) { + bmin[i] = bbox.bmin[i]; + bmax[i] = bbox.bmax[i]; + } +} + // ---- materials ---- GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl) { diff -r 76dea247f75c -r 9785847d52d4 src/goat3d.h --- a/src/goat3d.h Thu May 08 00:50:16 2014 +0300 +++ b/src/goat3d.h Thu May 08 13:43:45 2014 +0300 @@ -123,6 +123,8 @@ GOAT3DAPI void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab); GOAT3DAPI const float *goat3d_get_ambient(const struct goat3d *g); +GOAT3DAPI void goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax); + /* materials */ GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl); GOAT3DAPI int goat3d_get_mtl_count(struct goat3d *g); diff -r 76dea247f75c -r 9785847d52d4 src/mesh.cc --- a/src/mesh.cc Thu May 08 00:50:16 2014 +0300 +++ b/src/mesh.cc Thu May 08 13:43:45 2014 +0300 @@ -228,3 +228,22 @@ { return material; } + +AABox Mesh::get_bounds(const Matrix4x4 &xform) const +{ + AABox bbox; + + for(size_t i=0; i bbox.bmax[j]) { + bbox.bmax[j] = v[j]; + } + } + } + return bbox; +} \ No newline at end of file diff -r 76dea247f75c -r 9785847d52d4 src/mesh.h --- a/src/mesh.h Thu May 08 00:50:16 2014 +0300 +++ b/src/mesh.h Thu May 08 13:43:45 2014 +0300 @@ -61,7 +61,7 @@ Material *get_material(); const Material *get_material() const; - AABox get_bounds() const; + AABox get_bounds(const Matrix4x4 &xform) const; }; } // namespace g3dimpl diff -r 76dea247f75c -r 9785847d52d4 src/node.cc --- a/src/node.cc Thu May 08 00:50:16 2014 +0300 +++ b/src/node.cc Thu May 08 13:43:45 2014 +0300 @@ -47,7 +47,9 @@ const AABox &Node::get_bounds() const { if(!bbox_valid) { - bbox = obj ? obj->get_bounds() : AABox(); + Matrix4x4 xform; + get_xform(0, &xform); + bbox = obj ? obj->get_bounds(xform) : AABox(); for(int i=0; iget_bounds());