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
641b62ca01
commit
60a3180f1e
2 changed files with 11 additions and 10 deletions
|
@ -39,12 +39,13 @@ void RayTracer::calculateColor(const HitRecord &hit, Output *buffer, int i) {
|
||||||
buffer->b(i, result.z());
|
buffer->b(i, result.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayTracer::render(Scene *scene) {
|
void RayTracer::render() {
|
||||||
int width = scene->width();
|
int width = Scene::current->width();
|
||||||
int height = scene->height();
|
int height = Scene::current->height();
|
||||||
Vector3f cameraPos = scene->center();
|
Vector3f cameraPos = Scene::current->center();
|
||||||
Vector3f lookAt = scene->lookAt();
|
Vector3f lookAt = Scene::current->lookAt();
|
||||||
float vpHeight = 2 * tan(scene->fov() / 180 * M_PI / 2) * lookAt.norm();
|
float vpHeight =
|
||||||
|
2 * tan(Scene ::current->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);
|
||||||
|
@ -54,8 +55,8 @@ void RayTracer::render(Scene *scene) {
|
||||||
Vector3f vpUpperLeft = cameraPos + lookAt - vpU / 2.0 - vpV / 2.0;
|
Vector3f vpUpperLeft = cameraPos + lookAt - vpU / 2.0 - vpV / 2.0;
|
||||||
Vector3f pxUpperLeft = vpUpperLeft + (du + dv) / 2.0;
|
Vector3f pxUpperLeft = vpUpperLeft + (du + dv) / 2.0;
|
||||||
|
|
||||||
Output *buffer =
|
Output *buffer = new Output(Scene::current->backgroundColor(),
|
||||||
new Output(scene->backgroundColor(), scene->name(), width, height);
|
Scene::current->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) {
|
||||||
|
@ -87,7 +88,7 @@ void RayTracer::run() {
|
||||||
|
|
||||||
for (auto scene : scenes) {
|
for (auto scene : scenes) {
|
||||||
Scene::current = scene;
|
Scene::current = scene;
|
||||||
render(scene);
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
output();
|
output();
|
||||||
|
|
|
@ -23,7 +23,7 @@ private:
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
void calculateColor(const HitRecord &, Output *, int);
|
void calculateColor(const HitRecord &, Output *, int);
|
||||||
void render(Scene *);
|
void render();
|
||||||
void output();
|
void output();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue