mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
commit
4912d6c1d3
4 changed files with 39 additions and 37 deletions
|
@ -1,18 +1,6 @@
|
|||
#include "RayTracer.h"
|
||||
#include "../external/simpleppm.h"
|
||||
#include "Scene.h"
|
||||
|
||||
#include <vector>
|
||||
RayTracer::RayTracer(const nlohmann::json &json) : json(json) {}
|
||||
|
||||
RayTracer::RayTracer(const nlohmann::json &json)
|
||||
: json(json), scene(Scene(json["output"])) {}
|
||||
|
||||
void RayTracer::render() {
|
||||
int width = scene.getWidth();
|
||||
int height = scene.getHeight();
|
||||
|
||||
std::vector<double> buffer(3 * width * height);
|
||||
save_ppm(scene.getName(), buffer, width, height);
|
||||
}
|
||||
|
||||
void RayTracer::run() { render(); }
|
||||
void RayTracer::run() {}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define RAY_TRACER_H_
|
||||
|
||||
#include "../external/json.hpp"
|
||||
#include "Scene.h"
|
||||
|
||||
class RayTracer {
|
||||
public:
|
||||
|
@ -10,9 +9,7 @@ public:
|
|||
void run();
|
||||
|
||||
private:
|
||||
Scene scene;
|
||||
nlohmann::json json;
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif // !RAY_TRACER_H_
|
||||
|
|
27
src/Scene.cc
27
src/Scene.cc
|
@ -1,18 +1,17 @@
|
|||
#include "Scene.h"
|
||||
|
||||
Scene::Scene(const nlohmann::json &output) {
|
||||
for (auto i = output.begin(); i != output.end(); ++i) {
|
||||
if (i->contains("filename")) {
|
||||
this->name = (*i)["filename"].get<string>();
|
||||
}
|
||||
|
||||
if (i->contains("size")) {
|
||||
this->width = (*i)["size"].at(0).get<int>();
|
||||
this->height = (*i)["size"].at(1).get<int>();
|
||||
}
|
||||
}
|
||||
void Scene::setRaysPerPixel(const Eigen::VectorXi &raysPerPixel) {
|
||||
this->raysPerPixel = raysPerPixel;
|
||||
}
|
||||
|
||||
string Scene::getName() { return this->name; }
|
||||
int Scene::getWidth() { return this->width; }
|
||||
int Scene::getHeight() { return this->height; }
|
||||
void Scene::setAntialiasing(bool antialiasing) {
|
||||
this->antialiasing = antialiasing;
|
||||
}
|
||||
|
||||
void Scene::setTwoSideRender(bool twoSideRender) {
|
||||
this->twoSideRender = twoSideRender;
|
||||
}
|
||||
|
||||
void Scene::setGlobalIllum(bool globalIllum) {
|
||||
this->globalIllum = globalIllum;
|
||||
}
|
||||
|
|
30
src/Scene.h
30
src/Scene.h
|
@ -1,23 +1,41 @@
|
|||
#ifndef SCENE_H_
|
||||
#define SCENE_H_
|
||||
|
||||
#include "../external/json.hpp"
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <string>
|
||||
|
||||
using Eigen::Vector3f;
|
||||
using std::string;
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene(const nlohmann::json &);
|
||||
string getName();
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
Scene(string name, int width, int height, float fov, const Vector3f ¢er,
|
||||
const Vector3f &up, const Vector3f &lookAt, const Vector3f &ai,
|
||||
const Vector3f &bgc)
|
||||
: name(name), width(width), height(height), fov(fov), center(center),
|
||||
up(up), lookAt(lookAt), ai(ai), backgroundColor(bgc) {}
|
||||
|
||||
private:
|
||||
string name;
|
||||
int width;
|
||||
int height;
|
||||
float fov;
|
||||
Vector3f center;
|
||||
Vector3f up;
|
||||
Vector3f lookAt;
|
||||
Vector3f ai; // ambient intensity
|
||||
Vector3f backgroundColor;
|
||||
|
||||
Eigen::VectorXi raysPerPixel;
|
||||
bool antialiasing = false;
|
||||
bool twoSideRender = false;
|
||||
bool globalIllum = false;
|
||||
|
||||
public:
|
||||
void setRaysPerPixel(const Eigen::VectorXi &);
|
||||
void setAntialiasing(bool);
|
||||
void setTwoSideRender(bool);
|
||||
void setGlobalIllum(bool);
|
||||
};
|
||||
|
||||
#endif // !SCENE_H_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue