goat3d

diff src/goat3d.cc @ 0:2918358f5e6d

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 17 Aug 2013 16:10:26 +0300
parents
children cd71f0b92f44
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/goat3d.cc	Sat Aug 17 16:10:26 2013 +0300
     1.3 @@ -0,0 +1,62 @@
     1.4 +#include "goat3d.h"
     1.5 +#include "goat3d_impl.h"
     1.6 +
     1.7 +static void delete_node_tree(Node *n);
     1.8 +
     1.9 +Scene::Scene()
    1.10 +	: name("unnamed"), ambient(0.05, 0.05, 0.05)
    1.11 +{
    1.12 +}
    1.13 +
    1.14 +Scene::~Scene()
    1.15 +{
    1.16 +	clear();
    1.17 +}
    1.18 +
    1.19 +void Scene::clear()
    1.20 +{
    1.21 +	for(size_t i=0; i<materials.size(); i++) {
    1.22 +		delete materials[i];
    1.23 +	}
    1.24 +	materials.clear();
    1.25 +
    1.26 +	for(size_t i=0; i<meshes.size(); i++) {
    1.27 +		delete meshes[i];
    1.28 +	}
    1.29 +	meshes.clear();
    1.30 +
    1.31 +	for(size_t i=0; i<lights.size(); i++) {
    1.32 +		delete lights[i];
    1.33 +	}
    1.34 +	lights.clear();
    1.35 +
    1.36 +	for(size_t i=0; i<cameras.size(); i++) {
    1.37 +		delete cameras[i];
    1.38 +	}
    1.39 +	cameras.clear();
    1.40 +
    1.41 +	for(size_t i=0; i<nodes.size(); i++) {
    1.42 +		delete_node_tree(nodes[i]);
    1.43 +	}
    1.44 +	nodes.clear();
    1.45 +
    1.46 +	name = "unnamed";
    1.47 +}
    1.48 +
    1.49 +static void delete_node_tree(Node *n)
    1.50 +{
    1.51 +	for(int i=0; i<n->get_num_children(); i++) {
    1.52 +		delete_node_tree(n->get_child(i));
    1.53 +	}
    1.54 +	delete n;
    1.55 +}
    1.56 +
    1.57 +void Scene::set_name(const char *name)
    1.58 +{
    1.59 +	this->name = name;
    1.60 +}
    1.61 +
    1.62 +const char *Scene::get_name() const
    1.63 +{
    1.64 +	return name.c_str();
    1.65 +}