PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

problems with line function in EasyCE

I've been playing around with a new game dev, and I've been trying to use the line function in EasyCE, but no matter what I do I cant get it to draw anything.

i.e line(x1,y1,x2,y2,PIXEL color, buffer)

source for line function:

Code:

void line( int x1, int y1, int x2, int y2, PIXEL color, PIXEL* buff)
{
if (y1>y2)
{
int h=y1;
y1=y2, y2=h;
h=x1, x1=x2, x2=h;
}
int dx, dy, len = abs( x2-x1 );
if (abs( y2 - y1 ) > len) len = abs( y2 - y1 );
len = len >> FPP;
if (len != 0)
{
dx = (x2 - x1) / len;
dy = (y2 - y1) / len;
}
if (y1 < 0)
{
if (dy > 0)
{
int i = -(y1 / dy) + 1;
x1 += dx * i;
y1 += dy * i;
len -= i;
}
else len = 0;
}
if (len > 0) if (x1 < 0)
{
if (dx > 0)
{
int i = -(x1 / dx) + 1;
x1 += dx * i;
y1 += dy * i;
len -= i;
}
else len = 0;
}
if (len > 0) if (y2 > (240 << FPP))
{
if (dy > 0)
{
int i = ((y2 - (240 << FPP)) / dy) + 1;
x2 -= dx * i;
y2 -= dy * i;
len -= i;
}
else len = 0;
}
if (len > 0) if (x2 > (320 << FPP))
{
if (dx > 0)
{
int i = ((x2 - (320 << FPP)) / dx) + 1;
x2 -= dx * i;
y2 -= dy * i;
len -= i;
}
else len = 0;
}
for ( int i = 0; i < len + 1; i++)
{
buff[((y1 >> FPP) * 240) + (x1 >> FPP)] = color;
x1 += dx;
y1 += dy;
}
}


am I missing somthing here?, is there a bug in jakkos code? any ideas?
len = len >> FPP;


You are passing it fixed-point coordinates, right?
Yep, I think!.... There just ints...
brendan:
if you have x value like 5 (which means fifth pixel:)
you pass x to function or rather x<<FPP?

Take notice that this function uses fixedpoint math for better precision (it gives you smoother line animation, but you have to send fixedpoint coords to it)
Brendan:

call the function like this and see if it works:

Code:
line( x1<<FPP, y1<<FPP, x2<<FPP, y2<<FPP, color, buffer)
I think I remember posting about this a few months back.... DOH.... I will try....

-Brendan
I think theres still a bug?

using the same function as listed above, the following code will only draw a line for about 0,0 to 200,240 (ish), the rest is just not there?

Code:

line(IFP(0),IFP(0),IFP(239),IFP(319),BLUE,screen_buffer_p);


any ideas why.... I thought my code was stuffed at first until I tryed fixed numbers, it seems that it wont draw any line information below raster 240 ish
is there a 240 in the code that should be a 320?

any Ideas?
Yeah, there's a bug in that code. Where the code tests if x2 is greater than 320, should be greater than 240. Similarly, where it tests y2 is greater than 240, it should be 320. You'll also need to change the 320 and 240 values in the associated calculations for i.
hehe, yeah:)
I have just written pretty much the same in the other forum... brendan pls don't double-post your questions.
Sorry for the doublle post, I only posted it in here because someone suggested trying in the overloaded section after me posting in the general section!
I was that someone. Your post is better suited for this forum because it has to do with a bug in the Overloaded/EasyCE code.
Don't sweat it though, next time I'll take care of moving your thread or asking someone who can to do it.

Did the suggestions Mirek and I provided fix the line drawing problem?
Yep, all fixed, it was a bug (must have been a late night for jakko when he wrote it) lol

-B
brendan:nah, it's not Jacco's bug. At least not really:)
It's my code, I just had my screen rotated the other way and therefore when Jacco added it to EasyCE it didn't work:)
This problem was already described somewhere on this forum.
Lol, I see, that makes sence then.... it took me ages to determine that it wasent my code causing the programs.... lol... not to worry, it works fine now....