add geometry parser

This commit is contained in:
Shuo Feng 2024-02-18 20:21:43 -05:00
parent 9f63434b12
commit 73b90f7535
Signed by: sfeng
GPG key ID: 1E83AE6CD1C037B1
3 changed files with 13 additions and 2 deletions

View file

@ -71,9 +71,13 @@ Geometry *Parser::getGeometry(const nlohmann::json &j) {
return g; return g;
} }
// TODO: return four corners for rectangles and area lights // helper function to get four corners of a rectangle
const Matrix<float, 3, 4> getCorners(const nlohmann::json &j) { const Matrix<float, 3, 4> getCorners(const nlohmann::json &j) {
return Matrix<float, 3, 4>(); 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,

View file

@ -9,6 +9,9 @@ using std::vector;
void RayTracer::parse() { void RayTracer::parse() {
for (auto i = json["output"].begin(); i != json["output"].end(); ++i) for (auto i = json["output"].begin(); i != json["output"].end(); ++i)
scenes.push_back(Parser::getScene(*i)); scenes.push_back(Parser::getScene(*i));
for (auto i = json["geometry"].begin(); i != json["geometry"].end(); ++i)
geometries.push_back(Parser::getGeometry(*i));
} }
void RayTracer::render() {} void RayTracer::render() {}

View file

@ -2,6 +2,8 @@
#define RAY_TRACER_H_ #define RAY_TRACER_H_
#include "../external/json.hpp" #include "../external/json.hpp"
#include "Geometry.h"
#include "Light.h"
#include "Scene.h" #include "Scene.h"
#include <vector> #include <vector>
@ -14,6 +16,8 @@ public:
private: private:
nlohmann::json json; nlohmann::json json;
std::vector<Scene *> scenes; std::vector<Scene *> scenes;
std::vector<Light *> lights;
std::vector<Geometry *> geometries;
void parse(); void parse();
void render(); void render();