#ifndef SCENE_H #define SCENE_H SCENE_H #include #include #include #include #include #include "util/refptr.h" #include "util/Ray.h" #include "util/Color.h" #include "util/Material.h" #include "shapes/Shape.h" #include "Light.h" #include "parser/parser.h" #include "parser/nodes.h" #define SCENE_FACTOR_THRESHOLD 0.02 class Scene { public: /* types */ class ShapeDistance { public: ShapeDistance() {} ShapeDistance(refptr shape, double dist) { this->shape = shape; this->dist = dist; } refptr shape; double dist; }; Scene(const std::map & 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; } protected: /* private methods */ void renderPixel(int x, int y, unsigned char * pixel); Color traceRay(const Ray & ray); Color traceRayRecurse(const Ray & ray, int depth, double factor); ShapeDistance getRayClosestHit(const Ray & ray); Color computePhong(const refptr material, const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal); double calculateLightContribution(const Ray & toLight, refptr light); /* In Scene-load.cc */ void load(const char * filename); void processNode(refptr node); void processChildren(refptr node); refptr processMaterial(refptr node); refptr processBox(refptr node); refptr processCyl(refptr node); refptr processLight(refptr node); refptr processPlane(refptr node); refptr processSphere(refptr node); refptr processShape(refptr node); refptr processBool(refptr node); bool processTransforms(refptr node); void processCamera(refptr node); void processOptions(refptr node); void processTransformBlock(refptr node); void processMaterialDefinition(refptr 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; int m_max_depth; /* private data */ std::vector< refptr > m_shapes; std::vector< refptr > m_lights; std::stack m_transforms; double m_view_plane_dist; int m_multisample_level_squared; double m_sample_span; double m_half_sample_span; std::map< std::string, refptr > m_materials; /* framebuffer */ unsigned char * m_data; }; bool operator<(const Scene::ShapeDistance & sd1, const Scene::ShapeDistance & sd2); #endif