mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-08 07:22:01 +00:00
reformat rt
This commit is contained in:
parent
368039b57c
commit
9aaed2d6e8
3 changed files with 41 additions and 41 deletions
|
@ -43,11 +43,11 @@ void RayTracer::calculateColor(const HitRecord &hit, Output *buffer, int i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayTracer::render(Scene *scene) {
|
void RayTracer::render(Scene *scene) {
|
||||||
int width = scene->getWidth();
|
int width = scene->width();
|
||||||
int height = scene->getHeight();
|
int height = scene->height();
|
||||||
Vector3f cameraPos = scene->getCenter();
|
Vector3f cameraPos = scene->center();
|
||||||
Vector3f lookAt = scene->getLookAt();
|
Vector3f lookAt = scene->lookAt();
|
||||||
float vpHeight = 2 * tan(scene->getFov() / 180 * M_PI / 2) * lookAt.norm();
|
float vpHeight = 2 * tan(scene->fov() / 180 * M_PI / 2) * lookAt.norm();
|
||||||
float vpWidth = vpHeight * width / height;
|
float vpWidth = vpHeight * width / height;
|
||||||
Vector3f vpU = Vector3f(vpWidth, 0, 0);
|
Vector3f vpU = Vector3f(vpWidth, 0, 0);
|
||||||
Vector3f vpV = Vector3f(0, -vpHeight, 0);
|
Vector3f vpV = Vector3f(0, -vpHeight, 0);
|
||||||
|
@ -58,7 +58,7 @@ void RayTracer::render(Scene *scene) {
|
||||||
Vector3f pxUpperLeft = vpUpperLeft + (du + dv) / 2.0;
|
Vector3f pxUpperLeft = vpUpperLeft + (du + dv) / 2.0;
|
||||||
|
|
||||||
Output *buffer =
|
Output *buffer =
|
||||||
new Output(scene->getBackgroundColor(), scene->getName(), width, height);
|
new Output(scene->backgroundColor(), scene->name(), width, height);
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y)
|
for (int y = 0; y < height; ++y)
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < width; ++x) {
|
||||||
|
|
24
src/Scene.cc
24
src/Scene.cc
|
@ -1,33 +1,33 @@
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
|
|
||||||
string Scene::getName() const { return name; }
|
string Scene::name() const { return name_; }
|
||||||
|
|
||||||
int Scene::getWidth() { return width; }
|
int Scene::width() { return width_; }
|
||||||
|
|
||||||
int Scene::getHeight() { return height; }
|
int Scene::height() { return height_; }
|
||||||
|
|
||||||
float Scene::getFov() { return fov; }
|
float Scene::fov() { return fov_; }
|
||||||
|
|
||||||
Vector3f Scene::getCenter() const { return center; }
|
Vector3f Scene::center() const { return center_; }
|
||||||
|
|
||||||
Vector3f Scene::getUpVector() const { return up; }
|
Vector3f Scene::up() const { return up_; }
|
||||||
|
|
||||||
Vector3f Scene::getLookAt() const { return lookAt; }
|
Vector3f Scene::lookAt() const { return lookAt_; }
|
||||||
|
|
||||||
Vector3f Scene::getBackgroundColor() const { return backgroundColor; }
|
Vector3f Scene::backgroundColor() const { return bgc_; }
|
||||||
|
|
||||||
void Scene::setRaysPerPixel(const Eigen::VectorXi &raysPerPixel) {
|
void Scene::setRaysPerPixel(const Eigen::VectorXi &raysPerPixel) {
|
||||||
this->raysPerPixel = raysPerPixel;
|
this->raysPerPixel_ = raysPerPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setAntialiasing(bool antialiasing) {
|
void Scene::setAntialiasing(bool antialiasing) {
|
||||||
this->antialiasing = antialiasing;
|
this->antialiasing_ = antialiasing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setTwoSideRender(bool twoSideRender) {
|
void Scene::setTwoSideRender(bool twoSideRender) {
|
||||||
this->twoSideRender = twoSideRender;
|
this->twoSideRender_ = twoSideRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::setGlobalIllum(bool globalIllum) {
|
void Scene::setGlobalIllum(bool globalIllum) {
|
||||||
this->globalIllum = globalIllum;
|
this->globalIllum_ = globalIllum;
|
||||||
}
|
}
|
||||||
|
|
46
src/Scene.h
46
src/Scene.h
|
@ -12,34 +12,34 @@ public:
|
||||||
Scene(string name, int width, int height, float fov, const Vector3f ¢er,
|
Scene(string name, int width, int height, float fov, const Vector3f ¢er,
|
||||||
const Vector3f &up, const Vector3f &lookAt, const Vector3f &ai,
|
const Vector3f &up, const Vector3f &lookAt, const Vector3f &ai,
|
||||||
const Vector3f &bgc)
|
const Vector3f &bgc)
|
||||||
: name(name), width(width), height(height), fov(fov), center(center),
|
: name_(name), width_(width), height_(height), fov_(fov), center_(center),
|
||||||
up(up), lookAt(lookAt), ai(ai), backgroundColor(bgc) {}
|
up_(up), lookAt_(lookAt), ai_(ai), bgc_(bgc) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string name;
|
string name_;
|
||||||
int width;
|
int width_;
|
||||||
int height;
|
int height_;
|
||||||
float fov;
|
float fov_;
|
||||||
Vector3f center;
|
Vector3f center_;
|
||||||
Vector3f up;
|
Vector3f up_;
|
||||||
Vector3f lookAt;
|
Vector3f lookAt_;
|
||||||
Vector3f ai; // ambient intensity
|
Vector3f ai_; // ambient intensity
|
||||||
Vector3f backgroundColor;
|
Vector3f bgc_;
|
||||||
|
|
||||||
Eigen::VectorXi raysPerPixel;
|
Eigen::VectorXi raysPerPixel_;
|
||||||
bool antialiasing = false;
|
bool antialiasing_ = false;
|
||||||
bool twoSideRender = false;
|
bool twoSideRender_ = false;
|
||||||
bool globalIllum = false;
|
bool globalIllum_ = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
string getName() const;
|
string name() const;
|
||||||
int getWidth();
|
int width();
|
||||||
int getHeight();
|
int height();
|
||||||
float getFov();
|
float fov();
|
||||||
Vector3f getCenter() const;
|
Vector3f center() const;
|
||||||
Vector3f getUpVector() const;
|
Vector3f up() const;
|
||||||
Vector3f getLookAt() const;
|
Vector3f lookAt() const;
|
||||||
Vector3f getBackgroundColor() const;
|
Vector3f backgroundColor() const;
|
||||||
void setRaysPerPixel(const Eigen::VectorXi &);
|
void setRaysPerPixel(const Eigen::VectorXi &);
|
||||||
void setAntialiasing(bool);
|
void setAntialiasing(bool);
|
||||||
void setTwoSideRender(bool);
|
void setTwoSideRender(bool);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue