mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
add light parser
This commit is contained in:
parent
73b90f7535
commit
e13fd8a438
4 changed files with 46 additions and 2 deletions
|
@ -7,3 +7,7 @@ void Light::setTransform(const Matrix4f &transform) {
|
|||
void Light::setGridSize(unsigned int gridSize) { this->gridSize = gridSize; }
|
||||
|
||||
void Light::setUseCenter(bool useCenter) { this->useCenter = useCenter; }
|
||||
|
||||
void PointLight::illumination() const {}
|
||||
|
||||
void AreaLight::illumination() const {}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Parser.h"
|
||||
#include "Geometry.h"
|
||||
#include "Light.h"
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <string>
|
||||
|
@ -97,3 +98,37 @@ Rectangle *Parser::getRectangle(const nlohmann::json &j, float ka, float kd,
|
|||
|
||||
return new Rectangle(ka, kd, ks, ca, cd, cs, pc, corners);
|
||||
}
|
||||
|
||||
Light *Parser::getLight(const nlohmann::json &j) {
|
||||
Vector3f id = getVector3f(j["id"]);
|
||||
Vector3f is = getVector3f(j["is"]);
|
||||
|
||||
Light *l;
|
||||
if (j["type"].get<string>().compare("point"))
|
||||
l = getAreaLight(j, id, is);
|
||||
else
|
||||
l = getPointLight(j, id, is);
|
||||
|
||||
if (j.contains("transform")) {
|
||||
l->setTransform(getTransform(j["transform"]));
|
||||
}
|
||||
|
||||
l->setGridSize(j.value("n", 0));
|
||||
l->setUseCenter(j.value("usecenter", false));
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
AreaLight *Parser::getAreaLight(const nlohmann::json &j, const Vector3f &id,
|
||||
const Vector3f &is) {
|
||||
Matrix<float, 3, 4> corners = getCorners(j);
|
||||
|
||||
return new AreaLight(id, is, corners);
|
||||
}
|
||||
|
||||
PointLight *Parser::getPointLight(const nlohmann::json &j, const Vector3f &id,
|
||||
const Vector3f &is) {
|
||||
Vector3f center = getVector3f(j["centre"]);
|
||||
|
||||
return new PointLight(id, is, center);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,10 @@ public:
|
|||
static Scene *getScene(const nlohmann::json &);
|
||||
|
||||
private:
|
||||
static PointLight *getPointLight(const nlohmann::json &);
|
||||
static AreaLight *getAreaLight(const nlohmann::json &);
|
||||
static PointLight *getPointLight(const nlohmann::json &, const Vector3f &,
|
||||
const Vector3f &);
|
||||
static AreaLight *getAreaLight(const nlohmann::json &, const Vector3f &,
|
||||
const Vector3f &);
|
||||
static Rectangle *getRectangle(const nlohmann::json &, float, float, float,
|
||||
const Vector3f &, const Vector3f &,
|
||||
const Vector3f &, float);
|
||||
|
|
|
@ -12,6 +12,9 @@ void RayTracer::parse() {
|
|||
|
||||
for (auto i = json["geometry"].begin(); i != json["geometry"].end(); ++i)
|
||||
geometries.push_back(Parser::getGeometry(*i));
|
||||
|
||||
for (auto i = json["light"].begin(); i != json["light"].end(); ++i)
|
||||
lights.push_back(Parser::getLight(*i));
|
||||
}
|
||||
|
||||
void RayTracer::render() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue