mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 15:31:59 +00:00
rewrite Light class using Eigen
This commit is contained in:
parent
a73f25c027
commit
a12711e543
1 changed files with 44 additions and 5 deletions
49
src/Light.h
49
src/Light.h
|
@ -1,16 +1,55 @@
|
|||
#ifndef LIGHT_H_
|
||||
#define LIGHT_H_
|
||||
|
||||
enum LIGHT_TYPE { POINT, AREA };
|
||||
#include <Eigen/Core>
|
||||
|
||||
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<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_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue