Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Luhar II

Determining visibility of tiles on a tile map

This topic is 5838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First, I''m pretty new to 3D programming and I''m still learning the math involved. I''m using D3D8 to render a map of square tiles. I want to determine which tiles to render by projecting each corner of the viewport onto the ground plane and figuring out which tiles fall between these points. Would anybody care to help me figure out how to do this? All I really need is the coordinates where the projected rays intersect the ground plane (elevation = 0). Thanks, Luhar *********************** Unhand thy gigglestick!

Share this post


Link to post
Share on other sites
Advertisement
Could you be a little more specific ?? are you back-projectiong the tile on the near plane ? orthogonal view ? isometric view ?
i give you a quick hint , store your tile in a bsp tree and render the ones which coordinates lyes in the current view, avoid all sub-branches with a quick rectangulare bounding box rejection sub-routine, i hope it helps, sorry for my bad english

Share this post


Link to post
Share on other sites
v71,

Thank you for replying. My problem is how to determine the coordinates that lie in the current view. I could be wrong, but I''m not sure if BSPs and all the other techniques for culling or clipping non-visible objects are appropriate here. The elements I''m trying to render are simple, flat quads with an elevation of y=0. All I really need is to determine at which coordinates a ray, if cast from each corner of the view port, would intersect the ground plane. Once I have the coordinates, it should be easy to determine which tiles to render.

Thanks,

Share this post


Link to post
Share on other sites
v71,

Thank you for replying. My problem is how to determine the coordinates that lie in the current view. I could be wrong, but I''m not sure if BSPs and all the other techniques for culling or clipping non-visible objects are appropriate here. The elements I''m trying to render are simple, flat quads with an elevation of y=0. All I really need is to determine at which coordinates a ray, if cast from each corner of the view port, would intersect the ground plane. Once I have the coordinates, it should be easy to determine which tiles to render.

Thanks,


Luhar
***********************
Unhand thy gigglestick!

Share this post


Link to post
Share on other sites
I agree that a BSP tree is not the solution you''re looking for, at least for the map tiles. Don''t rule out a BSP tree for dynamic objects though. The KD variety of a BSP tree could work well. A quadtree would also work.

So anyway, how do you do it? I agree that casting corner rays could work well. So, let''s see if I can do this...

You know where the camera is. You know the field-of-view (FOV) angle on both the x and y axes (because the scren isn''t square, they will be slightly different. You can always just use the larger x-axis one for both though, and it''ll work fairly well). Knowing this, we can write parametric equations for rays passing through the corners fairly easily. Each ray can be expressed as a vector times a scalar, t. You can set the plane and ray expressions equal and solve for t, and then multiply the original vector times t to find the point of intersection. That''s the general gameplan. Now the only real problem is finding the vectors.

I did a little geometry on a piece of paper, and solved the following:

First, the x components of the vectors: On the left side of the screen, the x components are given by tan(yaw - FOVx/2). On the right side, they are tan(yaw + FOVx/2).

Now for the y components: On the top, the y components are tan(pitch + FOVy/2), and on the bottom, they''re tan(pitch - FOVy/2).

I solved both of this with the z component equal to 1.

All this assumes no camera roll. The points of intersection will form a trapezoid. You can use a simple scan-line algorithm to add the tiles within this trapezoid to a vertex buffer which you can then render.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!