i know that Jim Adams has an article about this on the light befallen site.
fortunately, and unfortunately at the same time, i'm currently working on a program that demonstrates EXACTLY what you are asking about. (the unfortunate part is that i wont be done with it for a few days, or i could show you right now)
however, i will give a quick answer as to how you can solve your problem.
the issue here is in translation of screen coordinates(ScreenSpace) to world coordinates(TileSpace), and vice versa.
ScreenSpace is the viewable area of the screen. it is usually a rectangle.
so, for example, lets say you are doing a fullscreen application that runs in 640x480, but at the left hand side of the screen, you have a 64 pixel wide toolbar, at the top of the screen you have a 16 pixels menu bar, thus leaving you with the following rectangle:
const int TOOLBARWIDTH=64;
const int MENUHEIGHT=8;
const int SCREENWIDTH=640;
const int SCREENHEIGHT=480;
and now lets say you want to also put an 8x8 pixel border inside this area.
const int BORDERWIDTH=8;
cosnt int BORDERHEIGHT=8;
now i've got the bounds of my screenspace (please note that since i've used constants,i have no idea what the actual coordinates of the screenspace are, and nor do i care, and nor SHOULD i care).
next, i'm going to determine by PlotSpace.
PlotSpace is exactly the same size as ScreenSpace, but with left and top at (0,0)
converting between them is a simple matter
now, we are going to make plotspace talk to tilespace, through a tilespacewindow
to do this, we merely need to keep track of a single point, that is the corresponding point in tilespace to (0,0) in plotspace. this is an arbitrary point, and it is the key to scrolling your map. i.e. this is the value you change by whatever factor you like to scroll your map in any direction.
so, let us call this point ptTileSpaceWindow.
now, to calculate the position of the tilespace window:
now we have a method by which we can translate tilespace coordinates into plotspace coordinates
its important to note, at this point, that i'm breaking this down into more steps than it needs to be. you can translate from screen space to tilespace without utilizing plotspace, which is only included here for illustration purposed.
now, we want to determine if a given tile is within the viewable area. in order to do this, we need to know the world coordinates of the rectangle that will contain an individual tile.
the following code provides the equations for plotting staggered (offset) tilemaps as well as diagonal (diamond) tilemaps. most likely, your own equations will be similar to one of these.
next we find the bounding rectangle of the tile.
LeftPad, etc are padding values, and may well be 0 depending on whether or not images stick out of the tile.
now, we check to see if any of the tile bounding rect is within the tilespace window:
//the tile is viewable
if it is viewable, you can easily translate rcTile from tilespace to screenspace coordinates, also, you can use rcIntersect to clip the tile without too much trouble.
did i say this post would be short? i lied.
[This message has been edited by TANSTAAFL (edited August 30, 1999).]