rayzor
view src/scene.cc @ 12:d94a69933a71
lots of stuff, can't remember
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 12 Apr 2014 23:28:24 +0300 |
parents | a68dbf80d547 |
children | a9a948809c6f |
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::draw() const
129 {
130 if(active_cam) {
131 // TODO
132 }
134 int num_nodes = get_node_count();
135 for(int i=0; i<num_nodes; i++) {
136 bool selected = false;
138 for(size_t j=0; j<sel.size(); j++) {
139 if(sel[j] == i) {
140 selected = true;
141 break;
142 }
143 }
145 m3d_color(1, 1, selected ? 0.25 : 1);
146 nodes[i]->draw();
147 }
148 }
150 void Scene::select(int s)
151 {
152 for(size_t i=0; i<sel.size(); i++) {
153 if(sel[i] == s) {
154 return;
155 }
156 }
157 sel.push_back(s);
158 }
160 void Scene::clear_selection()
161 {
162 sel.clear();
163 }
165 int Scene::get_selection_count() const
166 {
167 return (int)sel.size();
168 }
170 int Scene::get_selection(int idx) const
171 {
172 return idx >= 0 && idx < (int)sel.size() ? sel[idx] : -1;
173 }