goat3d

diff src/goat3d.cc @ 8:cd71f0b92f44

a bit more...
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 21 Aug 2013 05:52:28 +0300
parents 2918358f5e6d
children 04bb114fcf05
line diff
     1.1 --- a/src/goat3d.cc	Wed Aug 21 04:00:22 2013 +0300
     1.2 +++ b/src/goat3d.cc	Wed Aug 21 05:52:28 2013 +0300
     1.3 @@ -1,8 +1,6 @@
     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 @@ -43,14 +41,6 @@
    1.13  	name = "unnamed";
    1.14  }
    1.15  
    1.16 -static void delete_node_tree(Node *n)
    1.17 -{
    1.18 -	for(int i=0; i<n->get_num_children(); i++) {
    1.19 -		delete_node_tree(n->get_child(i));
    1.20 -	}
    1.21 -	delete n;
    1.22 -}
    1.23 -
    1.24  void Scene::set_name(const char *name)
    1.25  {
    1.26  	this->name = name;
    1.27 @@ -60,3 +50,123 @@
    1.28  {
    1.29  	return name.c_str();
    1.30  }
    1.31 +
    1.32 +void Scene::set_ambient(const Vector3 &amb)
    1.33 +{
    1.34 +	ambient = amb;
    1.35 +}
    1.36 +
    1.37 +const Vector3 &Scene::get_ambient() const
    1.38 +{
    1.39 +	return ambient;
    1.40 +}
    1.41 +
    1.42 +void Scene::add_material(Material *mat)
    1.43 +{
    1.44 +	materials.push_back(mat);
    1.45 +}
    1.46 +
    1.47 +Material *Scene::get_material(int idx) const
    1.48 +{
    1.49 +	return idx >=0 && idx < (int)materials.size() ? materials[idx] : 0;
    1.50 +}
    1.51 +
    1.52 +Material *Scene::get_material(const char *name) const
    1.53 +{
    1.54 +	for(size_t i=0; i<materials.size(); i++) {
    1.55 +		if(materials[i]->name == std::string(name)) {
    1.56 +			return materials[i];
    1.57 +		}
    1.58 +	}
    1.59 +	return 0;
    1.60 +}
    1.61 +
    1.62 +void Scene::add_mesh(Mesh *mesh)
    1.63 +{
    1.64 +	meshes.push_back(mesh);
    1.65 +}
    1.66 +
    1.67 +Mesh *Scene::get_mesh(int idx) const
    1.68 +{
    1.69 +	return idx >= 0 && idx < (int)meshes.size() ? meshes[idx] : 0;
    1.70 +}
    1.71 +
    1.72 +Mesh *Scene::get_mesh(const char *name) const
    1.73 +{
    1.74 +	for(size_t i=0; i<meshes.size(); i++) {
    1.75 +		if(meshes[i]->name == std::string(name)) {
    1.76 +			return meshes[i];
    1.77 +		}
    1.78 +	}
    1.79 +	return 0;
    1.80 +}
    1.81 +
    1.82 +void Scene::add_light(Light *light)
    1.83 +{
    1.84 +	lights.push_back(light);
    1.85 +}
    1.86 +
    1.87 +Light *Scene::get_light(int idx) const
    1.88 +{
    1.89 +	return idx >= 0 && idx < (int)lights.size() ? lights[idx] : 0;
    1.90 +}
    1.91 +
    1.92 +Light *Scene::get_light(const char *name) const
    1.93 +{
    1.94 +	for(size_t i=0; i<lights.size(); i++) {
    1.95 +		if(lights[i]->name == std::string(name)) {
    1.96 +			return lights[i];
    1.97 +		}
    1.98 +	}
    1.99 +	return 0;
   1.100 +}
   1.101 +
   1.102 +void Scene::add_camera(Camera *cam)
   1.103 +{
   1.104 +	cameras.push_back(cam);
   1.105 +}
   1.106 +
   1.107 +Camera *Scene::get_camera(int idx) const
   1.108 +{
   1.109 +	return idx >= 0 && idx < (int)cameras.size() ? cameras[idx] : 0;
   1.110 +}
   1.111 +
   1.112 +Camera *Scene::get_camera(const char *name) const
   1.113 +{
   1.114 +	for(size_t i=0; i<cameras.size(); i++) {
   1.115 +		if(cameras[i]->name == std::string(name)) {
   1.116 +			return cameras[i];
   1.117 +		}
   1.118 +	}
   1.119 +	return 0;
   1.120 +}
   1.121 +
   1.122 +void Scene::add_node(Node *node)
   1.123 +{
   1.124 +	nodes.push_back(node);
   1.125 +}
   1.126 +
   1.127 +Node *Scene::get_node(int idx) const
   1.128 +{
   1.129 +	return idx >= 0 && idx < (int)nodes.size() ? nodes[idx] : 0;
   1.130 +}
   1.131 +
   1.132 +Node *Scene::get_node(const char *name) const
   1.133 +{
   1.134 +	for(size_t i=0; i<nodes.size(); i++) {
   1.135 +		if(strcmp(nodes[i]->get_name(), name) == 0) {
   1.136 +			return nodes[i];
   1.137 +		}
   1.138 +	}
   1.139 +	return 0;
   1.140 +}
   1.141 +
   1.142 +bool Scene::load(goat3d_io *io)
   1.143 +{
   1.144 +	return false;
   1.145 +}
   1.146 +
   1.147 +bool Scene::save(goat3d_io *io) const
   1.148 +{
   1.149 +	return false;
   1.150 +}