rayzor

annotate src/scene.cc @ 6:a68dbf80d547

finally showing something ... :)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Apr 2014 06:04:11 +0300
parents 5fcf72837b69
children d94a69933a71
rev   line source
nuclear@5 1 #include <string.h>
nuclear@1 2 #include "scene.h"
nuclear@1 3
nuclear@1 4 Scene::Scene()
nuclear@1 5 {
nuclear@1 6 name = 0;
nuclear@6 7 active_cam = 0;
nuclear@1 8 }
nuclear@1 9
nuclear@1 10 Scene::~Scene()
nuclear@1 11 {
nuclear@1 12 clear();
nuclear@1 13 }
nuclear@1 14
nuclear@1 15 void Scene::clear()
nuclear@1 16 {
nuclear@1 17 delete [] name;
nuclear@1 18
nuclear@1 19 size_t i;
nuclear@1 20 for(i=0; i<objects.size(); i++) {
nuclear@1 21 delete objects[i];
nuclear@1 22 }
nuclear@1 23 for(i=0; i<lights.size(); i++) {
nuclear@1 24 delete lights[i];
nuclear@1 25 }
nuclear@1 26 for(i=0; i<cameras.size(); i++) {
nuclear@1 27 delete cameras[i];
nuclear@1 28 }
nuclear@1 29 }
nuclear@1 30
nuclear@1 31 void Scene::set_name(const char *name)
nuclear@1 32 {
nuclear@1 33 delete [] this->name;
nuclear@1 34 this->name = new char[strlen(name) + 1];
nuclear@1 35 strcpy(this->name, name);
nuclear@1 36 }
nuclear@1 37
nuclear@1 38 const char *Scene::get_name() const
nuclear@1 39 {
nuclear@1 40 return name ? name : "<unknown>";
nuclear@1 41 }
nuclear@1 42
nuclear@6 43 void Scene::add_object(Object *obj)
nuclear@6 44 {
nuclear@6 45 objects.push_back(obj);
nuclear@6 46 }
nuclear@6 47
nuclear@6 48 void Scene::add_light(Light *lt)
nuclear@6 49 {
nuclear@6 50 lights.push_back(lt);
nuclear@6 51 }
nuclear@6 52
nuclear@6 53 void Scene::add_camera(Camera *cam)
nuclear@6 54 {
nuclear@6 55 cameras.push_back(cam);
nuclear@6 56 }
nuclear@6 57
nuclear@6 58
nuclear@6 59 int Scene::get_object_count() const
nuclear@6 60 {
nuclear@6 61 return (int)objects.size();
nuclear@6 62 }
nuclear@6 63
nuclear@6 64 int Scene::get_light_count() const
nuclear@6 65 {
nuclear@6 66 return (int)lights.size();
nuclear@6 67 }
nuclear@6 68
nuclear@6 69 int Scene::get_camera_count() const
nuclear@6 70 {
nuclear@6 71 return (int)cameras.size();
nuclear@6 72 }
nuclear@6 73
nuclear@6 74
nuclear@6 75 Object *Scene::get_object(int idx)
nuclear@6 76 {
nuclear@6 77 return objects[idx];
nuclear@6 78 }
nuclear@6 79
nuclear@6 80 const Object *Scene::get_object(int idx) const
nuclear@6 81 {
nuclear@6 82 return objects[idx];
nuclear@6 83 }
nuclear@6 84
nuclear@6 85 Light *Scene::get_light(int idx)
nuclear@6 86 {
nuclear@6 87 return lights[idx];
nuclear@6 88 }
nuclear@6 89
nuclear@6 90 const Light *Scene::get_light(int idx) const
nuclear@6 91 {
nuclear@6 92 return lights[idx];
nuclear@6 93 }
nuclear@6 94
nuclear@6 95 Camera *Scene::get_camera(int idx)
nuclear@6 96 {
nuclear@6 97 return cameras[idx];
nuclear@6 98 }
nuclear@6 99
nuclear@6 100 const Camera *Scene::get_camera(int idx) const
nuclear@6 101 {
nuclear@6 102 return cameras[idx];
nuclear@6 103 }
nuclear@6 104
nuclear@1 105 void Scene::draw() const
nuclear@1 106 {
nuclear@6 107 if(active_cam) {
nuclear@6 108 // TODO
nuclear@6 109 }
nuclear@6 110
nuclear@6 111 int nobj = get_object_count();
nuclear@6 112 for(int i=0; i<nobj; i++) {
nuclear@6 113 objects[i]->draw();
nuclear@6 114 }
nuclear@1 115 }