From 0b38f9365555d8ea92ce01651b018b820e9ac9ae Mon Sep 17 00:00:00 2001 From: vonhyou Date: Tue, 20 Feb 2024 22:37:38 -0500 Subject: [PATCH] use p1 to p4 instead of a matrix --- src/Light.h | 8 ++++---- src/Parser.cc | 17 +++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Light.h b/src/Light.h index 3b41c7b..c708467 100644 --- a/src/Light.h +++ b/src/Light.h @@ -46,14 +46,14 @@ private: class AreaLight : public Light { public: - AreaLight(const Vector3f &id, const Vector3f &is, - const Matrix &corners) - : Light(Type::Area, id, is), corners(corners) {} + AreaLight(const Vector3f &id, const Vector3f &is, const Vector3f &p1, + const Vector3f &p2, const Vector3f &p3, const Vector3f &p4) + : Light(Type::Area, id, is), p1(p1), p2(p2), p3(p3), p4(p4) {} virtual void illumination() const override; private: - Matrix corners; // stores `p1`, `p2`, `p3` and `p4` + Vector3f p1, p2, p3, p4; }; #endif // !LIGHT_H_ diff --git a/src/Parser.cc b/src/Parser.cc index b44629d..4d15d76 100644 --- a/src/Parser.cc +++ b/src/Parser.cc @@ -72,15 +72,6 @@ Geometry *Parser::getGeometry(const nlohmann::json &j) { return g; } -// helper function to get four corners of a rectangle -const Matrix getCorners(const nlohmann::json &j) { - Matrix corners; - for (int i = 0; i < 4; ++i) { - corners.col(i) = getVector3f(j["p" + std::to_string(i + 1)]); - } - return corners; -} - Sphere *Parser::getSphere(const nlohmann::json &j, float ka, float kd, float ks, const Vector3f &ca, const Vector3f &cd, const Vector3f &cs, float pc) { @@ -94,7 +85,6 @@ Rectangle *Parser::getRectangle(const nlohmann::json &j, float ka, float kd, float ks, const Vector3f &ca, const Vector3f &cd, const Vector3f &cs, float pc) { - Matrix corners = getCorners(j); Vector3f p1 = getVector3f(j["p1"]); Vector3f p2 = getVector3f(j["p2"]); Vector3f p3 = getVector3f(j["p3"]); @@ -125,9 +115,12 @@ Light *Parser::getLight(const nlohmann::json &j) { AreaLight *Parser::getAreaLight(const nlohmann::json &j, const Vector3f &id, const Vector3f &is) { - Matrix corners = getCorners(j); - return new AreaLight(id, is, corners); + Vector3f p1 = getVector3f(j["p1"]); + Vector3f p2 = getVector3f(j["p2"]); + Vector3f p3 = getVector3f(j["p3"]); + Vector3f p4 = getVector3f(j["p4"]); + return new AreaLight(id, is, p1, p2, p3, p4); } PointLight *Parser::getPointLight(const nlohmann::json &j, const Vector3f &id,