diff options
Diffstat (limited to 'src/fb/chfb.cpp')
-rw-r--r-- | src/fb/chfb.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/fb/chfb.cpp b/src/fb/chfb.cpp index e2355df..82b8f86 100644 --- a/src/fb/chfb.cpp +++ b/src/fb/chfb.cpp @@ -7,6 +7,8 @@ #include "o3d/tri_vertex.h" #include "o3d/vertex_data.h" +using namespace engine::fb; + CharacterFrameBuffer::CharacterFrameBuffer(unsigned int w, unsigned int h) { resize(w, h); } @@ -37,12 +39,12 @@ void CharacterFrameBuffer::clear() { face_ind = -1; } -void CharacterFrameBuffer::_draw_cropped_triangle(TriangleVertex3 triangle) { - std::array<Vertex3*, 3> sorted_vs = { &triangle.vertex1, &triangle.vertex2, &triangle.vertex3 }; +void CharacterFrameBuffer::_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;\ }\ @@ -52,18 +54,18 @@ void CharacterFrameBuffer::_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; } @@ -123,7 +125,7 @@ void CharacterFrameBuffer::_draw_cropped_triangle(TriangleVertex3 triangle) { } } -void CharacterFrameBuffer::draw_triangle(TriangleVertex4 triangle) { +void CharacterFrameBuffer::draw_triangle(engine::o3d::TriangleVertex4 triangle) { face_ind++; for (auto t1 : triangle.crop_z_out(-1.f, 1.f)) { auto t1_2 = t1.div_by_w(); @@ -131,13 +133,13 @@ void CharacterFrameBuffer::draw_triangle(TriangleVertex4 triangle) { t1_2.vertex2.point.x *= 2.f; t1_2.vertex3.point.x *= 2.f; for (auto t2 : t1_2.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; |