diff options
Diffstat (limited to 'src/fb')
| -rw-r--r-- | src/fb/chfb.cpp | 7 | ||||
| -rw-r--r-- | src/fb/chfb.hpp | 5 | ||||
| -rw-r--r-- | src/fb/pixfb.cpp | 9 | ||||
| -rw-r--r-- | src/fb/pixfb.hpp | 5 |
4 files changed, 11 insertions, 15 deletions
diff --git a/src/fb/chfb.cpp b/src/fb/chfb.cpp index 9f293ed..7341015 100644 --- a/src/fb/chfb.cpp +++ b/src/fb/chfb.cpp @@ -8,6 +8,7 @@ using namespace engine::fb; using + engine::math::Vector2, engine::math::Vector3, engine::o3d::VertexData, engine::o3d::Camera; @@ -31,10 +32,8 @@ void CharacterFrameBuffer::clear() { 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 VertexData& vd, const Vector3& normal) { - (void) loc; - (void) vd; - auto v = normal.rot(camera->transform.rot.conjugate()); +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<float>(sizeof(brightness_chars) - 1)); chars_vector[x + y * w] = brightness_chars[c]; diff --git a/src/fb/chfb.hpp b/src/fb/chfb.hpp index 7f6857b..1748abf 100644 --- a/src/fb/chfb.hpp +++ b/src/fb/chfb.hpp @@ -7,14 +7,13 @@ namespace engine::fb { -using engine::math::Vector3, engine::o3d::VertexData; - class CharacterFrameBuffer { public: CharacterFrameBuffer(unsigned int w, unsigned int h); void resize(unsigned int w, unsigned int h); void clear(); - void draw_point(int x, int y, const Vector3& loc, const VertexData& vd, const Vector3& normal); + void draw_point(int x, int y, const engine::math::Vector3& loc, + const engine::math::Vector3& normal, const engine::math::Vector2& uv, const engine::o3d::VertexData& vd); constexpr unsigned int width() const & { return w; diff --git a/src/fb/pixfb.cpp b/src/fb/pixfb.cpp index b38ec30..c629adb 100644 --- a/src/fb/pixfb.cpp +++ b/src/fb/pixfb.cpp @@ -8,6 +8,7 @@ using namespace engine::fb; using + engine::math::Vector2, engine::math::Vector3, engine::o3d::VertexData, engine::o3d::Camera; @@ -29,17 +30,15 @@ void PixelFrameBuffer::clear() { extern Camera* camera; -void PixelFrameBuffer::draw_point(int x, int y, const Vector3& loc, const VertexData& vd, const Vector3& normal) { - (void) loc; - (void) vd; +void PixelFrameBuffer::draw_point(int x, int y, const Vector3& /* loc */, const Vector3& normal, const Vector2& /* uv */, const VertexData& vd) { auto u = vd.world_loc - camera->transform.loc; float u_len_sq = u.length_squared(); u = u.normalize(); - float attenuation = Vector3(0.f, 0.f, -1.f).rot(camera->transform.rot).dot(u); + float attenuation = camera->transform.rot.rot({ 0.f, 0.f, -1.f }).dot(u); if (attenuation < .7f) attenuation = 0.f; else if (attenuation > .8f) attenuation = 1.f; else attenuation = (attenuation - .7f) / .1f; - float light = -normal.dot(u) / u_len_sq; + float light = -normal.normalize().dot(u) / u_len_sq; if (light < 0.f) light = 0.f; float final_light = .003f + light * attenuation * .8f * .997f; if (final_light > 1.f) final_light = 1.f; diff --git a/src/fb/pixfb.hpp b/src/fb/pixfb.hpp index 92fa604..954f6e1 100644 --- a/src/fb/pixfb.hpp +++ b/src/fb/pixfb.hpp @@ -8,14 +8,13 @@ namespace engine::fb { -using engine::math::Vector3, engine::o3d::VertexData; - class PixelFrameBuffer { public: PixelFrameBuffer(unsigned int w, unsigned int h); void resize(unsigned int w, unsigned int h); void clear(); - void draw_point(int x, int y, const Vector3& loc, const VertexData& vd, const Vector3& normal); + void draw_point(int x, int y, const engine::math::Vector3& loc, + const engine::math::Vector3& normal, const engine::math::Vector2& uv, const engine::o3d::VertexData& vd); constexpr unsigned int width() const & { return w; |
