even wonkier line...

problems with angles and screen limits,
need to implement screen rotation seriously
This commit is contained in:
Emanuele Trabattoni
2021-05-29 12:55:35 +02:00
parent a77b66e4ef
commit 539a95df61
4 changed files with 54 additions and 28 deletions

View File

@@ -49,8 +49,8 @@ namespace Render {
}
void Mare::setPixel(uint8_t* img, uint16_t x, uint16_t y, bool value){
if (x >= _screenSize.x) return;
if (y >= _screenSize.y) return;
if (x >= _screenSize.y) return;
if (y >= _screenSize.x) return;
img += (sizeof(uint8_t)*y*(_screenSize.x>>3) + sizeof(uint8_t)*(x>>3));
if (value) *img &= ~(0x80 >> (x%8));
else *img |= (0x80 >> (x%8));

View File

@@ -99,7 +99,7 @@ namespace Render{
void clearScreen() {
EPD_2IN9_V2_Clear();
clearBuffer(_screenBufferBackground, _bufferDim, Color::White);
EPD_2IN9_V2_Display_Base(_screenBufferBackground);
EPD_2IN9_V2_Display(_screenBufferBackground);
}
// members

View File

@@ -64,23 +64,40 @@ namespace Render {
}
void DrawableLine::render(){
uint8_t* buf;
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
for (auto xx(0); xx <= tt; ++xx)
for (auto yy(0); yy <= tt; ++yy){
e->setPixel(buf,dy-(yy+y),xx+x,true);
}
};
if (isDirty()) {
buf = getBuffer();
_rotation = fmod(_rotation, M_TWOPI);
float cx,sx;
auto dx = engine()->getSize().x;
auto dy = engine()->getSize().y;
sincosf(_rotation,&sx,&cx); // use optimized float instructions
uint16_t endX = round(cx*(float)_lenght);
for(uint16_t yy(0); yy <= _thickness; ++yy){
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))
for(uint16_t xx(0); xx <= endX; ++xx){
float dydx = cx == 0.0f ? 0 : (sx/cx);
float dxdy = sx == 0.0f ? 0 : (cx/sx);
uint16_t y = getOrigin().y+yy+xx*dydx;
uint16_t x = dx-(getOrigin().x+xx+yy);
engine()->setPixel(buf,x,y,true);
uint16_t y = getOrigin().y+xx*dydx;
uint16_t x = getOrigin().x+xx;
square(x,y);
}
}
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;
square(x,y);
}
resetDirty();
}
}

View File

@@ -9,29 +9,38 @@ int main(){
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
bool s=false;
uint i(0);
uint i(2);
Render::dim_t ssize;
ssize.x = EPD_2IN9_V2_WIDTH;
ssize.y = EPD_2IN9_V2_HEIGHT;
auto viewer = Render::Mare(ssize);
Render::dim_t ps; ps.x=8; ps.y=8;
Render::dim_t ps; ps.x=0; ps.y=0;
Render::dim_t cx; cx.x=ssize.x/2; cx.y=ssize.y/2;
auto line = viewer.addDrawable<Render::DrawableLine>();
line->setThickness(4);
line->setOrigin(ps);
//auto line = viewer.addDrawable<Render::DrawableLine>();
//auto line2 = viewer.addDrawable<Render::DrawableLine>();
auto line3 = viewer.addDrawable<Render::DrawableLine>();
//line->setOrigin(ps);
//line->setLength(256);
//line2->setLength(256);
line3->setLength(32);
line3->setOrigin(cx);
while (true){
line->setRotation(0);
for (auto d(8); d < 128; d+=8){
line->setLength(d);
line->setDirty();
viewer.render();
}
for (float a(0.0f); a<=M_PI_2; a+=0.1){
line->setRotation(a);
line->setDirty();
//ps.x = ssize.y-i;
//line2->setOrigin(ps);
//line->setThickness(i);
//line2->setThickness(i);
line3->setThickness(i++);
for (float a(0.0f); a<=M_TWOPI; a+=(M_TWOPI/180.0f)){
//line->setRotation(a);
//line2->setRotation(M_PI-a);
line3->setRotation(a);
//line->setDirty();
//line2->setDirty();
line3->setDirty();
viewer.render();
}
viewer.clearScreen();