Line scrolling 'skipping' lines...

SGDK only sub forum

Moderator: Stef

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Line scrolling 'skipping' lines...

Post by POLYGAMe » Sat Jan 09, 2016 2:47 am

Hi there,

So I'm messing about trying to make a 2.5D racing game. I have got the road line scrolling working but there are a couple of issues. In the text code below I'm just offsetting the road by one pixel but it seems to only offset every other pixel and it looks to be shifting it more than one pixel. What am I doing wrong? It looks 'interlaced'.

Code: Select all

int main( )
{
        u16 iVertLine = 96;
        u16 iScrollAmount = 1;
        s16 iLinesToScroll = 124;
        
        VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
        VDP_drawImage(VDP_PLAN_A, &road, 0, 0);
        VDP_drawText("ROAD SCROLLING TEST", 8, 25);
        VDP_setHorizontalScrollLine(PLAN_A, iVertLine, iScrollAmount, iLinesToScroll, 0);
        
        return 0;
}
EDIT: It seems the line scrolling doesn't work for me at all. If I enter anything other than a 1 it goes haywire. Tile scrolling doesn't do anything at all but full screen (plane) scrolling works fine...

ANOTHER EDIT: I think pointers got me again, hence why full screen scrolling works :P

ANOTHER ANOTHER EDIT: Nope... thought I'd solved it but still doing it...
Attachments
ScrollingOffset.png
ScrollingOffset.png (7.47 KiB) Viewed 7487 times

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Sat Jan 09, 2016 4:49 am

UPDATE: I thought I'd worked out the pointer thing. I'm no longer getting casting warnings etc but it's still not working. I haven't really used pointers before, at least not for a long time but I think my code should be correct:

Code: Select all

int main( )
{
        u16 iVertLine = 96;
        s16 iScrollAmount = 1;
        u16 iLinesToScroll = 124;

        s16 *myPointer = NULL;
        myPointer = &iScrollAmount;

        VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
        VDP_drawImage(VDP_PLAN_A, &road, 0, 0);
        VDP_drawText("ROAD SCROLLING TEST", 8, 25);
        VDP_setHorizontalScrollLine(PLAN_A, iVertLine, myPointer, iLinesToScroll, FALSE);

        return 0;
}


Yet, you can see my results! Any help much appreciated. As I said, plane scrolling works fine, so not sure what's wrong!
Attachments
GarbledRoad.png
GarbledRoad.png (3.88 KiB) Viewed 7480 times

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Line scrolling 'skipping' lines...

Post by Stef » Sat Jan 09, 2016 1:18 pm

myPointer should be an array containing the scroll value for each line.
For instance you can do that :

Code: Select all

        u16 iVertLine = 96;
        u16 iLinesToScroll = 124;
        s16 scrollingValues[124];
        s16 *myPointer = NULL;
        s16 scroll;
        u16 i;

        scroll = 100;
        for(i = 0; i < 124; i++) scrollingValues[i] = scroll++;
        
        myPointer = scrollingValues;
        ....

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Sat Jan 09, 2016 6:38 pm

Ah!!! S16 array! Gotcha, thanks! I didn't even know you could do that with arrays and pointers. Very cool.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Sun Jan 10, 2016 12:47 am

Okay I got it working. Just looking into how to use 'floats' to make it smoother. Getting there!
Attachments
Road Test.png
Road Test.png (3.62 KiB) Viewed 7384 times

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Line scrolling 'skipping' lines...

Post by Stef » Sun Jan 10, 2016 12:27 pm

Well done :) Indeed that need some "smoothing". Use SGDK fix16 or fix32 type for that :
https://github.com/Stephane-D/SGDK/wiki/Tuto-Maths

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Sun Jan 10, 2016 6:32 pm

I tried that but the problem is the line scroll function only takes an S16 array not a fix16 array so I get the same results. I guess it's because it's impossible to scroll less than one pixel.

Will have a play with bit-shifting tonight but I think I have another idea that might work.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Mon Jan 11, 2016 9:31 am

Okay, bit-shifting didn't work. Gave the same results. The problem is I can't scroll less than a pixel so I need to approximate the curve without the exponential offset.

Any ideas on how to smoothen the road? Perhaps bezier curves? Really stuck on this! Haha.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Line scrolling 'skipping' lines...

Post by Stef » Mon Jan 11, 2016 9:52 am

You just need to compute your offset in fix16 type then convert it to s16 only at the end (when sending to HSCroll table).
The idea is to have 2 arrays, one in f16 to do the computations and one in s16 to set the horizontal scroll value.

Code: Select all

f16scroll[i] += FIX16(0.2);
s16scroll[i] = fix16ToInt(f16scroll[i]);
You can find the methods to transform s16 to fix16 and vice versa in the math tutorial i pointed above.

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Mon Jan 11, 2016 1:20 pm

I did exactly that yesterday. The problem is, offset still ends up as an int, so I get the same results. I'll try again in case I did it wrong though. Haha.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Line scrolling 'skipping' lines...

Post by Stef » Mon Jan 11, 2016 4:19 pm

Final offset are integer of course, scroll values are defined as integer in the VDP, i'm not sure about what you're trying to do..

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Mon Jan 11, 2016 6:34 pm

Okay, so I take each line's x position and shift the line above it plus an offset. Ints are too big as the road shoots off the screen. If I use float to int conversion as you posted above, it doesn't bend the road at all and if I use the same technique but also using the previous line's x for the offset point it does what's in the image below, which is the same as just adding 1 to each line - it's not an increasing bend, so floats don't seem to work at all - they're not adding anything to the offset. I need some way of 'drawing' the x positions into a bend smoothly.

Code: Select all

 
 ScrollValuesFloats[i] += FIX16(1.2);
 ScrollValues[i] = ScrollValues[i + 1] + fix16ToInt(ScrollValuesFloats[i]);
I tried smaller values for the FIX16 but it didn't bend the road at all.
Attachments
notbending.png
notbending.png (1.84 KiB) Viewed 7205 times

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Line scrolling 'skipping' lines...

Post by Stef » Mon Jan 11, 2016 6:57 pm

POLYGAMe wrote:

Code: Select all

 
 ScrollValuesFloats[i] += FIX16(1.2);
 ScrollValues[i] = ScrollValues[i + 1] + fix16ToInt(ScrollValuesFloats[i]);
I tried smaller values for the FIX16 but it didn't bend the road at all.
Why are you doing this ?

Code: Select all

ScrollValues[i] = ScrollValues[i + 1] + fix16ToInt(ScrollValuesFloats[i]);
Adding integer together won't solve your problem, if that is really what you want to do you need to do it on the fix16 table :

Code: Select all

ScrollValuesFloats[i] = ScrollValuesFloats[i + 1] + FIX16(1.2);
ScrollValues[i] = fix16ToInt(ScrollValuesFloats[i]);

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Mon Jan 11, 2016 8:34 pm

I'm so confused. Lol.

EDIT: Ah, wait, I see what you mean. Will try again when I get home. Stupid day job getting in the way of my hobby!

Thanks for all your help, too :)

POLYGAMe
Very interested
Posts: 151
Joined: Sun Apr 14, 2013 1:19 am
Location: Auckland, New Zealand
Contact:

Re: Line scrolling 'skipping' lines...

Post by POLYGAMe » Tue Jan 12, 2016 8:25 am

WOOHOO!!!! Thank you, Stef! You're a genius :D
Attachments
success.png
success.png (1.98 KiB) Viewed 7091 times

Post Reply