Page 1 of 1

[? ]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 21:10
by Chase Armitage
Hi!

My question isn't really aiming at modding or creating maps in general.
I simply need to know if there is an (easy) way of calculating the absolute height of a specific pixel in a given heightmap. Since you guys are the experts when it comes to things like heightmaps I thought this is a good place to turn to.
Something along the lines of there are that many gray values and they resolve to this height basing on this interpolation would already be most helpful.
I hope that makes any sense and if not I would be happy to further clarify.

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 21:34
by Z-trooper
I know very little of how it works in bf2, but you could do some experiments to determine it for yourself:

Find a pixel on the height map with value 255, find its corresponding location and height value.

Do the same for a pixel with value 0.

Then you got your scaling and offset (0 being the offset - but probably also 0).

Scaling can probably vary from map size to map size. This is only theory though, as I did not play much with the level editor during my time.

might be easiest to make the height map yourself so it is very easy to do this.

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 21:36
by Chase Armitage
That sounds like a reasonable idea. Actually I was already thinking in that direction. Though I am guessing there is a specific scale for each map. Probably a simple multiplication of the pixel value with the scale.
Thanks for the input. Going to check it out right away!

About making the heightmaps I really do need to parse all pixels in all existing height maps so making them myself probably wont help. Or did you mean something else ?

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 21:41
by pfhatoa
I might be far out as my knowledge is very limited so please get a second opinion. Anyway:

Get the maximum possible colours being stored in the picture. For a grey scale 8-bit picture 256, for a 16-bit 65536 colours. (2^8 and 2^16) For this example 16 bits will be used.

Then get the maximum height decided in a config probably. For this example say 500 metres.

Then get the value of said pixel (here we get to programming I'm lost.) Say the value is 43854.

500/(2^16)=0.00762939453125 this value is the increase in height in metres per change in the grey.

The height in said pixel is therefore: (43854)*0.00762939453125=334.5794677734375 (in metres)

But as I said, I might be totally wrong!

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 21:59
by Chase Armitage
No no this is exactly what I need.

The height maps I have are 8bit grayscales. On muttrah I found a scale of 0.78. But this is just an approximation given the way I worked. Checking that finding against lashkar valley seemed to yield roughly the right height values.
All I really need at this point is the said config file with the maximum height of a given map. From there on calculating the scale is a cakewalk.
Any idea where to find that?

Also do you make anything out of this:

Code: Select all

heightmapcluster.create HeighmapCluster
heightmapcluster.setClusterSize 3
heightmapcluster.setHeightmapSize 2048

rem --- primary ---
heightmapcluster.addHeightmap Heightmap 0 0
heightmap.setSize 1025 1025
heightmap.setScale 2/0.00305176/2
heightmap.setBitResolution 16
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapPrimary.raw
heightmap.setMaterialScale 1
heightmap.loadMaterialData Levels/muttrah_city_2/HeightmapPrimary.mat

rem --- secondary ---
heightmapcluster.addHeightmap Heightmap -1 -1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_L1U1.raw
heightmapcluster.addHeightmap Heightmap 0 -1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_U1.raw
heightmapcluster.addHeightmap Heightmap 1 -1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_R1U1.raw

heightmapcluster.addHeightmap Heightmap -1 0
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_L1.raw
heightmapcluster.addHeightmap Heightmap 1 0
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_R1.raw

heightmapcluster.addHeightmap Heightmap -1 1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_L1D1.raw
heightmapcluster.addHeightmap Heightmap 0 1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 1
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_D1.raw
heightmapcluster.addHeightmap Heightmap 1 1
heightmap.setSize 257 257
heightmap.setScale 8/0.78125/8
heightmap.setBitResolution 8
heightmap.setModified 0
heightmap.loadHeightData Levels/muttrah_city_2/HeightmapSecondary_R1D1.raw

heightmapcluster.setSeaWaterLevel 26.8
I think thats the jackpot!
If you take a look at this

Code: Select all

heightmap.setScale 8/0.78125/8
you might notice the proximity to my measured scale value.
Now the config file on lashkar says 0.64 as for the scale. Applying that yields exactly the height expected for
a given point. I guess I can start with the coding.
If anyone else has something to say on behalf of this I would certainly appreciate it!
Also my thanks to the two fellows above for their contribution.

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 22:08
by pfhatoa
First thing: I think BF2 uses 16-bit .raw for Heightmaps, not 8-bit.

Second thing, I have no idea where maximum height is stored. It is possible to find (and change) this value if you load the map in the editor and check in the tweak window under level settings.

Ah, edit ninjad!

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-13 22:15
by Chase Armitage
Hehe sorry editing is a bad habit of mine... ;)

But you are right BF2 seems to use 16bit heightmaps. Though the maps I currently use are 8bit. So for now I am going to work with them. For one I dont need overly accurate heights and should the need for 16bit arise that wouldn't take to much of changing the code. Just a different interpolation.

Re: [QUESTION]Calculating the absolute height of specific pixels from heightmaps

Posted: 2011-02-14 14:54
by Tomking
Once the heightmap is enabled on a map the maximum height of the map can be manually entered in the tweak level tab. As expected, adjusting this number will then effect the grayscale values according.