Jump to content
Sign in to follow this  
Matthijs

Measuring altitude

Recommended Posts

Can anyone tell me if it's possible to get the altitude of an object relative to sea level? (in order to calculate altitude difference between objects)

The only method I could find was:

- take distance between objects:

valDISTANCE = THIS Distance THAT

- calculate the horizontal vector between objects:

valVECTORX = GetPos THAT select 0 - GetPos THIS select 0

valVECTORY = GetPos THAT select 1 - GetPos THIS select 1

- calculate vector length between objects using pythagoras:

valVECTOR = Sqrt ( valVECTORX^2 + valVECTORY^2 )

- calculate the altitude difference using pythagoras:

valRELATIVEALT = Sqrt ( valDISTANCE^2 - valVECTOR^2 )

Isn't there a simpler method?

Like: valDIFFERENCE = Altitude THAT - Altitude THIS

Note that GETPOS won't do, as it only gives altitude relative to ground level.

Share this post


Link to post
Share on other sites

solution (for 1.90+):

in init.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">sea_level = "emptyDetector" camCreate [0,0,0]

get_sea_level = loadFile "get_sea_level.sqf"<span id='postcolor'>

in get_sea_level.sqf:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_object","_height_asl"];

_object = _this select 0;

sea_level setPos (getPos _object);

_height_asl = sea_level distance _object;

_height_asl<span id='postcolor'>

example usage:

  if you wanted to find the height asl of a helicopter called chopper...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">chopper_height_asl = [chopper] call get_sea_level<span id='postcolor'>

solution (for < 1.90):

in init.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">sea_level = "emptyDetector" camCreate [0,0,0]

height_asl = 0<span id='postcolor'>

in get_sea_level.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_object = _this select 0

sea_level setPos (getPos _object)

height_asl = sea_level distance _object<span id='postcolor'>

example usage:

  if you wanted to find the height asl of a helicopter called chopper...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">[chopper] exec "get_sea_level.sqs"

chopper_height_asl = height_asl<span id='postcolor'>

Share this post


Link to post
Share on other sites

Would that also work for multiplayer?

I want to include the script in an object, but I can imagine that if I have several of these objects in the game, they will all use the same "sea level" object.

Share this post


Link to post
Share on other sites

Um, I don't know if it would work in multiplayer or not...

It should work if you change the camCreate to createVehicle...and put public sea_level below the createVehicle command...

And yeah, they'll all use sea_level...If you're gonna be using it a lot you can change it to a private variable for each, to prevent weird things happening smile.gif

Share this post


Link to post
Share on other sites
Guest BratZ

It wont work like that. Anywheres on the map 0 is depending on the terrain height.

Even if you moved the object wanting the height check to over and above your sea level marker ,it will still be the same height off the land it was in the other position.

Anywheres in the water 0 is same tho

Appears math is needed

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (BratZ @ Feb. 15 2003,11:11)</td></tr><tr><td id="QUOTE">It wont work like that. Anywheres on the map 0 is depending on the terrain height.

Even if you moved the object wanting the height check to over and  above your sea level marker ,it will still be the same height off the land it was in the other position.

Anywheres in the water 0 is same tho

Appears math is needed<span id='postcolor'>

Math is most definitely not needed.

Ok, I'll use the version I would use (I have 1.91) to explain this clearly...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">solution (for 1.90+):

in init.sqs:

Setup that only needs to happen once...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">;create a trigger (an object with 0 asl as it's height always...

sea_level = "emptyDetector" camCreate [0,0,0]

;load the function file into memory as a string to optimize code...

get_sea_level = loadFile "get_sea_level.sqf" <span id='postcolor'>

in get_sea_level.sqf:

called whenever someone wants to get the height asl of an object...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">commant "declare a couple of variables a private in scope..."

private ["_object","_height_asl"];

comment "set _object to the object to get the height asl of..."

_object = _this select 0;

comment "set the trigger to the position of the object (and since it's height is always 0 asl, you can use the fast way (setpos getpos)"

sea_level setPos (getPos _object);

comment "get the distance between the object and the trigger, which is the height asl of the object...and the distance function is very accurate, so no complaints there please..."

_height_asl = sea_level distance _object;

comment "return the height asl of the object"

_height_asl<span id='postcolor'>

example usage:

 if you wanted to find the height asl of a helicopter called chopper...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">chopper_height_asl = [chopper] call get_sea_level

hint format ["%1",chopper_height_asl]<span id='postcolor'><span id='postcolor'>

EDIT: OK, I re-read your post, and I now understand where you have gone wrong...the object I am camCreating here is a trigger not a marker...meaning that it always has a height of 0 asl...

Share this post


Link to post
Share on other sites
Guest BratZ

LOL silly,try it and you will see what I mean, I don't care if you are using a trigger or marker

Have you tried it?

Show me a working sea level script

Share this post


Link to post
Share on other sites
Guest BratZ

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Liquid_Silence @ Feb. 08 2003,06:55)</td></tr><tr><td id="QUOTE">solution (for 1.90+):

in init.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">sea_level = "emptyDetector" camCreate [0,0,0]

get_sea_level = loadFile "get_sea_level.sqf"<span id='postcolor'>

in get_sea_level.sqf:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_object","_height_asl"];

_object = _this select 0;

sea_level setPos (getPos _object);

_height_asl = sea_level distance _object;

_height_asl<span id='postcolor'>

example usage:

  if you wanted to find the height asl of a helicopter called chopper...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">chopper_height_asl = [chopper] call get_sea_level<span id='postcolor'>

solution (for < 1.90):

in init.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">sea_level = "emptyDetector" camCreate [0,0,0]

height_asl = 0<span id='postcolor'>

in get_sea_level.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_object = _this select 0

sea_level setPos (getPos _object)

height_asl = sea_level distance _object<span id='postcolor'>

example usage:

  if you wanted to find the height asl of a helicopter called chopper...

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">[chopper] exec "get_sea_level.sqs"

chopper_height_asl = height_asl<span id='postcolor'><span id='postcolor'>

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">

in init.sqs:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">sea_level = "emptyDetector" camCreate [0,0,0]

get_sea_level = loadFile "get_sea_level.sqf"<span id='postcolor'>

in get_sea_level.sqf:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_object","_height_asl"];

_object = _this select 0;

sea_level setPos (getPos _object);

_height_asl = sea_level distance _object;

_height_asl<span id='postcolor'>

<span id='postcolor'>

Think about what you are saying here,if an object is 200 meters above the ground at another part of island...moving a marker that that is 0,0,0 below it will still say 200meters

confused.gif??

When you move the sea level marker,its not going to drop so you can measure the difference.A marker at 0 at sea,will still be a marker at 0 at the highest top of a mountain.!

Please see this post then you will see:

http://www.flashpoint1985.com/cgi-bin....t=24373

edit:

Apparantly the ASL using a trigger does work differently,possible that it is accurate enough.

Just the angle,get height problem now and could experince times of item shifting because of height differences

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (BratZ @ Feb. 15 2003,19:45)</td></tr><tr><td id="QUOTE">(...)

Have you tried it?

Show me a working sea level script<span id='postcolor'>

Hey BratZ,

I did check Liquid_Silence's sea-level script, and I can tell you it works like a charm for my purpose.

And to LS: thanks again! This may mean.... well... that's my little secret!

biggrin.gif

Share this post


Link to post
Share on other sites
Guest jacobaby

theres a snippet section at ofpec re this.

I also made a way to discover EXACT sea level at any one time. But it was quite CPU intensive and I didnt bother pursuing it.

You can see a demo of that in action in the thread about DKM's rotorwash, theres a link to an mpg which I think is still available.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×