added mappers to rest of primatives
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "../helpers.cpp"
|
||||
#include "../buffer.cpp"
|
||||
#include "../shaders/shaders.h"
|
||||
#include "../mappers/mappers.h"
|
||||
|
||||
namespace UwU {
|
||||
class Triangle {
|
||||
@@ -30,8 +31,8 @@ namespace UwU {
|
||||
uint16_t y2;
|
||||
|
||||
// Draw a triangle
|
||||
template <class ShaderT>
|
||||
void draw (Buffer buffer, ShaderBase<ShaderT>& shader) {
|
||||
template <class MapperT, class ShaderT>
|
||||
void draw (Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
||||
uint16_t topX, topY, midX, midY, btmX, btmY;
|
||||
// Find top, middle and bottom points of triangle
|
||||
if (y0 <= y1 && y0 <= y2) {
|
||||
@@ -90,19 +91,22 @@ namespace UwU {
|
||||
// Calculate LUT for short two lines
|
||||
Helpers::bresenham(0, topX, midY - topY, midX, splitBound);
|
||||
Helpers::bresenham(midY - topY, midX, height - 1, btmX, splitBound);
|
||||
Coord2 uv;
|
||||
|
||||
// Left-handed triangle case (midpoint is left of triangle)
|
||||
if ((int16_t)midX < longBound[midY - topY]) {
|
||||
for (uint16_t i = 0; i < height; i++) {
|
||||
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
|
||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(x, i + (uint16_t)topY));
|
||||
uv = mapper.map(x, i + (uint16_t)topY);
|
||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
||||
}
|
||||
}
|
||||
// Right-handed triangle case (midpoint is right of triangle)
|
||||
} else {
|
||||
for (uint16_t i = 0; i < height; i++) {
|
||||
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
|
||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(x, i + (uint16_t)topY));
|
||||
uv = mapper.map(x, i + (uint16_t)topY);
|
||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user