I'm diving into 3d programming a bit and am currently learning by writing a procedural terrain gen开发者_开发百科erator that generates terrain based on a heightmap. I would also want to implement some physics and my first attempt at terrain collision was by simply checking the current position vs the heightmap. This however wont work well against small objects as you'd have to calculate the height by taking the heightdifference of the nearest vertices of the object and doing this every colision check is pretty slow.
Beleive me I tried googling for it but there's simply so much crap and millions of blogs posting ripped-of newbie tutorials everywhere with basically no real information on the subject, I can't find anything that explains it or even names any generally used techniques.
I'm not asking for code or a complete solution, but if anyone knows a particular technique good for calculating a high-res heightmap out of the already generated and smoothed terrain I would be very happy as I could look into it further when I know what I'm looking for.
Thanks
What if you made your terrain a group of quads based on those height positions combined with their x/y positions. Now, store the normals for those quads. Now, you are doing a simple, is this point on this side of the polygon check which is very quick to calculate - the sign of a dot product between the surface normal and the point you are checking against. It's like back face culling and most 3D systems will have routines to handle this for you.
I would strongly recommend that you first start within a 2d world heightmap, then once you grasp how the heightmap works then program it in a 3D world.
This tutorial best describes what I mean. http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_from_file.php
Look into Unity also: http://vimeo.com/73273585
精彩评论