goat3d

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