From 1b0df92e70c51f354d9363f6a5636ecc91fa5e2a Mon Sep 17 00:00:00 2001 From: vonhyou Date: Thu, 1 Feb 2024 19:17:37 -0500 Subject: [PATCH 1/7] prepare for alpha1 submission --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index db24cfc..c65ce39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ *.ppm +*.zip From 39c584eff949727d0580b020560bd373968ebe71 Mon Sep 17 00:00:00 2001 From: vonhyou Date: Thu, 8 Feb 2024 16:43:41 -0500 Subject: [PATCH 2/7] make the render function private --- src/RayTracer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RayTracer.h b/src/RayTracer.h index 8300f13..91dbcb3 100644 --- a/src/RayTracer.h +++ b/src/RayTracer.h @@ -7,12 +7,12 @@ class RayTracer { public: RayTracer(const nlohmann::json &); - void render(); void run(); private: Scene scene; nlohmann::json json; + void render(); }; #endif // !RAY_TRACER_H_ From a73f25c0276cdc0dc70476039fcfefbb89e17bcd Mon Sep 17 00:00:00 2001 From: vonhyou Date: Sun, 11 Feb 2024 16:22:51 -0500 Subject: [PATCH 3/7] add light header --- src/Light.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/Light.h diff --git a/src/Light.h b/src/Light.h new file mode 100644 index 0000000..f0b5360 --- /dev/null +++ b/src/Light.h @@ -0,0 +1,16 @@ +#ifndef LIGHT_H_ +#define LIGHT_H_ + +enum LIGHT_TYPE { POINT, AREA }; + +class Light { +public: + Light(LIGHT_TYPE, float *, float *); + +private: + LIGHT_TYPE type; + float diffuse[3]; // field `id` + float specular[3]; // field `is` +}; + +#endif // !LIGHT_H_ From a12711e543267f50cb1161974143ca6291097fdf Mon Sep 17 00:00:00 2001 From: vonhyou Date: Sun, 11 Feb 2024 17:53:14 -0500 Subject: [PATCH 4/7] rewrite Light class using Eigen --- src/Light.h | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/Light.h b/src/Light.h index f0b5360..2e913cc 100644 --- a/src/Light.h +++ b/src/Light.h @@ -1,16 +1,55 @@ #ifndef LIGHT_H_ #define LIGHT_H_ -enum LIGHT_TYPE { POINT, AREA }; +#include +using Eigen::Matrix; +using Eigen::Matrix4f; +using Eigen::Vector3f; + +// Abstract base class for Lights class Light { public: - Light(LIGHT_TYPE, float *, float *); + enum class Type { Point, Area }; + + virtual ~Light() = default; + + // a pure virtual function for derived class implementation + virtual void illumination() const = 0; + +protected: + Light(Type type, const Vector3f &id, const Vector3f &is) + : type(type), diffuse(id), specular(is) {} + + Type type; + Vector3f diffuse; // mandatory member `id` + Vector3f specular; // mandatory member `is` + Matrix4f transform = Matrix4f::Identity(); // optional member `transform` + unsigned int gridSize = 0; // optional member `n` + bool useCenter = false; // optional member `usecenter` +}; + +class PointLight : public Light { +public: + PointLight(const Vector3f &id, const Vector3f &is, Vector3f ¢er) + : Light(Type::Point, id, is), center(center) {} + + virtual void illumination() const override; private: - LIGHT_TYPE type; - float diffuse[3]; // field `id` - float specular[3]; // field `is` + Vector3f center; +}; + +class AreaLight : public Light { +public: + AreaLight(const Vector3f &id, const Vector3f &is, + const Matrix &corners) + : Light(Type::Area, id, is), corners(corners) {} + + virtual void illumination() const override; + +private: + Matrix corners; // stores `p1`, `p2`, `p3` and `p4` }; #endif // !LIGHT_H_ From 2e6a248b3c779e82bb9fbb3c8f8a12db2874ceb2 Mon Sep 17 00:00:00 2001 From: vonhyou Date: Sun, 11 Feb 2024 17:54:46 -0500 Subject: [PATCH 5/7] add Light.cc, nothing need to implement yet --- src/Light.cc | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/Light.cc diff --git a/src/Light.cc b/src/Light.cc new file mode 100644 index 0000000..5c44cc5 --- /dev/null +++ b/src/Light.cc @@ -0,0 +1 @@ +#include "Light.h" From 287fdec97bd31b9290cd04e9eb9b1cbdfc1bc143 Mon Sep 17 00:00:00 2001 From: vonhyou Date: Sun, 11 Feb 2024 18:00:14 -0500 Subject: [PATCH 6/7] declare setters for optional members --- src/Light.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Light.h b/src/Light.h index 2e913cc..31ec15a 100644 --- a/src/Light.h +++ b/src/Light.h @@ -13,7 +13,6 @@ public: enum class Type { Point, Area }; virtual ~Light() = default; - // a pure virtual function for derived class implementation virtual void illumination() const = 0; @@ -27,6 +26,12 @@ protected: Matrix4f transform = Matrix4f::Identity(); // optional member `transform` unsigned int gridSize = 0; // optional member `n` bool useCenter = false; // optional member `usecenter` + +public: + // setters for optional members + void setTransform(const Matrix4f &); + void setGridSize(unsigned int); + void setUseCenter(bool); }; class PointLight : public Light { From f3f534a8fe3b0431b64f4e9ac66b004a97a94a48 Mon Sep 17 00:00:00 2001 From: vonhyou Date: Sun, 11 Feb 2024 18:07:04 -0500 Subject: [PATCH 7/7] implement setters --- src/Light.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Light.cc b/src/Light.cc index 5c44cc5..dddb575 100644 --- a/src/Light.cc +++ b/src/Light.cc @@ -1 +1,9 @@ #include "Light.h" + +void Light::setTransform(const Matrix4f &transform) { + this->transform = transform; +} + +void Light::setGridSize(unsigned int gridSize) { this->gridSize = gridSize; } + +void Light::setUseCenter(bool useCenter) { this->useCenter = useCenter; }