78 lines
2.2 KiB
C++
78 lines
2.2 KiB
C++
|
|
#ifndef SCENE_H
|
|
#define SCENE_H SCENE_H
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include "util/refptr.h"
|
|
#include "util/Ray.h"
|
|
#include "util/Color.h"
|
|
#include "shapes/Shape.h"
|
|
#include "Light.h"
|
|
#include "parser/nodes.h"
|
|
|
|
#define SCENE_MAX_TRANSPARENT_HITS 8
|
|
#define SCENE_TRANSPARENCY_THRESHOLD 0.01
|
|
|
|
class Scene
|
|
{
|
|
public:
|
|
/* types */
|
|
class ShapeDistance : public std::pair<refptr<Shape>, double>
|
|
{
|
|
public:
|
|
ShapeDistance(refptr<Shape> shape, double dist)
|
|
: std::pair<refptr<Shape>, double>(shape, dist)
|
|
{
|
|
};
|
|
};
|
|
|
|
Scene(const std::map<std::string, const char *> & options,
|
|
const char * filename);
|
|
~Scene();
|
|
void render();
|
|
void setWidth(int width) { m_width = width; }
|
|
void setHeight(int height) { m_height = height; }
|
|
void setMultisampleLevel(int level) { m_multisample_level = level; }
|
|
void setVFOV(double vfov) { m_vfov = vfov; }
|
|
void setAmbientLight(const Color & al) { m_ambient_light = al; }
|
|
Transform & getTransform() { return m_transform; }
|
|
|
|
protected:
|
|
/* private methods */
|
|
void load(const char * filename);
|
|
void renderPixel(int x, int y, unsigned char * pixel);
|
|
Color traceRay(const Ray & ray);
|
|
std::vector<ShapeDistance> getRayHits(const Ray & ray);
|
|
void parse(refptr<Node> node);
|
|
|
|
/* rendering parameters */
|
|
int m_width;
|
|
int m_height;
|
|
int m_multisample_level;
|
|
std::string m_output_file_name;
|
|
bool m_verbose;
|
|
double m_vfov;
|
|
Color m_ambient_light;
|
|
|
|
/* private data */
|
|
std::vector< refptr<Shape> > m_shapes;
|
|
std::vector< refptr<Light> > m_lights;
|
|
Transform m_transform;
|
|
double m_view_plane_dist;
|
|
int m_multisample_level_squared;
|
|
double m_sample_span;
|
|
double m_half_sample_span;
|
|
|
|
/* framebuffer */
|
|
unsigned char * m_data;
|
|
};
|
|
|
|
bool operator<(const Scene::ShapeDistance & sd1,
|
|
const Scene::ShapeDistance & sd2);
|
|
|
|
#endif
|
|
|