#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/shapes.h" #include "parser/parser.h" #include "parser/nodes.h" #include "Light.h" #define SCENE_FACTOR_THRESHOLD 0.02 class Scene { public: Scene(const std::map & options, const char * filename); ~Scene(); 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; } void renderPixel(int x, int y, unsigned char * pixel); int getWidth() { return m_width; } int getHeight() { return m_height; } int getMultisampleLevel() { return m_multisample_level; } double getVFOV() { return m_vfov; } protected: /* private methods */ Color traceRay(const Ray & ray); Color traceRayRecurse(const Ray & ray, int depth, double factor); Shape::Intersection getRayClosestHit(const Ray & ray); Color computePhong(const refptr material, const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal); Color calculateLightContribution(const Ray & toLight, const Vector & lightPosition); /* In Scene-load.cc */ void load(const char * filename); void processNode(refptr node); void processChildren(refptr node); void processScene(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; double m_vfov; Color m_ambient_light; int m_max_depth; double m_exposure; /* 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; }; #endif