goat3d

diff src/scene.cc @ 75:76dea247f75c

in progress
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 May 2014 00:50:16 +0300
parents ab66cdabf6f2
children
line diff
     1.1 --- a/src/scene.cc	Tue May 06 13:26:52 2014 +0300
     1.2 +++ b/src/scene.cc	Thu May 08 00:50:16 2014 +0300
     1.3 @@ -26,6 +26,7 @@
     1.4  	: name("unnamed"), ambient(0.05, 0.05, 0.05)
     1.5  {
     1.6  	goat = 0;
     1.7 +	bbox_valid = false;
     1.8  }
     1.9  
    1.10  Scene::~Scene()
    1.11 @@ -61,6 +62,7 @@
    1.12  	nodes.clear();
    1.13  
    1.14  	name = "unnamed";
    1.15 +	bbox_valid = false;
    1.16  }
    1.17  
    1.18  void Scene::set_name(const char *name)
    1.19 @@ -222,6 +224,24 @@
    1.20  	return (int)nodes.size();
    1.21  }
    1.22  
    1.23 +const AABox &Scene::get_bounds() const
    1.24 +{
    1.25 +	if(!bbox_valid) {
    1.26 +		bbox = AABox();
    1.27 +
    1.28 +		for(size_t i=0; i<nodes.size(); i++) {
    1.29 +			if(nodes[i]->get_parent()) {
    1.30 +				continue;
    1.31 +			}
    1.32 +
    1.33 +			bbox = aabox_union(bbox, nodes[i]->get_bounds());
    1.34 +		}
    1.35 +		bbox_valid = true;
    1.36 +	}
    1.37 +
    1.38 +	return bbox;
    1.39 +}
    1.40 +
    1.41  // Scene::load is defined in goat3d_read.cc
    1.42  // Scene::loadxml is defined in goat3d_readxml.cc
    1.43  // Scene::save is defined in goat3d_write.cc