blob: a8d6bee0e45465cfa1a6ad9c6f860445cfb5bed7 (
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
34
35
36
37
38
|
#include "fb/pixfb.h"
#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);
}
void PixelFrameBuffer::resize(unsigned int w, unsigned int h) {
this->w = w;
this->h = h;
pixels_vector.resize(w * h);
clear();
}
void PixelFrameBuffer::clear() {
std::fill(pixels_vector.begin(), pixels_vector.end(), 0x000000FF);
}
extern engine::math::Quaternion camera_quat;
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;
}
|