added origin to mapper parameters
This commit is contained in:
+3
-3
@@ -38,16 +38,16 @@ int main(void) {
|
|||||||
|
|
||||||
UwU::Surface surface = UwU::Surface(w, h, onKey);
|
UwU::Surface surface = UwU::Surface(w, h, onKey);
|
||||||
|
|
||||||
UwU::Color fuchsia = UwU::Color(0xb00b69ff);
|
// UwU::Color fuchsia = UwU::Color(0xb00b69ff);
|
||||||
UwU::Color red = UwU::Color(0xff0000ff);
|
UwU::Color red = UwU::Color(0xff0000ff);
|
||||||
UwU::Color green = UwU::Color(0x00ff00ff);
|
UwU::Color green = UwU::Color(0x00ff00ff);
|
||||||
UwU::Color blue = UwU::Color(0x0000ffff);
|
UwU::Color blue = UwU::Color(0x0000ffff);
|
||||||
|
|
||||||
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
|
// UwU::ColorShader fuchsia = UwU::ColorShader(UwU::Color(0xb00b69ff));
|
||||||
UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, red, blue);
|
UwU::VGradientShader bisexual = UwU::VGradientShader(0, 351, red, blue);
|
||||||
UwU::OffsetMapper rectMapper = UwU::OffsetMapper(69, 69);
|
UwU::OffsetMapper offsetMapper = UwU::OffsetMapper();
|
||||||
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
|
UwU::Rectangle rectangle = UwU::Rectangle(69, 69, 420, 420);
|
||||||
rectangle.draw(surface.buffer, rectMapper, bisexual);
|
rectangle.draw(surface.buffer, offsetMapper, bisexual);
|
||||||
|
|
||||||
UwU::ColorShader greenShader = UwU::ColorShader(green);
|
UwU::ColorShader greenShader = UwU::ColorShader(green);
|
||||||
UwU::NullMapper nullMapper = UwU::NullMapper();
|
UwU::NullMapper nullMapper = UwU::NullMapper();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace UwU {
|
|||||||
template <class MapperT>
|
template <class MapperT>
|
||||||
class MapperBase {
|
class MapperBase {
|
||||||
public:
|
public:
|
||||||
Coord2 map(uint16_t x, uint16_t y) {
|
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
|
||||||
return static_cast<MapperT*>(this)->map(x, y);
|
return static_cast<MapperT*>(this)->map(x0, y0, x, y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,9 @@ namespace UwU {
|
|||||||
public:
|
public:
|
||||||
NullMapper() {}
|
NullMapper() {}
|
||||||
|
|
||||||
Coord2 map(uint16_t x, uint16_t y) {
|
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
|
||||||
|
(void)x0;
|
||||||
|
(void)y0;
|
||||||
return Coord2(x, y);
|
return Coord2(x, y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,13 +9,9 @@
|
|||||||
namespace UwU {
|
namespace UwU {
|
||||||
class OffsetMapper : public MapperBase<OffsetMapper> {
|
class OffsetMapper : public MapperBase<OffsetMapper> {
|
||||||
public:
|
public:
|
||||||
OffsetMapper(uint16_t x0, uint16_t y0) {
|
OffsetMapper() {}
|
||||||
this->x0 = x0;
|
|
||||||
this->y0 = y0;
|
|
||||||
}
|
|
||||||
uint16_t x0, y0;
|
|
||||||
|
|
||||||
Coord2 map(uint16_t x, uint16_t y) {
|
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
|
||||||
uint16_t u = x -x0;
|
uint16_t u = x -x0;
|
||||||
uint16_t v = y -y0;
|
uint16_t v = y -y0;
|
||||||
return Coord2(u, v);
|
return Coord2(u, v);
|
||||||
|
|||||||
@@ -9,13 +9,9 @@
|
|||||||
namespace UwU {
|
namespace UwU {
|
||||||
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
|
class TileMapper : public MapperBase<TileMapper> { // not actually tilemapping yet
|
||||||
public:
|
public:
|
||||||
TileMapper(uint16_t x0, uint16_t y0) {
|
TileMapper() {}
|
||||||
this->x0 = x0;
|
|
||||||
this->y0 = y0;
|
|
||||||
}
|
|
||||||
uint16_t x0, y0;
|
|
||||||
|
|
||||||
Coord2 map(uint16_t x, uint16_t y) {
|
Coord2 map(uint16_t x0, uint16_t y0, uint16_t x, uint16_t y) {
|
||||||
uint16_t u = x -x0;
|
uint16_t u = x -x0;
|
||||||
uint16_t v = y -y0;
|
uint16_t v = y -y0;
|
||||||
return Coord2(u, v);
|
return Coord2(u, v);
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ namespace UwU {
|
|||||||
Coord2 uv;
|
Coord2 uv;
|
||||||
|
|
||||||
for (int16_t x = ix0; x < ix1; x++) {
|
for (int16_t x = ix0; x < ix1; x++) {
|
||||||
uv = mapper.map(x, y);
|
uv = mapper.map(ix0, iy0, x, y);
|
||||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
y += yi;
|
y += yi;
|
||||||
@@ -56,7 +56,7 @@ namespace UwU {
|
|||||||
Coord2 uv;
|
Coord2 uv;
|
||||||
|
|
||||||
for (int16_t y = iy0; y < iy1; y++) {
|
for (int16_t y = iy0; y < iy1; y++) {
|
||||||
uv = mapper.map(x, y);
|
uv = mapper.map(ix0, iy0, x, y);
|
||||||
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
buffer.drawPixel((uint16_t)x, (uint16_t)y, shader.shade(uv.x, uv.y));
|
||||||
if (d > 0) {
|
if (d > 0) {
|
||||||
x += xi;
|
x += xi;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace UwU {
|
|||||||
template <class MapperT, class ShaderT>
|
template <class MapperT, class ShaderT>
|
||||||
void draw (Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
void draw (Buffer buffer, MapperBase<MapperT>& mapper, ShaderBase<ShaderT>& shader) {
|
||||||
if (x > buffer.width || y > buffer.height) {return;};
|
if (x > buffer.width || y > buffer.height) {return;};
|
||||||
Coord2 uv = mapper.map(x, y);
|
Coord2 uv = mapper.map(x, y, x, y);
|
||||||
buffer.drawPixel(x, y, shader.shade(uv.x, uv.y));
|
buffer.drawPixel(x, y, shader.shade(uv.x, uv.y));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace UwU {
|
|||||||
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
|
||||||
for (uint16_t y = y0; y <= y1; y++) {
|
for (uint16_t y = y0; y <= y1; y++) {
|
||||||
for (uint16_t x = x0; x <= x1; x++) {
|
for (uint16_t x = x0; x <= x1; x++) {
|
||||||
Coord2 uv = mapper.map(x, y);
|
Coord2 uv = mapper.map(x0, y0, x, y);
|
||||||
buffer.drawPixel(x, y, shader.shade(uv.x, uv.y));
|
buffer.drawPixel(x, y, shader.shade(uv.x, uv.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ namespace UwU {
|
|||||||
Helpers::bresenham(0, xl0, y1 - y0, xl1, LeftBound);
|
Helpers::bresenham(0, xl0, y1 - y0, xl1, LeftBound);
|
||||||
Helpers::bresenham(0, xr0, y1 - y0, xr1, RightBound);
|
Helpers::bresenham(0, xr0, y1 - y0, xr1, RightBound);
|
||||||
|
|
||||||
|
uint16_t x0 = std::min(xl0, xl1);
|
||||||
|
|
||||||
for (uint16_t i = 0; i < height; i++) {
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
|
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
|
||||||
Coord2 uv = mapper.map(x, i + y0);
|
Coord2 uv = mapper.map(x0, y0, x, i + y0);
|
||||||
buffer.drawPixel(x, i + y0, shader.shade(uv.x, uv.y));
|
buffer.drawPixel(x, i + y0, shader.shade(uv.x, uv.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,13 +91,15 @@ namespace UwU {
|
|||||||
// Calculate LUT for short two lines
|
// Calculate LUT for short two lines
|
||||||
Helpers::bresenham(0, topX, midY - topY, midX, splitBound);
|
Helpers::bresenham(0, topX, midY - topY, midX, splitBound);
|
||||||
Helpers::bresenham(midY - topY, midX, height - 1, btmX, splitBound);
|
Helpers::bresenham(midY - topY, midX, height - 1, btmX, splitBound);
|
||||||
|
|
||||||
Coord2 uv;
|
Coord2 uv;
|
||||||
|
uint16_t leftX = std::min(topX, std::min(midX, btmX));
|
||||||
|
|
||||||
// Left-handed triangle case (midpoint is left of triangle)
|
// Left-handed triangle case (midpoint is left of triangle)
|
||||||
if ((int16_t)midX < longBound[midY - topY]) {
|
if ((int16_t)midX < longBound[midY - topY]) {
|
||||||
for (uint16_t i = 0; i < height; i++) {
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
|
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
|
||||||
uv = mapper.map(x, i + (uint16_t)topY);
|
uv = mapper.map(leftX, topY, x, i + (uint16_t)topY);
|
||||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +107,7 @@ namespace UwU {
|
|||||||
} else {
|
} else {
|
||||||
for (uint16_t i = 0; i < height; i++) {
|
for (uint16_t i = 0; i < height; i++) {
|
||||||
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
|
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
|
||||||
uv = mapper.map(x, i + (uint16_t)topY);
|
uv = mapper.map(leftX, topY, x, i + (uint16_t)topY);
|
||||||
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
buffer.drawPixel(x, i + (uint16_t)topY, shader.shade(uv.x, uv.y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user