correct render of sprite lines!!

This commit is contained in:
Emanuele Trabattoni
2021-05-30 13:03:02 +02:00
parent 539a95df61
commit 7116885f2d
4 changed files with 110 additions and 48 deletions

View File

@@ -66,13 +66,14 @@ namespace Render {
void DrawableLine::render(){
uint8_t* buf = getBuffer();
auto tt = _thickness;
auto dx = engine()->getSize().x;
auto dy = engine()->getSize().y;
auto e = engine();
auto square = [tt,dy,buf,e](uint16_t x, uint16_t y){ //sprite render
auto square = [buf,e,tt](uint16_t x, uint16_t y){
uint8_t c = tt > 1 ? tt>>1 : 0; //sprite render
x -= c;
y -= c;
for (auto xx(0); xx <= tt; ++xx)
for (auto yy(0); yy <= tt; ++yy){
e->setPixel(buf,dy-(yy+y),xx+x,true);
e->setPixel(buf,xx+x,yy+y,true);
}
};
@@ -80,24 +81,28 @@ namespace Render {
_rotation = fmod(_rotation, M_TWOPI);
float cx,sx;
sincosf(_rotation,&sx,&cx); // use optimized float instructions
uint16_t endX = round(cx*(float)_lenght);
uint16_t endY = round(sx*(float)_lenght);
if ((_rotation >= -M_PI_4 && _rotation <= M_PI_4) ||
(_rotation >= 3*M_PI_4 && _rotation <= 5*M_PI_4))
uint16_t endX = fabs(round(cx*(float)_lenght));
uint16_t endY = fabs(round(sx*(float)_lenght));
int8_t mult = (_rotation <= 3*M_PI_4 || _rotation >= 7*M_PI_4) ? 1 : -1;
if ((_rotation >= 7*M_PI_4 || _rotation <= M_PI_4) ||
(_rotation >= 3*M_PI_4 && _rotation <= 5*M_PI_4)) {
for(uint16_t xx(0); xx <= endX; ++xx){
float dydx = cx == 0.0f ? 0 : (sx/cx);
uint16_t y = getOrigin().y+xx*dydx;
uint16_t x = getOrigin().x+xx;
uint16_t y = getOrigin().y+xx*mult*dydx;
uint16_t x = getOrigin().x+xx*mult;
square(x,y);
}
else
} else {
for (uint16_t yy(0); yy <= endY; ++yy){
float dxdy = sx == 0.0f ? 0 : (cx/sx);
uint16_t y = getOrigin().y+yy;
uint16_t x = getOrigin().x+yy*dxdy;
uint16_t y = getOrigin().y+yy*mult;
uint16_t x = getOrigin().x+yy*mult*dxdy;
square(x,y);
}
}
resetDirty();
}
}