gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Mapping cartesian coordinates to screen

#35071 - ymalik - Sun Jan 30, 2005 2:16 am

Hello,
I want to be able to display shapefiles on the GBA. A line in a shapefile may have coordinates like (-121.811, 37.073) to (-121.811, 37.075). In OpenGL I would define the viewport and draw the coordinates. How can I do this in the GBA? Or can someone direct me to a simple tutorial?

Thanks,
Yasir

#35075 - tepples - Sun Jan 30, 2005 2:44 am

First off, round the coordinates to the nearest integer and then use [url=http://en.wikipedia.org/wiki/Bresenham's_line_algorithm]Bresenham's algorithm[/url] to plot them on a mode 3 screen.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#35076 - ymalik - Sun Jan 30, 2005 3:56 am

I'm not sure how rounding points to the nearest integer would work. For example, the simplest shapefile contains an outline of a county. The county file I am looking at bounds from (-122.318, 36.820) to (-121.581, 37.286) and consists of 1208 vertices. When displayed on a shapefile viewer the image takes up the whole screen of course. I have points like (-121.841, 37.094), (-121.840, 37.094). I could round those points to the nearest integer and plot them, but I might look a lot of detail.

Thanks,
Yasir

#35078 - tepples - Sun Jan 30, 2005 4:19 am

ymalik wrote:
I'm not sure how rounding points to the nearest integer would work. [The lines are about a thousandth of a unit long]

First you multiply the points by the current zoom level and then you round them.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#35080 - ymalik - Sun Jan 30, 2005 4:23 am

What do you mean by the zoom level?

#35087 - sajiimori - Sun Jan 30, 2005 6:43 am

If you have a line that's 1/1000 of a unit long, how long do you want it to be in pixels? If you wanted it to be 10 pixels long, that means your units-per-pixel value is 1/10000.

#35286 - ymalik - Wed Feb 02, 2005 4:53 pm

Ok, here's what I came up:
(1) A file bounds from (-111.047, 40.995) to (-110.048, 41.580)
(2) Assume the (-111.047, 40.995) is origin, so (-111.013, 41.548) becomes (0.034, 0.55).
(3) Assume that 0.999 units (width of image) maps 1 to 1 to GBA screen width, so 0.004 units = 1px. Same translation for height regardless of height of real image.
(4) (0.034, 0.55) now becomes (8, 132) and then (8, 28) (flipped)
(5) To zoom in, make 0.004 units = 2px, etc.

Any optimizations I can make to this?

Thanks,
Yasir

#35297 - sajiimori - Wed Feb 02, 2005 7:24 pm

It seems like you've got the right idea. Optimization can wait until you have an implementation, and then only if it's not fast enough. For now, just be sure to use fixed-point math.

#35377 - ymalik - Thu Feb 03, 2005 8:31 pm

The update to the VRAM will be done during vblank. However, vblank only lasts for some 200,000 cycles. I'm going to be doing complex calculations during vblank, and suppose all of my updates take more time than vblank. Does this mean that my image will be only partially drawn?

#35379 - poslundc - Thu Feb 03, 2005 8:37 pm

Do your complex calculations while the screen is still drawing (in the VDraw period). Store them in an array, then when the VBlank period begins simply pull the information out of there instead of doing the calculations at the more critical point in time.

This is the general strategy GBA games use: take as much time as you need to figure out what the screen is going to look like during VDraw, then blast it all to the screen as quickly as you can during VBlank.

Dan.

#35599 - ymalik - Mon Feb 07, 2005 10:49 pm

How to games run at 30 frames/second if all the calculations are done during vdraw? Do developers stop vdraw?

#35601 - sajiimori - Mon Feb 07, 2005 11:44 pm

The hardware keeps rendering while you're calculating your next frame, even if that takes longer than 1/60s. As long as you don't modify VRAM (or related registers), the screen will stay the same the whole time.

#35602 - sasq - Tue Feb 08, 2005 12:13 am

Tell me _one_ game that redraws the screen every frame and uses single buffered mode 3 ?

Use Mode 4 (256 Colors) and double buffering; that is render to one screen while displaying the other and then switch during vblank.

#35606 - ymalik - Tue Feb 08, 2005 12:29 am

sasq wrote:
Tell me _one_ game that redraws the screen every frame and uses single buffered mode 3 ?


I am using mode 4. I don't know the internals of any game, but you can use mode 3 for double buffering as well--just draw the buffer in EWRAM and then use DMA to copy in the buffer on the next frame.

#35619 - sasq - Tue Feb 08, 2005 9:23 am

ymalik wrote:


I am using mode 4. I don't know the internals of any game, but you can use mode 3 for double buffering as well--just draw the buffer in EWRAM and then use DMA to copy in the buffer on the next frame.


You should have a very good reason for doing so though, as it is a big performance hit. EWRAM is slower to begin with, and I suspect most of the VBLANK is used for the DMA-copy.

#35621 - ymalik - Tue Feb 08, 2005 2:05 pm

sasq wrote:
You should have a very good reason for doing so though, as it is a big performance hit. EWRAM is slower to begin with, and I suspect most of the VBLANK is used for the DMA-copy.


Have more vibrant colors?

#35622 - tepples - Tue Feb 08, 2005 3:01 pm

sasq wrote:
You should have a very good reason for doing so though, as it is a big performance hit.

The GBA Video titles at least justify rendering each frame to VRAM in mode 3.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#35625 - Abscissa - Tue Feb 08, 2005 3:10 pm

sasq wrote:
ymalik wrote:


I am using mode 4. I don't know the internals of any game, but you can use mode 3 for double buffering as well--just draw the buffer in EWRAM and then use DMA to copy in the buffer on the next frame.


You should have a very good reason for doing so though, as it is a big performance hit. EWRAM is slower to begin with, and I suspect most of the VBLANK is used for the DMA-copy.

Plus that would eat up a sizable chunk of RAM that could probably be better used for other stuff (Unless your program is simple enough that it wouldn't need much RAM).

#35687 - sasq - Wed Feb 09, 2005 5:50 pm

ymalik wrote:

Have more vibrant colors?


But you wont. You will only get more available colors, so you only need to use it if you are sure you need more than 256. And besides, using a palette gives you the ability to do all sorts of tricks with the colors.