#include "fb/chfb.hpp" #include #include #include "math/vector.hpp" #include "math/quat.hpp" #include "o3d/vertex_data.hpp" #include "o3d/camera.hpp" using namespace engine::fb; using engine::math::Vector2, engine::math::Vector3, engine::o3d::VertexData, engine::o3d::Camera; 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%&@"; extern Camera* camera; void CharacterFrameBuffer::draw_point(int x, int y, const Vector3& /* loc */, const Vector3& normal, const Vector2& /* uv */, const VertexData& /* vd */) { auto v = camera->transform.rot.conjugate().rot(normal).normalize(); float light = .1f + (v.z < 0.f ? 0.f : v.z) * .9f; std::uint32_t c = (int) (light * static_cast(sizeof(brightness_chars) - 1)); chars_vector[x + y * w] = brightness_chars[c]; }