erebus

view liberebus/src/scene.cc @ 17:e9da2916bc79

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