Trying To Understand How The Map Is Drawn In A Trailblazer Style Game

Discussion in 'Homebrew' started by scrapheap, Aug 16, 2007.

  1. scrapheap

    scrapheap Still Fresh

    Joined:
    Oct 31, 2006
    Messages:
    28
    Hi,
    I am currently working on a trailblazer clone for the GP2X but I can't get my head around how the map is drawn to the screen. It is my first steps into 3D and it should in theory be simple once I figure it out but I just can't seem to get it drawing correctly.

    Does anyone have any suggestions on how to go about doing this or how to calculate which map pixel I should be plotting based on the current screen pixel? I hope to put this into a lookup table and then I can simply loop through this lookup table and offset it by the current position on the map, which should speed things up.

    Regards,
    Scrapheap.
     
    Tags:
  2. Dzz

    Dzz stmia r0!, {r2-r9}

    Joined:
    Jan 30, 2006
    Messages:
    1,098
    Trailblazer had lots of different versions for different systems. Can you post a link to a screenshot of exactly what you're trying to accomplish? The approach will depend on the details of what view you're trying for.
     
    Last edited by a moderator: Dec 18, 2015
  3. scrapheap

    scrapheap Still Fresh

    Joined:
    Oct 31, 2006
    Messages:
    28
    Hi,
    An example of the sort of effect that I am trying to create is.
    [​IMG]

    I am using a tile map and it is easy enough to draw that to the screen in a 2D effect, but when I try to draw it with a 3D effect it draws it to the screen with lots of gaps.
     
    Last edited by a moderator: Dec 18, 2015
  4. P-J

    P-J Member

    Joined:
    Jul 24, 2007
    Messages:
    137
    Location:
    Warwickshire, England
    It's still hard to see what you're trying to accomplish.

    Is it TRUE 3D you're doing or are you doing 'fake perspective' like, say Pole Position and so on? If it's the latter, I seem to remember you would have a 'plan view' of the track on a different buffer and then blit each line to the screen, shrinking each line as you get further away to create the perspective effect.
     
  5. scrapheap

    scrapheap Still Fresh

    Joined:
    Oct 31, 2006
    Messages:
    28
    I am currently trying to do it as True 3D. So I am taking my 2D map as a plane and projecting it on to the screen.

    I have tried taking each point on the map and projecting that onto the screen and that works except that I get a lot gaps between the projected points. So I want to take each point on the screen and work out what point on the map should be plotted there. This is where I have the problem as I can't figure out how to calculate which point on the map should be plotted. I know that if i can precalculate it and store it in a lookup table I can use that with the current position on the map as an offset and just plot the points without much in the way of calculations at the rendering stage.
     
    Last edited by a moderator: Dec 18, 2015
  6. P-J

    P-J Member

    Joined:
    Jul 24, 2007
    Messages:
    137
    Location:
    Warwickshire, England
    QUOTE
    I am currently trying to do it as True 3D. So I am taking my 2D map as a plane and projecting it on to the screen.


    Having read your original post better I realise your question was not about drawing, but more about the actual basics of tiling and viewports. I'm not really qualified to answer this so I'll step aside =P
     
  7. Dzz

    Dzz stmia r0!, {r2-r9}

    Joined:
    Jan 30, 2006
    Messages:
    1,098
    There is no simple answer for this, but there are some approaches to try.

    In this type of view you can rely on fact that the tiles are parallel to the bottom of the screen, which means you don't have to do a completely general textured polygon rendering engine.

    For a given tile, the first thing to do is figure out the screen coordinates of the corners of the tile. This is normally done with a perspective projection transform (about which google knows all). Once you have the four corners you process it something like this:

    for each scan line
    compute which row in the tile bitmap to use for this scan line (the same tile row will be used for the entire scanline because of the horizontal alignment)
    Use the width of the screen line you're trying to draw to figure out how far to move horizontally through the tile bitmap after each pixel
    Loop through the pixels of the scan line, incrementing the source location by the amount computed above for each pixel

    A couple of notes: You'll want to use fixed-point fractional offsets for the increments. If the tile is very close you might end up with more than one screen pixel corresponding to one tile pixel, and if the tile is far away you will have many tile pixels per screen pixel.

    It would be best to not just sample the tile bitmap but filter it instead (use input from multiple tile pixels to decide what color the screen pixel should be). That is probably too computationally intensive for the gp2x.

    To help get around that, you can precompute several mipmaps of the tile and use the appropriate one.
     
  8. scrapheap

    scrapheap Still Fresh

    Joined:
    Oct 31, 2006
    Messages:
    28
    Thanks, I will try to get my head around that and see how I do.
     
  9. Dzz

    Dzz stmia r0!, {r2-r9}

    Joined:
    Jan 30, 2006
    Messages:
    1,098
    No problem, if you would like me to clarify something just ask.
     
    Last edited by a moderator: Dec 18, 2015
  10. Newsdee

    Newsdee Still Fresh

    Joined:
    Aug 13, 2007
    Messages:
    31
    I've done a game similar to Trailblazer in Flash using Mode7, Babeball. If it works in Flash, I reckon a mode7 type engine would do fine in the GP2X. After all it's just a form of raycasting.

    I would see two challenges though... one would be to figure out the 3D engine part of it, and the other would be to write the Matrix math that Flash has built-in. The "3D engine" bit is for sprites and objects in the game... even though the background is just 2D (notice that all Mode7 games are flat), if you want to show opponents/enemies/rocks you will need to figure out where to place them.
     

Share This Page

Loading...