Jump to content
  • Advertisement

Archived

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

TimesOldRoman

Easy Terrain question!

This topic is 5564 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

This is an easy one, I''m sure...maybe you guys can help me. I''ve got my terrain represented as a linked list of triangles. I want to find out, using the coordinates of my moving object(car), which triangle it is inside of. So I want to traverse my list until I find the triangle that the car is in. Do any of you guys know an equation or expression to represent this relationship? How can I tell if the car''s (x,z) coordinates ly in the polygon''s area (triangle)? This way, I can figure out what the Y coordinate of my car should be, which I don''t have a problem doing. It''s just figuring out which polygon (triangle) is in the region of the car.

Share this post


Link to post
Share on other sites
Advertisement
hi,

Traversing the triangle list is a bad thing unless you''ve got a very low polygon representation of terrain. You need a more elegant solution.There are two methods that spring to mind that you can try depending on how your terrain geometry is organised.

1. If the terrain is generated from a heightmap, i.e. is based on a regular grid, with each grid the same dimensions then its simple to calculate the grid cell the car is in (or better still check the four corner points of the car to see what grid cells they are in). Simply map the x,z of the point to test into the terrain/heightmap space. You''ll need to keep track of which triangles in you''re linked list belong to which cell.

So now you know you are over 1 of 2 triangles (as a grid cell is square, and made of two traingles). Its possible to calculate which one it is directly or simply cast a ray down through both and see which one interests.

2. If you terrain is mesh based and does not conform to a regular grid, then you are going to need some simple space aprtitioning method first off, such as a quadtree.

Once built you can traverse the quad tree, checking if the point is within each quad and then proceeding through that quads children, etc.

Eventually you''ll get to a leaf, where you will proberbly have several triangles, then simply raycast through the point into these traingles to find an intersection.

Hope this helps

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!