Terrain minimum height
by Daniel Buckmaster · in Torque Game Engine · 12/21/2007 (12:19 pm) · 5 replies
I've set up a simple terrain to test my game on, with some hills and DIFs. Now what I want to do is make a little depression with some water. However, it seems like my terrain is siting right on its minimum height - nothing I do will let me excavate or adjust the terrain lower. I tried changing the minimum height in the terraform editor, but when I hit apply, my terrain got flattened. I guess I could just remake all the hills, but I really want to know a better way to fix this, if there is one. Thanks in advance...
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
www.garagegames.com/mg/forums/result.thread.php?qt=62237
12/21/2007 (12:43 pm)
Another similar thread:www.garagegames.com/mg/forums/result.thread.php?qt=62237
#3
12/21/2007 (12:59 pm)
Exporting the terrain as a heightmap seems interesting, but I can't find a way to do it. I think I might just have to flatten the terrain and start again, making it all higher. Matthew, that's an interesting idea, but not something I want to delve too deep into right now :P
#4
Assuming your min ht is zero and your max height is 1000 (for a total variation of 1000 meters), raising all the terrain by 10 meters is something like:
mHeightMap[i]+(unsigned int)(10.0* (65535.0/1000.0))
This kind of change just adds 10 meters to all the terrain values as they are saved, giving you 10 more meters under the terrain to dig your river.
You could insert the code above one time, load, and then save the terrain, then remove the extra code.
Note: You would also want to make sure that none of the values went over 65535 after you added some to it (takes another couple of lines of code.)
12/21/2007 (1:18 pm)
TerrainFile::save is called normally to do the work when you save the terrain from the editor. The terrain is stored in the .ter file as a 256 by 256 grid of heights. All the stock TGE code in the previous post does is write out each height value to the file. (It does it one by one, 65536 times.)Assuming your min ht is zero and your max height is 1000 (for a total variation of 1000 meters), raising all the terrain by 10 meters is something like:
mHeightMap[i]+(unsigned int)(10.0* (65535.0/1000.0))
This kind of change just adds 10 meters to all the terrain values as they are saved, giving you 10 more meters under the terrain to dig your river.
You could insert the code above one time, load, and then save the terrain, then remove the extra code.
Note: You would also want to make sure that none of the values went over 65535 after you added some to it (takes another couple of lines of code.)
#5
12/23/2007 (12:38 am)
Whoah - it's that simple? I might do that after all :P. Thanks!
Torque 3D Owner Matthew Jessick
You could probably do it patching in right here:
bool TerrainFile::save(const char *filename) { FileStream writeFile; if (!ResourceManager->openFileForWrite(writeFile, filename)) return false; // write the VERSION and HeightField writeFile.write((U8)FILE_VERSION); for (S32 i=0; i < (TerrainBlock::BlockSize * TerrainBlock::BlockSize); i++) [b]writeFile.write(mHeightMap[i]);[/b]