2013-09-05 21:58:58 -07:00
|
|
|
/* scene.h
|
|
|
|
*
|
2013-09-10 16:28:32 -07:00
|
|
|
* Definition of the Scene class.
|
|
|
|
*
|
|
|
|
* Scenes are the top level object in charles. Scenes contain objects, lights, a camera,
|
|
|
|
* etc. and can be rendered to pixel data and written to a file.
|
2013-09-05 21:58:58 -07:00
|
|
|
*
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SCENE_H__
|
|
|
|
#define __SCENE_H__
|
|
|
|
|
2013-09-10 16:28:32 -07:00
|
|
|
#include <list>
|
2013-09-10 21:04:56 -07:00
|
|
|
#include <string>
|
|
|
|
#include "basics.h"
|
2014-07-16 23:32:44 -07:00
|
|
|
#include "camera.h"
|
2013-09-10 21:04:56 -07:00
|
|
|
|
2013-09-05 22:57:03 -07:00
|
|
|
|
2013-09-13 14:12:55 -07:00
|
|
|
class AmbientLight;
|
|
|
|
class PointLight;
|
2013-09-10 16:28:32 -07:00
|
|
|
class Shape;
|
2013-09-10 21:04:56 -07:00
|
|
|
class Writer;
|
2013-09-07 16:10:50 -07:00
|
|
|
|
2013-09-05 21:58:58 -07:00
|
|
|
|
2013-09-10 16:28:32 -07:00
|
|
|
class Scene
|
2013-09-05 21:58:58 -07:00
|
|
|
{
|
2013-09-10 16:28:32 -07:00
|
|
|
public:
|
|
|
|
Scene();
|
|
|
|
~Scene();
|
2013-09-06 23:04:30 -07:00
|
|
|
|
2013-09-10 16:28:32 -07:00
|
|
|
bool is_rendered() const;
|
2013-09-10 21:04:56 -07:00
|
|
|
int get_width() const;
|
2014-07-13 20:12:10 -07:00
|
|
|
void set_width(int w) { width = w; }
|
2013-09-10 21:04:56 -07:00
|
|
|
int get_height() const;
|
2014-07-13 20:12:10 -07:00
|
|
|
void set_height(int h) { height = h; }
|
2013-09-13 18:25:09 -07:00
|
|
|
AmbientLight &get_ambient() const;
|
2013-09-10 21:04:56 -07:00
|
|
|
const Color *get_pixels() const;
|
2013-09-07 16:10:50 -07:00
|
|
|
|
2013-09-10 21:04:56 -07:00
|
|
|
void read(const std::string &filename);
|
|
|
|
void write(Writer &writer, const std::string &filename);
|
2013-09-10 16:28:32 -07:00
|
|
|
void render();
|
|
|
|
|
|
|
|
void add_shape(Shape *obj);
|
2013-09-13 14:12:55 -07:00
|
|
|
void add_light(PointLight *light);
|
2013-09-05 21:58:58 -07:00
|
|
|
|
2013-09-10 16:28:32 -07:00
|
|
|
private:
|
2013-09-21 16:45:10 -07:00
|
|
|
Color trace_ray(const Ray &ray, const int depth = 0, const float weight = 1.0);
|
2013-09-05 21:58:58 -07:00
|
|
|
|
2013-09-11 10:33:16 -07:00
|
|
|
// Pixel dimensions of the image.
|
2013-09-10 21:04:56 -07:00
|
|
|
int width, height;
|
2013-09-11 10:33:16 -07:00
|
|
|
|
2014-07-16 23:32:44 -07:00
|
|
|
Camera *camera;
|
|
|
|
|
2013-09-21 17:01:11 -07:00
|
|
|
/*
|
|
|
|
* Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum
|
|
|
|
* specular weight to apply before giving up.
|
|
|
|
*/
|
2013-09-11 10:33:16 -07:00
|
|
|
int max_depth;
|
2013-09-21 17:01:11 -07:00
|
|
|
float min_weight;
|
2013-09-11 10:33:16 -07:00
|
|
|
|
|
|
|
// Scene objects.
|
2013-09-13 14:15:34 -07:00
|
|
|
AmbientLight *ambient;
|
2013-09-10 16:28:32 -07:00
|
|
|
std::list<Shape *> shapes;
|
2013-09-13 14:12:55 -07:00
|
|
|
std::list<PointLight *> lights;
|
2013-09-05 21:58:58 -07:00
|
|
|
|
2013-09-12 09:10:22 -07:00
|
|
|
// Rendering stats
|
|
|
|
unsigned int nrays;
|
|
|
|
|
2013-09-11 10:33:16 -07:00
|
|
|
// Rendering output.
|
2013-09-10 16:28:32 -07:00
|
|
|
bool _is_rendered;
|
|
|
|
Color *pixels;
|
|
|
|
};
|
2013-09-05 21:58:58 -07:00
|
|
|
|
|
|
|
#endif
|