mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
use p1 to p4 instead of a matrix
This commit is contained in:
parent
295bdc0c89
commit
0b38f93655
2 changed files with 9 additions and 16 deletions
|
@ -46,14 +46,14 @@ private:
|
||||||
|
|
||||||
class AreaLight : public Light {
|
class AreaLight : public Light {
|
||||||
public:
|
public:
|
||||||
AreaLight(const Vector3f &id, const Vector3f &is,
|
AreaLight(const Vector3f &id, const Vector3f &is, const Vector3f &p1,
|
||||||
const Matrix<float, 3, 4> &corners)
|
const Vector3f &p2, const Vector3f &p3, const Vector3f &p4)
|
||||||
: Light(Type::Area, id, is), corners(corners) {}
|
: Light(Type::Area, id, is), p1(p1), p2(p2), p3(p3), p4(p4) {}
|
||||||
|
|
||||||
virtual void illumination() const override;
|
virtual void illumination() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Matrix<float, 3, 4> corners; // stores `p1`, `p2`, `p3` and `p4`
|
Vector3f p1, p2, p3, p4;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !LIGHT_H_
|
#endif // !LIGHT_H_
|
||||||
|
|
|
@ -72,15 +72,6 @@ Geometry *Parser::getGeometry(const nlohmann::json &j) {
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to get four corners of a rectangle
|
|
||||||
const Matrix<float, 3, 4> getCorners(const nlohmann::json &j) {
|
|
||||||
Matrix<float, 3, 4> 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,
|
Sphere *Parser::getSphere(const nlohmann::json &j, float ka, float kd, float ks,
|
||||||
const Vector3f &ca, const Vector3f &cd,
|
const Vector3f &ca, const Vector3f &cd,
|
||||||
const Vector3f &cs, float pc) {
|
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,
|
float ks, const Vector3f &ca,
|
||||||
const Vector3f &cd, const Vector3f &cs,
|
const Vector3f &cd, const Vector3f &cs,
|
||||||
float pc) {
|
float pc) {
|
||||||
Matrix<float, 3, 4> corners = getCorners(j);
|
|
||||||
Vector3f p1 = getVector3f(j["p1"]);
|
Vector3f p1 = getVector3f(j["p1"]);
|
||||||
Vector3f p2 = getVector3f(j["p2"]);
|
Vector3f p2 = getVector3f(j["p2"]);
|
||||||
Vector3f p3 = getVector3f(j["p3"]);
|
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,
|
AreaLight *Parser::getAreaLight(const nlohmann::json &j, const Vector3f &id,
|
||||||
const Vector3f &is) {
|
const Vector3f &is) {
|
||||||
Matrix<float, 3, 4> 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,
|
PointLight *Parser::getPointLight(const nlohmann::json &j, const Vector3f &id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue