PocketMatrix forums

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

EasyCE 1.6 Sample

This is probably a question that has already been answered but I didn't see it so here goes....

The 1.6 sample draws a diagonal line and particle effect. I modified the line command to say:

line( IFP( 10 ), IFP( 10 ), IFP( 230 ), IFP( 310 ), 0xFFFF );

but it doesn't draw to those coords, it stops around 240 vertical. I pasted in the old 1.5 line code and it draws correctly using the non-fixed point math.

So, my question is this something that has been/needs to be fixed or did I goober it?

Thanks in advance!
I'm not very familiar with EasyCE, but does the line function accept fixed point values? If not then the results would certainly not be what you desire.

Dan East
Thanks for a quick response. Let's see if a little more info helps...

Here's the FP macro definitions:

// Fixed point defines
#define FPP 10
#define FP_ONE (1<<FPP)
#define FPMUL(x,y) (((x)*(y))>>FPP)
#define FPDIV(x,y) (((x)<<FPP)/(y))
#define FP(x) ((int)((x)*FP_ONE+0.5f))
#define IFP(x) ((x)<<FPP)

The line prototype:
void line( int x1, int y1, int x2, int y2, PIXEL color );

And the call:
line( IFP( 10 ), IFP( 10 ), IFP( 230 ), IFP( 310 ), 0xFFFF );


The ramp/step of the line is correct. It acts like it is clipped at the 240 vertical point. I tried changing the FPP define to 0x10 since it is 32bit int types, no change.
I think I've got it now ... did some more research in the forum and found a post for the "new fast line" algorithm:
http://forums.pocketmatrix.com/viewtopic.php?t=1333

It is tailored for 320x240 and as the post says, "...As-is it works in 320x240 mode so you will have to make slight changes to make it work with 240x320/whatever you use mode. ..."

I suspect the code in EasyCE is using this without "adjustments". There is code in the line routine that is hard-coded for 240 and 320 -- probably will need to make those vars and flip them depending on the LANDSCAPE value. I suspect the line_x and line_a may have the same issue?
hmm, it's build on my line code, just check where x ends (240 or 320) in landscape/non-landscape mode. This will tell you if it's ok or not for your needs. If it's not you will just have to exchange the 240 and 320 values and it should work fine then.
Also check if the pixel is saved to correct position.
Okay, maybe I'm just really confused here. In the sample code you give, line ends up being called as follows:
line( 10240, 10240, 235520, 317440, 0xFFFF );

That is with FPP defined as 10, and not 0x10. Again, I am not familiar with EasyCE, but the line routine should be taking standard X, Y coordinates as plain old integers, and not fixed point. Are those coordinates above really what you want? Is your bitmap really 235520 pixels wide by 317440 pixels tall?

Dan East
EasyCE does use fixed-point for the line routine. Everything else uses plain integers, though.
Dan - Sorry for any confusion - obviously I did a poor job of explaining the problem.

To any that are interested - I made a couple of changes to the line routines (line, line_a, and line_x):

1. I added a couple of locals to reduce duplication of shift calls
2. Replaced the hard-coded 240's and 320's either with references to the locals or the globals that are defined when LANDSCAPE is resolved.

Testing so far shows this to work as expected. If anyone sees something wrong please let me know, thanks.


Code:
void line( int x1, int y1, int x2, int y2, PIXEL color )
{
int shiftedSCRWIDTH, shiftedSCRHEIGHT;
shiftedSCRWIDTH = SCRWIDTH << FPP;
shiftedSCRHEIGHT = SCRHEIGHT << FPP;

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 > shiftedSCRHEIGHT)
{
if (dy > 0)
{
int i = ((y2 - shiftedSCRHEIGHT) / dy) + 1;
x2 -= dx * i;
y2 -= dy * i;
len -= i;
}
else len = 0;
}
if (len > 0) if (x2 > shiftedSCRWIDTH)
{
if (dx > 0)
{
int i = ((x2 - shiftedSCRWIDTH) / dx) + 1;
x2 -= dx * i;
y2 -= dy * i;
len -= i;
}
else len = 0;
}
for ( int i = 0; i < len + 1; i++)
{
buffer[((y1 >> FPP) * SCRWIDTH) + (x1 >> FPP)] = color;
x1 += dx;
y1 += dy;
}
}
Hmmm, that post didn't go as expected. I've seen others that have the code block scrunched and scrollable -- how would I set that up so it doesn't take up so much space?
There is a maximum width a source block can achieve. At this time the height is not restricted, although that will probably change in the near future.

Dan East
I think there is an error in the in the function for the line. The limit checking is reversed so x can go to 320 and y to 240. Hope this helps.