goat3d
annotate 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 |
rev | line source |
---|---|
nuclear@0 | 1 #include "goat3d.h" |
nuclear@0 | 2 #include "goat3d_impl.h" |
nuclear@0 | 3 |
nuclear@0 | 4 Scene::Scene() |
nuclear@0 | 5 : name("unnamed"), ambient(0.05, 0.05, 0.05) |
nuclear@0 | 6 { |
nuclear@0 | 7 } |
nuclear@0 | 8 |
nuclear@0 | 9 Scene::~Scene() |
nuclear@0 | 10 { |
nuclear@0 | 11 clear(); |
nuclear@0 | 12 } |
nuclear@0 | 13 |
nuclear@0 | 14 void Scene::clear() |
nuclear@0 | 15 { |
nuclear@0 | 16 for(size_t i=0; i<materials.size(); i++) { |
nuclear@0 | 17 delete materials[i]; |
nuclear@0 | 18 } |
nuclear@0 | 19 materials.clear(); |
nuclear@0 | 20 |
nuclear@0 | 21 for(size_t i=0; i<meshes.size(); i++) { |
nuclear@0 | 22 delete meshes[i]; |
nuclear@0 | 23 } |
nuclear@0 | 24 meshes.clear(); |
nuclear@0 | 25 |
nuclear@0 | 26 for(size_t i=0; i<lights.size(); i++) { |
nuclear@0 | 27 delete lights[i]; |
nuclear@0 | 28 } |
nuclear@0 | 29 lights.clear(); |
nuclear@0 | 30 |
nuclear@0 | 31 for(size_t i=0; i<cameras.size(); i++) { |
nuclear@0 | 32 delete cameras[i]; |
nuclear@0 | 33 } |
nuclear@0 | 34 cameras.clear(); |
nuclear@0 | 35 |
nuclear@0 | 36 for(size_t i=0; i<nodes.size(); i++) { |
nuclear@0 | 37 delete_node_tree(nodes[i]); |
nuclear@0 | 38 } |
nuclear@0 | 39 nodes.clear(); |
nuclear@0 | 40 |
nuclear@0 | 41 name = "unnamed"; |
nuclear@0 | 42 } |
nuclear@0 | 43 |
nuclear@0 | 44 void Scene::set_name(const char *name) |
nuclear@0 | 45 { |
nuclear@0 | 46 this->name = name; |
nuclear@0 | 47 } |
nuclear@0 | 48 |
nuclear@0 | 49 const char *Scene::get_name() const |
nuclear@0 | 50 { |
nuclear@0 | 51 return name.c_str(); |
nuclear@0 | 52 } |
nuclear@8 | 53 |
nuclear@8 | 54 void Scene::set_ambient(const Vector3 &amb) |
nuclear@8 | 55 { |
nuclear@8 | 56 ambient = amb; |
nuclear@8 | 57 } |
nuclear@8 | 58 |
nuclear@8 | 59 const Vector3 &Scene::get_ambient() const |
nuclear@8 | 60 { |
nuclear@8 | 61 return ambient; |
nuclear@8 | 62 } |
nuclear@8 | 63 |
nuclear@8 | 64 void Scene::add_material(Material *mat) |
nuclear@8 | 65 { |
nuclear@8 | 66 materials.push_back(mat); |
nuclear@8 | 67 } |
nuclear@8 | 68 |
nuclear@8 | 69 Material *Scene::get_material(int idx) const |
nuclear@8 | 70 { |
nuclear@8 | 71 return idx >=0 && idx < (int)materials.size() ? materials[idx] : 0; |
nuclear@8 | 72 } |
nuclear@8 | 73 |
nuclear@8 | 74 Material *Scene::get_material(const char *name) const |
nuclear@8 | 75 { |
nuclear@8 | 76 for(size_t i=0; i<materials.size(); i++) { |
nuclear@8 | 77 if(materials[i]->name == std::string(name)) { |
nuclear@8 | 78 return materials[i]; |
nuclear@8 | 79 } |
nuclear@8 | 80 } |
nuclear@8 | 81 return 0; |
nuclear@8 | 82 } |
nuclear@8 | 83 |
nuclear@8 | 84 void Scene::add_mesh(Mesh *mesh) |
nuclear@8 | 85 { |
nuclear@8 | 86 meshes.push_back(mesh); |
nuclear@8 | 87 } |
nuclear@8 | 88 |
nuclear@8 | 89 Mesh *Scene::get_mesh(int idx) const |
nuclear@8 | 90 { |
nuclear@8 | 91 return idx >= 0 && idx < (int)meshes.size() ? meshes[idx] : 0; |
nuclear@8 | 92 } |
nuclear@8 | 93 |
nuclear@8 | 94 Mesh *Scene::get_mesh(const char *name) const |
nuclear@8 | 95 { |
nuclear@8 | 96 for(size_t i=0; i<meshes.size(); i++) { |
nuclear@8 | 97 if(meshes[i]->name == std::string(name)) { |
nuclear@8 | 98 return meshes[i]; |
nuclear@8 | 99 } |
nuclear@8 | 100 } |
nuclear@8 | 101 return 0; |
nuclear@8 | 102 } |
nuclear@8 | 103 |
nuclear@8 | 104 void Scene::add_light(Light *light) |
nuclear@8 | 105 { |
nuclear@8 | 106 lights.push_back(light); |
nuclear@8 | 107 } |
nuclear@8 | 108 |
nuclear@8 | 109 Light *Scene::get_light(int idx) const |
nuclear@8 | 110 { |
nuclear@8 | 111 return idx >= 0 && idx < (int)lights.size() ? lights[idx] : 0; |
nuclear@8 | 112 } |
nuclear@8 | 113 |
nuclear@8 | 114 Light *Scene::get_light(const char *name) const |
nuclear@8 | 115 { |
nuclear@8 | 116 for(size_t i=0; i<lights.size(); i++) { |
nuclear@8 | 117 if(lights[i]->name == std::string(name)) { |
nuclear@8 | 118 return lights[i]; |
nuclear@8 | 119 } |
nuclear@8 | 120 } |
nuclear@8 | 121 return 0; |
nuclear@8 | 122 } |
nuclear@8 | 123 |
nuclear@8 | 124 void Scene::add_camera(Camera *cam) |
nuclear@8 | 125 { |
nuclear@8 | 126 cameras.push_back(cam); |
nuclear@8 | 127 } |
nuclear@8 | 128 |
nuclear@8 | 129 Camera *Scene::get_camera(int idx) const |
nuclear@8 | 130 { |
nuclear@8 | 131 return idx >= 0 && idx < (int)cameras.size() ? cameras[idx] : 0; |
nuclear@8 | 132 } |
nuclear@8 | 133 |
nuclear@8 | 134 Camera *Scene::get_camera(const char *name) const |
nuclear@8 | 135 { |
nuclear@8 | 136 for(size_t i=0; i<cameras.size(); i++) { |
nuclear@8 | 137 if(cameras[i]->name == std::string(name)) { |
nuclear@8 | 138 return cameras[i]; |
nuclear@8 | 139 } |
nuclear@8 | 140 } |
nuclear@8 | 141 return 0; |
nuclear@8 | 142 } |
nuclear@8 | 143 |
nuclear@8 | 144 void Scene::add_node(Node *node) |
nuclear@8 | 145 { |
nuclear@8 | 146 nodes.push_back(node); |
nuclear@8 | 147 } |
nuclear@8 | 148 |
nuclear@8 | 149 Node *Scene::get_node(int idx) const |
nuclear@8 | 150 { |
nuclear@8 | 151 return idx >= 0 && idx < (int)nodes.size() ? nodes[idx] : 0; |
nuclear@8 | 152 } |
nuclear@8 | 153 |
nuclear@8 | 154 Node *Scene::get_node(const char *name) const |
nuclear@8 | 155 { |
nuclear@8 | 156 for(size_t i=0; i<nodes.size(); i++) { |
nuclear@8 | 157 if(strcmp(nodes[i]->get_name(), name) == 0) { |
nuclear@8 | 158 return nodes[i]; |
nuclear@8 | 159 } |
nuclear@8 | 160 } |
nuclear@8 | 161 return 0; |
nuclear@8 | 162 } |
nuclear@8 | 163 |
nuclear@8 | 164 bool Scene::load(goat3d_io *io) |
nuclear@8 | 165 { |
nuclear@8 | 166 return false; |
nuclear@8 | 167 } |
nuclear@8 | 168 |
nuclear@8 | 169 bool Scene::save(goat3d_io *io) const |
nuclear@8 | 170 { |
nuclear@8 | 171 return false; |
nuclear@8 | 172 } |