rayzor

annotate src/scene.cc @ 14:a9a948809c6f

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