Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

would this work better than bresenham?

Name: Anonymous 2013-08-08 12:39

function drawline(x0,y0,x1,y1){
dx = x1-x0
dy = y1-y0
len = sqrt(dx*dx+dy*dy)
dx /= len
dy /= len
    for (k=0;k<=len;k++){
        paint(floor(x0),floor(y0))
        x0 += dx
        y0 += dy
    }
}

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-08-10 8:17

Can't beat this:

; void drawline(int x1:eax, int x2:ecx, int y1:edx, int colour:edi);
; void put_pixel(int x:esi, int y:eax, int colour:edi)/P(ecx,edx,ebx,esi,edi);
drawline:
 mov esi, eax   ; esi = x1
 sub ecx, eax   ; ecx = x2 - x1
 sub ebx, edx   ; ebx = y2 - y1
 push edx
 shl ebx, 16    ; ebx = (y2 - y1) <<16
 xchg eax, ebx  ; eax = (y2 - y1) <<16, ebx = x1
 cdq            ; edx:eax = (y2 - y1) <<16
 div ecx        ; eax = ((y2 - y1) <<16) / (x2 - x1) = m
 pop edx
 inc ecx        ; ecx = x2 - x1 + 1
 shl edx, 16    ; edx = f = y1 << 16
 xchg eax, ebx  ; ebx = m
; eax : g
; ecx : x2 - x1 + 1
; edx : f
; ebx : m
; esi : x
lineloop:
 mov eax, edx
 add eax, 32768
 call put_pixel
 inc esi
 add edx, ebx
 loop lineloop
 ret


Another thing I noticed when writing the above code is that his rounding is wrong: to get the standard half+up rounding, 32768, i.e. 1/2, needs to be added. Otherwise it's an off-by-1 rounding error.

>>14
Benchmark this... if you can.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List