diff --git a/src/Light.cc b/src/Light.cc index dddb575..07d7c27 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -7,3 +7,7 @@ void Light::setTransform(const Matrix4f &transform) { void Light::setGridSize(unsigned int gridSize) { this->gridSize = gridSize; } void Light::setUseCenter(bool useCenter) { this->useCenter = useCenter; } + +void PointLight::illumination() const {} + +void AreaLight::illumination() const {} diff --git a/src/Parser.cc b/src/Parser.cc index 7dd1b76..69fabb3 100644 --- a/src/Parser.cc +++ b/src/Parser.cc @@ -1,5 +1,6 @@ #include "Parser.h" #include "Geometry.h" +#include "Light.h" #include #include @@ -97,3 +98,37 @@ Rectangle *Parser::getRectangle(const nlohmann::json &j, float ka, float kd, return new Rectangle(ka, kd, ks, ca, cd, cs, pc, corners); } + +Light *Parser::getLight(const nlohmann::json &j) { + Vector3f id = getVector3f(j["id"]); + Vector3f is = getVector3f(j["is"]); + + Light *l; + if (j["type"].get().compare("point")) + l = getAreaLight(j, id, is); + else + l = getPointLight(j, id, is); + + if (j.contains("transform")) { + l->setTransform(getTransform(j["transform"])); + } + + l->setGridSize(j.value("n", 0)); + l->setUseCenter(j.value("usecenter", false)); + + return l; +} + +AreaLight *Parser::getAreaLight(const nlohmann::json &j, const Vector3f &id, + const Vector3f &is) { + Matrix corners = getCorners(j); + + return new AreaLight(id, is, corners); +} + +PointLight *Parser::getPointLight(const nlohmann::json &j, const Vector3f &id, + const Vector3f &is) { + Vector3f center = getVector3f(j["centre"]); + + return new PointLight(id, is, center); +} diff --git a/src/Parser.h b/src/Parser.h index 6b3b3d4..f82c63c 100644 --- a/src/Parser.h +++ b/src/Parser.h @@ -14,8 +14,10 @@ public: static Scene *getScene(const nlohmann::json &); private: - static PointLight *getPointLight(const nlohmann::json &); - static AreaLight *getAreaLight(const nlohmann::json &); + static PointLight *getPointLight(const nlohmann::json &, const Vector3f &, + const Vector3f &); + static AreaLight *getAreaLight(const nlohmann::json &, const Vector3f &, + const Vector3f &); static Rectangle *getRectangle(const nlohmann::json &, float, float, float, const Vector3f &, const Vector3f &, const Vector3f &, float); diff --git a/src/RayTracer.cc b/src/RayTracer.cc index b130c70..2cb39a1 100644 --- a/src/RayTracer.cc +++ b/src/RayTracer.cc @@ -12,6 +12,9 @@ void RayTracer::parse() { for (auto i = json["geometry"].begin(); i != json["geometry"].end(); ++i) geometries.push_back(Parser::getGeometry(*i)); + + for (auto i = json["light"].begin(); i != json["light"].end(); ++i) + lights.push_back(Parser::getLight(*i)); } void RayTracer::render() {}