diff --git a/src/Parser.cc b/src/Parser.cc index fb9fc21..abca50e 100644 --- a/src/Parser.cc +++ b/src/Parser.cc @@ -18,9 +18,8 @@ const Vector3f getVector3f(const nlohmann::json &j) { const VectorXi getRpp(const nlohmann::json &j) { VectorXi rpp(j.size()); - for (int i = 0; i < j.size(); ++i) { + for (int i = 0; i < j.size(); ++i) rpp[i] = j[i].get(); - } return rpp; } diff --git a/src/RayTracer.cc b/src/RayTracer.cc index 13d5ad8..c8244b8 100644 --- a/src/RayTracer.cc +++ b/src/RayTracer.cc @@ -173,7 +173,6 @@ Light *RayTracer::singleLightSource() const { return nullptr; } -// helper functions Ray getRay(int x, int y) { using namespace camera; return Ray(pos, pxUpperLeft + x * du + y * dv - pos); @@ -194,12 +193,14 @@ void writeColor(int i, const Vector3f &color) { Output::current->b(i, color.z()); } +// This should generate a higher quality random number float getRandomNumber() { static std::uniform_real_distribution distribution(0.0, 1.0); static std::mt19937 generator; return distribution(generator); } +// Generate a randon point on a unit hemisphere Vector3f getRandomDirection() { RETRY_RANDOM: float x = getRandomNumber() * 2 - 1; @@ -225,13 +226,13 @@ Vector3f getGlobalRandDirection(Vector3f normal) { return local2World * getRandomDirection(); } +// Check if a light source in on a surface (or really near) bool lightOnSurface(HitRecord hit, const Light *l) { Vector3f center = l->getCenter(); Geometry *g = hit.geometry(); Geometry::Type type = g->type(); - if (type == Geometry::Type::RECTANGLE) { + if (type == Geometry::Type::RECTANGLE) return (g->sample() - center).dot(g->normal(center)) < 1e-5; - } return false; } @@ -293,6 +294,11 @@ int getRayNumber(VectorXi data) { return data.size() == 2 ? data.y() : (data.size() == 3 ? data.z() : 1); } +/** + * Initialize camera parameters + * + * Construct the surface for viewing the world + */ void init() { width = Scene::current->width(); height = Scene::current->height(); diff --git a/src/RayTracer.h b/src/RayTracer.h index d6ff470..2da4613 100644 --- a/src/RayTracer.h +++ b/src/RayTracer.h @@ -10,6 +10,8 @@ #include +using std::vector; + class RayTracer { public: RayTracer(const nlohmann::json &j) : json(j) {} @@ -17,10 +19,10 @@ public: private: nlohmann::json json; - std::vector scenes; - std::vector lights; - std::vector geometries; - std::vector outputs; + vector scenes; + vector lights; + vector geometries; + vector outputs; void parse(); void render();