mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 15:31:59 +00:00
Merge pull request #2 from vonhyou/light-parser
Add Light related classes
This commit is contained in:
commit
21ae034dd4
4 changed files with 71 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
build/
|
build/
|
||||||
*.ppm
|
*.ppm
|
||||||
|
*.zip
|
||||||
|
|
9
src/Light.cc
Normal file
9
src/Light.cc
Normal file
|
@ -0,0 +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; }
|
60
src/Light.h
Normal file
60
src/Light.h
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#ifndef LIGHT_H_
|
||||||
|
#define LIGHT_H_
|
||||||
|
|
||||||
|
#include <Eigen/Core>
|
||||||
|
|
||||||
|
using Eigen::Matrix;
|
||||||
|
using Eigen::Matrix4f;
|
||||||
|
using Eigen::Vector3f;
|
||||||
|
|
||||||
|
// Abstract base class for Lights
|
||||||
|
class Light {
|
||||||
|
public:
|
||||||
|
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`
|
||||||
|
|
||||||
|
public:
|
||||||
|
// setters for optional members
|
||||||
|
void setTransform(const Matrix4f &);
|
||||||
|
void setGridSize(unsigned int);
|
||||||
|
void setUseCenter(bool);
|
||||||
|
};
|
||||||
|
|
||||||
|
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:
|
||||||
|
Vector3f center;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AreaLight : public Light {
|
||||||
|
public:
|
||||||
|
AreaLight(const Vector3f &id, const Vector3f &is,
|
||||||
|
const Matrix<float, 3, 4> &corners)
|
||||||
|
: Light(Type::Area, id, is), corners(corners) {}
|
||||||
|
|
||||||
|
virtual void illumination() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Matrix<float, 3, 4> corners; // stores `p1`, `p2`, `p3` and `p4`
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !LIGHT_H_
|
|
@ -7,12 +7,12 @@
|
||||||
class RayTracer {
|
class RayTracer {
|
||||||
public:
|
public:
|
||||||
RayTracer(const nlohmann::json &);
|
RayTracer(const nlohmann::json &);
|
||||||
void render();
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Scene scene;
|
Scene scene;
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
|
void render();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !RAY_TRACER_H_
|
#endif // !RAY_TRACER_H_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue