erebus
annotate liberebus/src/scene.cc @ 8:e2d9bf168a41
semi-works ...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 24 May 2014 06:12:57 +0300 |
parents | 93894c232d65 |
children | 6204e4d3f445 |
rev | line source |
---|---|
nuclear@4 | 1 #include "scene.h" |
nuclear@4 | 2 |
nuclear@8 | 3 // default enviromental parameters |
nuclear@8 | 4 Environment::Environment() |
nuclear@8 | 5 : bgcolor(0.05, 0.05, 0.05), ambient(0.05, 0.05, 0.05) |
nuclear@8 | 6 { |
nuclear@8 | 7 } |
nuclear@8 | 8 |
nuclear@4 | 9 Scene::Scene() |
nuclear@4 | 10 { |
nuclear@4 | 11 active_cam = 0; |
nuclear@4 | 12 root = new SceneNode; |
nuclear@4 | 13 } |
nuclear@4 | 14 |
nuclear@4 | 15 Scene::~Scene() |
nuclear@4 | 16 { |
nuclear@4 | 17 for(auto obj : objects) { |
nuclear@4 | 18 delete obj; |
nuclear@4 | 19 } |
nuclear@4 | 20 for(auto node : nodes) { |
nuclear@4 | 21 delete node; |
nuclear@4 | 22 } |
nuclear@4 | 23 delete root; |
nuclear@4 | 24 } |
nuclear@4 | 25 |
nuclear@8 | 26 void Scene::set_env(const Environment &env) |
nuclear@8 | 27 { |
nuclear@8 | 28 this->env = env; |
nuclear@8 | 29 } |
nuclear@8 | 30 |
nuclear@8 | 31 Environment &Scene::get_env() |
nuclear@8 | 32 { |
nuclear@8 | 33 return env; |
nuclear@8 | 34 } |
nuclear@8 | 35 |
nuclear@8 | 36 const Environment &Scene::get_env() const |
nuclear@8 | 37 { |
nuclear@8 | 38 return env; |
nuclear@8 | 39 } |
nuclear@8 | 40 |
nuclear@8 | 41 Color Scene::get_env_color() const |
nuclear@8 | 42 { |
nuclear@8 | 43 return env.bgcolor; |
nuclear@8 | 44 } |
nuclear@8 | 45 |
nuclear@8 | 46 Color Scene::get_env_color(const Ray &ray) const |
nuclear@8 | 47 { |
nuclear@8 | 48 // TODO |
nuclear@8 | 49 return get_env_color(); |
nuclear@8 | 50 } |
nuclear@8 | 51 |
nuclear@4 | 52 void Scene::add_object(Object *obj) |
nuclear@4 | 53 { |
nuclear@4 | 54 objects.push_back(obj); |
nuclear@4 | 55 } |
nuclear@4 | 56 |
nuclear@4 | 57 int Scene::get_object_count() const |
nuclear@4 | 58 { |
nuclear@4 | 59 return (int)objects.size(); |
nuclear@4 | 60 } |
nuclear@4 | 61 |
nuclear@4 | 62 Object *Scene::get_object(int idx) const |
nuclear@4 | 63 { |
nuclear@4 | 64 return objects[idx]; |
nuclear@4 | 65 } |
nuclear@4 | 66 |
nuclear@4 | 67 void Scene::add_node(SceneNode *node) |
nuclear@4 | 68 { |
nuclear@4 | 69 nodes.push_back(node); |
nuclear@4 | 70 |
nuclear@4 | 71 if(!node->get_parent()) { |
nuclear@4 | 72 root->add_child(node); |
nuclear@4 | 73 } |
nuclear@4 | 74 } |
nuclear@4 | 75 |
nuclear@4 | 76 int Scene::get_node_count() const |
nuclear@4 | 77 { |
nuclear@4 | 78 return (int)nodes.size(); |
nuclear@4 | 79 } |
nuclear@4 | 80 |
nuclear@4 | 81 SceneNode *Scene::get_node(int idx) const |
nuclear@4 | 82 { |
nuclear@4 | 83 return nodes[idx]; |
nuclear@4 | 84 } |
nuclear@4 | 85 |
nuclear@4 | 86 void Scene::use_camera(Camera *cam) |
nuclear@4 | 87 { |
nuclear@4 | 88 active_cam = cam; |
nuclear@4 | 89 } |
nuclear@4 | 90 |
nuclear@4 | 91 Camera *Scene::get_active_camera() const |
nuclear@4 | 92 { |
nuclear@4 | 93 return active_cam; |
nuclear@4 | 94 } |
nuclear@4 | 95 |
nuclear@4 | 96 void Scene::update(long msec) |
nuclear@4 | 97 { |
nuclear@4 | 98 root->update(msec); |
nuclear@4 | 99 } |
nuclear@4 | 100 |
nuclear@4 | 101 bool Scene::intersect(const Ray &ray, RayHit *hit) const |
nuclear@4 | 102 { |
nuclear@4 | 103 return root->intersect(ray, hit); |
nuclear@4 | 104 } |
nuclear@4 | 105 |
nuclear@4 | 106 bool Scene::load(const char *fname) |
nuclear@4 | 107 { |
nuclear@4 | 108 return false; // TODO |
nuclear@4 | 109 } |