Hi,
I am trying to anti-alias a bresenham line. I have this code so far. My only problem is that for the two variables that are declared as double, i have some problems. When i get to the code:
invD = 1.0 / (2.0 * Sqr(du * du + dv * dv))
invD2du = 2.0 * (du * invD)
It becomes
invD = 1# / (2# * Sqr(du * du + dv * dv))
invD2du = 2# * (du * invD)
There are # signs instead of decimals. Then i get overflow errors. Does anyone know how to fix this, or if there is a better way to anti alias the bresenham line? This would help me tremendously. Thankyou.
Code:dim uend As Integer Dim uincr As Integer Dim vincr As Integer Dim addr As Integer Dim incrS As Integer Dim incrD As Integer Dim twovdu As Integer Dim invD As Double Dim invD2du As Double Dim du As Integer Dim dv As Integer Dim u As Integer Dim v As Integer addr = (y0 * 640 + x0) * 4 dx = x1 - x0 dy = y1 - y0 If Abs(dx) > Abs(dy) Then du = Abs(dx) dv = Abs(dy) u = x1 v = y1 uincr = 4 vincr = 640 * 4 If dx < 0 Then uincr = -uincr End If If dy < 0 Then vincr = -vincr End If Else du = Abs(dy) dv = Abs(dx) u = y1 v = x1 uincr = 640 * 4 vincr = 4 If dy < 0 Then uincr = -uincr End If If dx < 0 Then vincr = -vincr End If End If uend = u + 2 * du d = (2 * dv) - du incrS = 2 * dv incrD = 2 * (dv - du) twovdu = 0 invD = 1.0 / (2.0 * Sqr(du * du + dv * dv)) invD2du = 2.0 * (du * invD) Do PSet (addr, twovdu * invD) PSet (addr + vincr, invD2du - twovdu * invD) PSet (addr - vincr, invD2du + twovdu * invD) If d < 0 Then twovdu = d + du d = d + incrS Else twovdu = d - du d = d + incrD v = v + 1 addr = addr + vincr End If u = u + 1 addr = addr + uincr Loop While (u < uend)




Reply With Quote