aboutsummaryrefslogtreecommitdiff
path: root/src/fb/pixfb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fb/pixfb.cpp')
-rw-r--r--src/fb/pixfb.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/fb/pixfb.cpp b/src/fb/pixfb.cpp
index d4563ca..c9e9927 100644
--- a/src/fb/pixfb.cpp
+++ b/src/fb/pixfb.cpp
@@ -8,6 +8,8 @@
#include "o3d/tri_vertex.h"
#include "o3d/vertex_data.h"
+using namespace engine::fb;
+
PixelFrameBuffer::PixelFrameBuffer(unsigned int w, unsigned int h) {
resize(w, h);
}
@@ -38,12 +40,12 @@ void PixelFrameBuffer::clear() {
face_ind = -1;
}
-void PixelFrameBuffer::_draw_cropped_triangle(TriangleVertex3 triangle) {
- std::array<Vertex3*, 3> sorted_vs = { &triangle.vertex1, &triangle.vertex2, &triangle.vertex3 };
+void PixelFrameBuffer::_draw_cropped_triangle(engine::o3d::TriangleVertex3 triangle) {
+ std::array<engine::o3d::Vertex3*, 3> sorted_vs = { &triangle.vertex1, &triangle.vertex2, &triangle.vertex3 };
#define SWAP_IF_LT(X,Y) ({\
if (sorted_vs[X]->point.y < sorted_vs[Y]->point.y) {\
- Vertex3* temp = sorted_vs[X];\
+ engine::o3d::Vertex3* temp = sorted_vs[X];\
sorted_vs[X] = sorted_vs[Y];\
sorted_vs[Y] = temp;\
}\
@@ -53,18 +55,18 @@ void PixelFrameBuffer::_draw_cropped_triangle(TriangleVertex3 triangle) {
SWAP_IF_LT(1, 0);
#undef SWAP_IF_LT
- Vertex3 middle_vl = *sorted_vs[1];
+ engine::o3d::Vertex3 middle_vl = *sorted_vs[1];
float fac = (sorted_vs[1]->point.y - sorted_vs[0]->point.y) / (sorted_vs[2]->point.y - sorted_vs[0]->point.y);
- Vertex3 middle_vr{
+ engine::o3d::Vertex3 middle_vr{
{
sorted_vs[0]->point.x + fac * (sorted_vs[2]->point.x - sorted_vs[0]->point.x),
sorted_vs[1]->point.y,
sorted_vs[0]->point.z + fac * (sorted_vs[2]->point.z - sorted_vs[0]->point.z)
},
- VertexData::lerp(sorted_vs[0]->data, sorted_vs[2]->data, fac)
+ engine::o3d::VertexData::lerp(sorted_vs[0]->data, sorted_vs[2]->data, fac)
};
if (middle_vr.point.x < middle_vl.point.x) {
- Vertex3 temp = middle_vr;
+ engine::o3d::Vertex3 temp = middle_vr;
middle_vr = middle_vl;
middle_vl = temp;
}
@@ -124,17 +126,17 @@ void PixelFrameBuffer::_draw_cropped_triangle(TriangleVertex3 triangle) {
}
}
-void PixelFrameBuffer::draw_triangle(TriangleVertex4 triangle) {
+void PixelFrameBuffer::draw_triangle(engine::o3d::TriangleVertex4 triangle) {
face_ind++;
for (auto t1 : triangle.crop_z_out(-1.f, 1.f)) {
for (auto t2 : t1.div_by_w().crop_xy_out(-1.f, 1.f, -1.f, 1.f)) {
- MathVector2 pp1 = t2.vertex1.point.xy(),
- pp2 = t2.vertex2.point.xy(),
- pp3 = t2.vertex3.point.xy();
+ engine::math::MathVector2 pp1 = t2.vertex1.point.xy(),
+ pp2 = t2.vertex2.point.xy(),
+ pp3 = t2.vertex3.point.xy();
if ((pp2 - pp1).det(pp3 - pp1) >= 0.f) continue;
- t2.vertex1.point = (t2.vertex1.point + MathVector3{1.f, 1.f, 0.f}) / 2.f;
- t2.vertex2.point = (t2.vertex2.point + MathVector3{1.f, 1.f, 0.f}) / 2.f;
- t2.vertex3.point = (t2.vertex3.point + MathVector3{1.f, 1.f, 0.f}) / 2.f;
+ t2.vertex1.point = (t2.vertex1.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f;
+ t2.vertex2.point = (t2.vertex2.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f;
+ t2.vertex3.point = (t2.vertex3.point + engine::math::MathVector3{1.f, 1.f, 0.f}) / 2.f;
float fw = static_cast<float>(w), fh = static_cast<float>(h);
t2.vertex1.point.x = t2.vertex1.point.x * fw - .5f;
t2.vertex1.point.y = t2.vertex1.point.y * fh - .5f;