diff options
author | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
---|---|---|
committer | vimene <vincent.menegaux@gmail.com> | 2024-12-31 03:40:14 +0100 |
commit | cc6fb8c33637566a7b116d46440e6063f016deea (patch) | |
tree | 5cc83f84525507994add57df7dd974e6611d675a /src/fb/pixfb.cpp | |
parent | 6b765a85cf81bf4b7162e4c9280dd4054581c611 (diff) | |
download | engine-cc6fb8c33637566a7b116d46440e6063f016deea.tar.gz |
various improvements
- added quaternions and rewrote all rotations to use them
- added transforms to put all object transforms in a single place
- added Wavefront .obj file parser
- removed frame buffer's abstract class
- improved vectors, matrices, triangles, vertices and vertices data by putting all code in header file
- added vector's operations
- changed from NULL to nullptr
- miscellaneous improvements
Diffstat (limited to 'src/fb/pixfb.cpp')
-rw-r--r-- | src/fb/pixfb.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/fb/pixfb.cpp b/src/fb/pixfb.cpp index 10f2d02..a8d6bee 100644 --- a/src/fb/pixfb.cpp +++ b/src/fb/pixfb.cpp @@ -2,9 +2,11 @@ #include <cstdint> #include <algorithm> #include "math/vector.h" +#include "math/quat.h" #include "o3d/vertex_data.h" using namespace engine::fb; +using engine::math::Vector3, engine::o3d::VertexData; PixelFrameBuffer::PixelFrameBuffer(unsigned int w, unsigned int h) { resize(w, h); @@ -17,30 +19,20 @@ void PixelFrameBuffer::resize(unsigned int w, unsigned int h) { clear(); } -unsigned int PixelFrameBuffer::width() const { - return w; -} - -unsigned int PixelFrameBuffer::height() const { - return h; -} - -const uint32_t* PixelFrameBuffer::pixels() const { - return pixels_vector.data(); -} - void PixelFrameBuffer::clear() { std::fill(pixels_vector.begin(), pixels_vector.end(), 0x000000FF); } -void PixelFrameBuffer::draw_point(int x, int y, engine::math::Vector3 loc, const engine::o3d::VertexData& vd) { - (void) loc; - int ir = ((int) (((float) ((int) (vd.tx * 10.f))) * 25.5f)); - int ig = ((int) (((float) ((int) (vd.ty * 10.f))) * 25.5f)); - pixels_vector[x + y * w] = (ir << 24) | (ig << 16) | 0xFFFF; -} +extern engine::math::Quaternion camera_quat; -uint32_t PixelFrameBuffer::face_color(int face_ind) const { - int n = face_ind / 2; - return ((n % 2 ? 0xFF000000 : 0x55000000) >> ((n % 6) / 2 * 8)) | 0xFF; +void PixelFrameBuffer::draw_point(int x, int y, const Vector3& loc, const VertexData& vd, const Vector3& normal) { + (void) loc; + (void) vd; + // int ir = ((int) (((float) ((int) (vd.tx * 10.f))) * 25.5f)); + // int ig = ((int) (((float) ((int) (vd.ty * 10.f))) * 25.5f)); + // pixels_vector[x + y * w] = (ir << 24) | (ig << 16) | 0xFFFF; + 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 * 255.f); + pixels_vector[x + y * w] = c << 24 | c << 16 | c << 8 | 0xff; } |