Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

problems with line function in EasyCE


problems with line function in EasyCE

Postby brendan » Oct 28, 2002 @ 6:48am

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: Select all









10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
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;
    }
}
67 lines; 31 keywds; 25 nums; 249 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


am I missing somthing here?, is there a bug in jakkos code? any ideas?
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby refractor » Oct 28, 2002 @ 8:43am

len = len >> FPP;


You are passing it fixed-point coordinates, right?
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby brendan » Oct 28, 2002 @ 9:43am

Yep, I think!.... There just ints...
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby MirekCz » Oct 28, 2002 @ 10:01am

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)
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Postby refractor » Oct 28, 2002 @ 11:35am

Brendan:

call the function like this and see if it works:

Code: Select all

line( x1<<FPP, y1<<FPP, x2<<FPP, y2<<FPP, color, buffer)
1 lines; 0 keywds; 0 nums; 15 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby brendan » Oct 28, 2002 @ 12:39pm

I think I remember posting about this a few months back.... DOH.... I will try....

-Brendan
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby brendan » Nov 8, 2002 @ 4:37am

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: Select all

 line(IFP(0),IFP(0),IFP(239),IFP(319),BLUE,screen_buffer_p);
1 lines; 0 keywds; 4 nums; 16 ops; 0 strs; 0 coms    Syntactic Coloring v0.4 - Dan East  


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?
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Digby » Nov 8, 2002 @ 8:56am

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.
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby MirekCz » Nov 8, 2002 @ 12:13pm

hehe, yeah:)
I have just written pretty much the same in the other forum... brendan pls don't double-post your questions.
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Postby brendan » Nov 9, 2002 @ 1:01am

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!
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Digby » Nov 9, 2002 @ 3:18am

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?
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby brendan » Nov 11, 2002 @ 12:42am

Yep, all fixed, it was a bug (must have been a late night for jakko when he wrote it) lol

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby MirekCz » Nov 11, 2002 @ 1:47am

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.
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Postby brendan » Nov 11, 2002 @ 2:09am

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....
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Return to Phantom's Forum


Sort


Forum Description

Discuss any of Phantom's projects here (Operation Nutcracker, etc.)

Moderators:

sponge, RICoder, Phantom

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum