project reality header
Go Back   Project Reality Forums > PR:BF2 Mod Forums > PR:BF2 Community Modding
19 Feb 2018, 00:00:00 (PRT)
Register Forum RulesDeveloper Blogs Project Reality Members List Search Today's Posts Mark Forums Read
PR:BF2 Community Modding Making or wanting help making your own asset? Check in here

Reply
 
LinkBack Thread Tools Display Modes
Old 07-07-2012, 08:41 AM   #1
MeKillHatch

MeKillHatch's Avatar
Default Working with map heights.

Hello everyone.

I am creating a heightmap analysis tool as a hobby programming project and I have hit a problem I can't immediately work out. I was hoping that someone in this forum could help me.

I have used the helicopters in PR to figure out the altitude of certain points on a couple of PR maps, but I can't figure out how those heights translate to those in the heightmap files (or rather from heightmap to in-game altitude).

I know how heightmaps are stored and know the idea of "white = highest, black = lowest on the map".

In the corresponding Heightdata.con file for the level there is a line:
Code:
heightmap.setScale 4/0.0025/4
And I was wondering if the 0.0025 value had to do with the computation of the actual in-game height?

It's hard to find detailed documentation on this I have found, so I could really use some help here.

- Thanks in advance.
KillHatch.
MeKillHatch is offline Reply With Quote
Old 07-07-2012, 12:00 PM   #2
Amok@ndy
Retired PR Developer
Supporting Member

Amok@ndy's Avatar
Send a message via Skype™ to Amok@ndy
Default Re: Working with map heights.

0.0025 is the height scale yes, though i dont belive anyone has get behind the doors of the secret how its calculated, only thing you can do is have a look into the editor where you type in a special height value and that gets calculated to the scale


Amok@ndy is offline Reply With Quote
Old 07-07-2012, 01:21 PM   #3
WeeD-KilleR
Supporting Member
Default Re: Working with map heights.

I remember that a german PR player made a mortar calc tool which used the heightmap to get the height values of the map. You may want to look how he has done it.

http://www.realitymod.com/forum/f138...alculator.html
WeeD-KilleR is offline Reply With Quote
Old 07-07-2012, 03:04 PM   #4
MeKillHatch

MeKillHatch's Avatar
Default Re: Working with map heights.

Quote:
Originally Posted by WeeD-KilleR View Post
I remember that a german PR player made a mortar calc tool which used the heightmap to get the height values of the map. You may want to look how he has done it.

http://www.realitymod.com/forum/f138...alculator.html
I have tried PM'ing the creator. I doubt he will respond any time soon, so I am still looking for the solution!
MeKillHatch is offline Reply With Quote
Old 07-07-2012, 03:19 PM   #5
WeeD-KilleR
Supporting Member
Default Re: Working with map heights.

Well, let me take a look into the files. I guess it should be possible to find the code he used.

Found it, here we go:

Quote:
//get height
v1 = getPixel(x1,y1) * heightscale;
v2 = getPixel(x2,y2) * heightscale;
heightdif = v2 - v1;
That's how he calculates the height. the heightscale is set for each map like this:
Quote:
if (gettitle == "2km_2albasrah") { heightscale = 0.0025; }
if (gettitle == "1km_1asad_khal") { heightscale = 0.0025; }
if (gettitle == "4km_burning_sands") { heightscale = 0.000915527; }
[...]

He uses the heightmap all the time to calulate the rounds for the mortar. If I understood it right he uses the build-in function getPixel() to get the value of the postition and multiplies it with the heightscale.


I hope it helped you.

EDIT2:

Another edit, getPixel(x1,y1) returns a 4-5 ditgit number, multiplied by the scale it returns reasonable values.
WeeD-KilleR is offline
Last edited by WeeD-KilleR; 07-07-2012 at 04:18 PM..
Reply With Quote
Old 07-07-2012, 04:59 PM   #6
MeKillHatch

MeKillHatch's Avatar
Lightbulb Re: Working with map heights.

Quote:
Originally Posted by WeeD-KilleR View Post
Well, let me take a look into the files. I guess it should be possible to find the code he used.

Found it, here we go:



That's how he calculates the height. the heightscale is set for each map like this:



He uses the heightmap all the time to calulate the rounds for the mortar. If I understood it right he uses the build-in function getPixel() to get the value of the postition and multiplies it with the heightscale.


I hope it helped you.

EDIT2:

Another edit, getPixel(x1,y1) returns a 4-5 ditgit number, multiplied by the scale it returns reasonable values.
It did but in an indirect way, I did have a look at his code and I went back to my own code. I think my troubles stem from the conversion I do between the .raw format and the displayable image I create. The code snippet I am using at the moment seems (if I understand it correctly) to only take every odd 8 bits and use those, which is why I get so very small numbers when I multiply with the height scale, which is a very small number.

I will update the thread if I make progress tomorrow. As for now, thank you for your help! It made me go back and check my code.

Feel free to contribute further (everyone). Information is still appreciated!
MeKillHatch is offline Reply With Quote
Old 07-07-2012, 05:19 PM   #7
Amok@ndy
Retired PR Developer
Supporting Member

Amok@ndy's Avatar
Send a message via Skype™ to Amok@ndy
Default Re: Working with map heights.

mortar app is using .png or .tiff files not .raw if i remember right


Amok@ndy is offline Reply With Quote
Old 07-08-2012, 08:47 AM   #8
MeKillHatch

MeKillHatch's Avatar
Default Re: Working with map heights.

Quote:
Originally Posted by [R-DEV]Amok@ndy View Post
mortar app is using .png or .tiff files not .raw if i remember right
True, but I don't want to make .png or .tiff files for each map / whenever update changes are made. I want my program to work with any map
MeKillHatch is offline Reply With Quote
Old 07-08-2012, 01:27 PM   #9
Hjid
Default Re: Working with map heights.

Wookie sniper mod uses python to read heightmaps to prevent people from spawning in slopes. You might find something interesting there.

WOoKie Sniper Mod for Battlefield 2 - Mod DB

http://www.realitymod.com/forum/uploads/signatures/sigpic33103_1.gif
Hjid is offline Reply With Quote
Old 07-08-2012, 03:09 PM   #10
[R-DEV]Rhino
PR:BF2 Developer
Supporting Member

[R-DEV]Rhino's Avatar
Default Re: Working with map heights.

Its really pretty simple when you break the system down to its basics.

How a heightmap works is that 100% black, aka, 0% white = 0m height on every single map in BF2. However ingame the altitude is done off the "sea" water level (aka, terrain water level), which might actually be set to something like 15m high above the heightmaps bottom point, as otherwise you wouldn't have any sea bed. This also note is the reason why on the Falklands why when you jump in a jet, it says your altitude is 10,000m when your actually at sea level, which is because the Falklands can't use the normal terrain water most maps have, so instead its terrain water is 10km underground, with a waterplane being the water you see and also why it doesn't look like water for low gfx users.
100% white on the heightmap = the maps coded max terrain height. I can't remember what the default value in meters is, that most maps uses but to find out that you need to open a map up with the BF2 editor and then look in the map's level settings to what it is then you can translate that to the y scale in what you have quoted above.

One thing to keep in mind however is that many maps do not actually use the heightmap to its full potential. While most maps do go down to 100% black, other than really deserts without any water, most maps do not go up to 100% white, with there highest peak being something around 95% white, or some not going anything much above 60% white (which isn't very good mapping btw in that case as your not using the heightmap to its full potential of accuracy and decreasing terrain warping by as much as possible).

So the only thing you really need to find is what the altitude is on each map, with the default being iirc something around 164.something meters high but to find out the real value, the only way is the editor.

Once you've found it, its a simple process of working out the height by simply finding out what % of white that part of the heightmap is, then applying that % to the max height value. So for example if a map has a 250m max height setting, and the point on the heightmap you want to know the height to is 72% white, then its simply 72% of 250m which is 180m. Another point on the heightmap of the same example map might be 19% white, which in that case its height would be 47.5m high.

Hope that clears it up.


EDIT: quickly loaded up a map with the default height value in the editor since I had it running and the default value is 163.84m
And yes its heightmap scale is "heightmap.setScale 2/0.0025/2", so 0.0025 = 163.84m

[R-DEV]Rhino is offline
Last edited by [R-DEV]Rhino; 07-08-2012 at 04:31 PM..
Reply With Quote
Reply


Tags
heights, map, working
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:28 PM.


Powered by: vBulletin. ©vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.1
All Content Copyright ©2004 - 2015, Project Reality.