   Changing vertices and textures during run-time - XNA
  Hey guys,I recently took interest in the XNA framework, and to exercise what I've read, I decided to start building a simple 3D engine. Right now I have a terrain (textured) built using a heightmap, and a "flying" camera to look around with. What I want to do next is apply dynamic changes to terrain height, as well as paint new textures on it, but I couldn't find any tutorials, or even source code, and I'm pretty clueless as to where to even start changing code. Can any of you guys help out?Thanks in advance.PS. One thing I missed, I've got an idea of how to arbitrarily do those changes, what I'm looking for is how to do them in a controlled manner, i.e. with the mouse.   
  Please guys, even a two-line description of the theory involved would be much appreciated. ;  The answer would be specific to how you structure your data. With out knowing more, you're only going to get very generalized answers.ie, find out where the mouse is clicking, and then paint the texture to that area of your terrain.   ;  It is bit of a heavy topic that won't warrant a quick answer nor a quick snippet of code.I don't personally have much experience working with terrains, but you probably would want to look up Ray-Triangle intersection testing. Cast a ray where your mouse pointer is on the screen, find the triangle it intersects with, then find the vertices that are within its influence (which would probably have a gradual fall off, affecting vertices very close more than vertices further away up until some point). Then you transform said vertices (e.g. raise/lower) or add/remove/change texture coordinates (e.g. say you have several texture layers, painting texture 1 modifies the first set of UV coords, painting texture 2 the second, and so on). The specifics of doing this depends on how you organize your data.Since ray-triangle intersection tests can be expensive for large terrains (and in general), it would probably help to break up your terrain into a bunch of tiles each with a bounding volume (e.g. an axis-aligned box). Do a coarse ray-bounding volume tests to cull away terrain blocks that shouldn't be checked, then a finer ray-triangle test to find the affected triangles near your mouse cursor.   