mirror of
https://github.com/vonhyou/ray-tracer-comp371.git
synced 2025-06-07 23:12:00 +00:00
add progress bar
This commit is contained in:
parent
4d4c257ef1
commit
0d450261a7
3 changed files with 36 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
#ifndef OPTIONAL_H_
|
||||
#define OPTIONAL_H_
|
||||
|
||||
namespace utils {
|
||||
|
||||
|
|
29
src/Progress.h
Normal file
29
src/Progress.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef PROGRESS_H_
|
||||
#define PROGRESS_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace utils {
|
||||
|
||||
#define BAR_WIDTH 70
|
||||
|
||||
class Progress {
|
||||
public:
|
||||
static void of(float p) {
|
||||
std::cout << "[";
|
||||
int pos = BAR_WIDTH * p;
|
||||
for (int i = 0; i < BAR_WIDTH; ++i) {
|
||||
if (i < pos)
|
||||
std::cout << "=";
|
||||
else if (i == pos)
|
||||
std::cout << ">";
|
||||
else
|
||||
std::cout << " ";
|
||||
}
|
||||
std::cout << "] " << int(p * 100.0) << " %\r";
|
||||
std::cout.flush();
|
||||
}
|
||||
};
|
||||
} // namespace utils
|
||||
|
||||
#endif // !PROGRESS_H_
|
|
@ -2,6 +2,7 @@
|
|||
#include "HitRecord.h"
|
||||
#include "Output.h"
|
||||
#include "Parser.h"
|
||||
#include "Progress.h"
|
||||
#include "Ray.h"
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
@ -70,7 +71,8 @@ void RayTracer::render() {
|
|||
rpp = raysPerPixel.z();
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int y = 0; y < height; ++y) {
|
||||
utils::Progress::of((y + 1.0f) / height);
|
||||
for (int x = 0; x < width; ++x)
|
||||
for (int j = 0; j < gridHeight; ++j)
|
||||
for (int i = 0; i < gridWidth; ++i) {
|
||||
|
@ -88,6 +90,9 @@ void RayTracer::render() {
|
|||
calculateColor(hit, y * width + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void RayTracer::run() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue