diff options
author | vimene <vincent.menegaux@gmail.com> | 2024-12-31 08:58:28 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2024-12-31 08:58:28 +0100 |
commit | 4eede3d13227f2e9be03629db1a299c8119a7c59 (patch) | |
tree | 36d106ee9bfac37f286780c586bfef43c02e2b88 /src/fb/chfb.cpp | |
parent | 1e19d706fc5f5e3490d4ce204a6c5ca56c6614f8 (diff) | |
download | engine-4eede3d13227f2e9be03629db1a299c8119a7c59.tar.gz |
added brightness to terminal frame buffers
Diffstat (limited to 'src/fb/chfb.cpp')
-rw-r--r-- | src/fb/chfb.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/fb/chfb.cpp b/src/fb/chfb.cpp index 98c9f23..71259aa 100644 --- a/src/fb/chfb.cpp +++ b/src/fb/chfb.cpp @@ -1,10 +1,12 @@ #include "fb/chfb.h" #include <algorithm> +#include <cstdint> #include "math/vector.h" +#include "math/quat.h" #include "o3d/vertex_data.h" using namespace engine::fb; -using engine::math::Vector3, engine::o3d::VertexData; +using engine::math::Vector3, engine::math::Quaternion, engine::o3d::VertexData; CharacterFrameBuffer::CharacterFrameBuffer(unsigned int w, unsigned int h) { resize(w, h); @@ -21,11 +23,15 @@ 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%&@"; +extern Quaternion camera_quat; + void CharacterFrameBuffer::draw_point(int x, int y, const Vector3& loc, const VertexData& vd, const Vector3& normal) { - (void) x; - (void) y; (void) loc; (void) vd; - (void) normal; - chars_vector[x + y * w] = 'A'; + auto v = normal.rot(camera_quat.conjugate()); + float light = .1f + (v.z < 0.f ? 0.f : v.z) * .9f; + std::uint32_t c = (int) (light * static_cast<float>(sizeof(brightness_chars) - 1)); + chars_vector[x + y * w] = brightness_chars[c]; } |