Advertisement

2d visibility on a 3d game (well, kinda)

Started by August 07, 2000 12:21 PM
2 comments, last by AngryLlama 24 years, 5 months ago
I have run into a problem. My 3d game has a map that works like a big Grid. So basically you move around on a huge piece of graph paper if you goto http://www.radioactivesoft.com/screenshots.htm you can see how the map looks by looking at the map editor, and how it gets drawn to the Gl Scene. The problem i run into is this: the level is 60x60 Tiles.. and each tile is 10x10 Gl Units. The visibility is about 50 units deep... I couldn''t just go a loop thru all 3600 tiles!! that makes the FPS drop to about 6. If you goto http://www.radioactivesoft.com/vis.gif you can see an illustration on my problem, and what i need as a solution. Thank You with any help you can provide! ~Paul Giblock

I recently had an idea for a tile-based sorter, for a system just like this, but I haven''t put it in code yet.

You have a visibility depth of 5 tiles. So, divide your map into ''sections''. Each section is 5 by 5 tiles in size, the viewing depth.

Every frame, determine which section the camera is in. Now, send only that section and the 8 sections adjacent to it to the renderer. So, 225 processed tiles instead of 3600 should speed it up quite a bit.

Another optimization would be to track the approximate rotation of the camera, like "the nearest of the 8 compass points", and only process those tiles in the front 180 degrees.

Should work. Drop me a line at (zlaj@hotmail.com) if it works, please!


RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Advertisement
Ok, I can't really be bothered doing the math for you , but here's an idea...

The hypoteneuse of the viewing frustrum is ~= 60 units (6 tiles),
so if you stored your tiles in an array[60][60], loop through the tiles that could possibly be visible by:

for (int i = (PlayerTile - 6); i < (PlayerTile + 7); i++)
for (int j = (PlayerTile - 6); j < (PlayerTile + 7); j++)
{
//Calculate which these tiles are visible.
//If they are, draw them.
}

of course you'd need range checking so that you didn't check past the start or end of the array.

Inside the loop your check is a simple intersection test between the frustrum lines and the tile boundaries. (All tiles between intersected tiles are drawn too).

Alternatively, you could work out the angle from North (or whatever) to each of the corners of the tile (using your current position as a pivot point), if any of these angles are between the angles from north to the two corner points of your frustrum (again using your player pos as the pivot) then the tile is visible. (I must remember that one ).

Hope this helps, sorry if I'm way off the mark.

ps - can I have a beta

If this is confusing and ill describeed, I'll email you a drawing if you ask. Laters.

Edited by - poontardis on August 10, 2000 4:53:12 AM
thank you everyone...

And about that beta.... sure. When its ready tho. and the game will be freeware anyways.

-Paul

This topic is closed to new replies.

Advertisement