blob: e7717eb1180a4cd2940e0fb475b9dc4c591a4245 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "fb/chfb.hpp"
#include <algorithm>
#include <cstdint>
#include "math/vector.hpp"
#include "math/quat.hpp"
#include "o3d/camera.hpp"
using namespace engine::fb;
using engine::math::Vector4;
CharacterFrameBuffer::CharacterFrameBuffer(unsigned int w, unsigned int h) {
resize(w, h);
}
void CharacterFrameBuffer::resize(unsigned int w, unsigned int h) {
this->w = w;
this->h = h;
chars_vector.resize(w * h);
clear();
}
void CharacterFrameBuffer::clear() {
std::fill(chars_vector.begin(), chars_vector.end(), ' ');
}
// taken from https://stackoverflow.com/a/74186686
char brightness_chars[] = " `.-':_,^=;><+!rc*/z?sLTv)J7(|Fi{C}fI31tlu[neoZ5Yxjya]2ESwqkP6h9d4VpOGbUAKXHm8RD#$Bg0MNWQ%&@";
void CharacterFrameBuffer::draw_point(int x, int y, const Vector4& point) {
float light = .2126f * point.x + .7152f * point.y + .0722f * point.z;
std::uint32_t c = (int) (light * static_cast<float>(sizeof(brightness_chars) - 1));
chars_vector[x + y * w] = brightness_chars[c];
}
|