rayzor
view src/scene.cc @ 15:be616b58df99
continued the renderer slightly
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 13 Apr 2014 09:54:36 +0300 |
parents | a9a948809c6f |
children | 79609d482762 |
line source
1 #include <string.h>
2 #include "scene.h"
3 #include "min3d.h"
5 Scene::Scene()
6 {
7 name = 0;
8 active_cam = 0;
9 }
11 Scene::~Scene()
12 {
13 clear();
14 }
16 void Scene::clear()
17 {
18 delete [] name;
20 size_t i;
21 for(i=0; i<objects.size(); i++) {
22 delete objects[i];
23 }
24 for(i=0; i<lights.size(); i++) {
25 delete lights[i];
26 }
27 for(i=0; i<cameras.size(); i++) {
28 delete cameras[i];
29 }
30 }
32 void Scene::set_name(const char *name)
33 {
34 delete [] this->name;
35 this->name = new char[strlen(name) + 1];
36 strcpy(this->name, name);
37 }
39 const char *Scene::get_name() const
40 {
41 return name ? name : "<unknown>";
42 }
44 void Scene::add(SceneNode *node)
45 {
46 nodes.push_back(node);
48 switch(node->get_type()) {
49 case NODE_OBJECT:
50 objects.push_back((Object*)node);
51 break;
53 case NODE_LIGHT:
54 lights.push_back((Light*)node);
55 break;
57 case NODE_CAMERA:
58 cameras.push_back((Camera*)node);
59 break;
61 default:
62 break;
63 }
65 sel.clear();
66 }
68 int Scene::get_node_count() const
69 {
70 return (int)nodes.size();
71 }
73 int Scene::get_object_count() const
74 {
75 return (int)objects.size();
76 }
78 int Scene::get_light_count() const
79 {
80 return (int)lights.size();
81 }
83 int Scene::get_camera_count() const
84 {
85 return (int)cameras.size();
86 }
88 SceneNode *Scene::get_node(int idx)
89 {
90 return nodes[idx];
91 }
93 const SceneNode *Scene::get_node(int idx) const
94 {
95 return nodes[idx];
96 }
98 Object *Scene::get_object(int idx)
99 {
100 return objects[idx];
101 }
103 const Object *Scene::get_object(int idx) const
104 {
105 return objects[idx];
106 }
108 Light *Scene::get_light(int idx)
109 {
110 return lights[idx];
111 }
113 const Light *Scene::get_light(int idx) const
114 {
115 return lights[idx];
116 }
118 Camera *Scene::get_camera(int idx)
119 {
120 return cameras[idx];
121 }
123 const Camera *Scene::get_camera(int idx) const
124 {
125 return cameras[idx];
126 }
128 void Scene::set_active_camera(Camera *cam)
129 {
130 active_cam = cam;
131 }
133 Camera *Scene::get_active_camera() const
134 {
135 return active_cam;
136 }
138 void Scene::draw() const
139 {
140 if(active_cam) {
141 // TODO
142 }
144 int num_nodes = get_node_count();
145 for(int i=0; i<num_nodes; i++) {
146 bool selected = false;
148 for(size_t j=0; j<sel.size(); j++) {
149 if(sel[j] == i) {
150 selected = true;
151 break;
152 }
153 }
155 nodes[i]->draw(selected);
156 }
157 }
159 void Scene::select(int s)
160 {
161 for(size_t i=0; i<sel.size(); i++) {
162 if(sel[i] == s) {
163 return;
164 }
165 }
166 sel.push_back(s);
167 }
169 void Scene::clear_selection()
170 {
171 sel.clear();
172 }
174 int Scene::get_selection_count() const
175 {
176 return (int)sel.size();
177 }
179 int Scene::get_selection(int idx) const
180 {
181 return idx >= 0 && idx < (int)sel.size() ? sel[idx] : -1;
182 }