Outerra forum

Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => Topic started by: fly77 on October 12, 2019, 03:48:58 pm

Title: Is it possible to detect if free camera is below lake waterlevel ?
Post by: fly77 on October 12, 2019, 03:48:58 pm
I have figured out that I can check in "free camera mode" (ufo mode) when camera is "underwater", "above land" or "above sea" by determining altitude above sealevel of the ECEF position of the camera and also altitude of terrain under the camera through raycasting. I'd like to do the same to check if I am "above lake"  or "under lake water level"...but don't know what to probe for. Is there a way to do raycasting to  intersect also lake surfaces ?


Code: [Select]
function init_vehicle(){
...
    $igc = this.$query_interface("ot::js::igc.get");
}

function update_frame(){

ecef_cam = $igc.pos();
   
   altsea_cam=Math.sqrt(ecef_cam.x*ecef_cam.x+ecef_cam.y*ecef_cam.y+ecef_cam.z*ecef_cam.z)-6378137;
   
   norm = gravity_normal(ecef_cam);
   ground_ecef = {x:ecef_cam.x-10000*norm.x,y:ecef_cam.y-10000*norm.y,z:ecef_cam.z-10000*norm.z};
   igc_ray = $igc.intersect( ecef_cam, ground_ecef );
   
   if ((igc_ray.$ret !=undefined) && (igc_ray.$ret !=null)){ 
     altground_cam =  igc_ray.$ret;     
   }else{
     altground_cam  = -10000;
   }


   if (altsea_cam+2 < 0 ){   
      underwater=true;
   }
   
   
   if (! underwater){
      if  ( altsea_cam+2 < altground_cam  - 10  )       {
        insea=true;
      }

}
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: cameni on October 14, 2019, 02:56:27 am
Not from IGC, which predates the lakes and doesn't have any above_water field in igc_data. In world there's elevation_above_terrain_layers returning signed elevations above hard ground, soft ground (mud, snow) and water.
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: fly77 on October 14, 2019, 04:21:56 am
Wow...thanks ! I 'll try to see if I can use it to add some sounds specific for lakes when roaming around near lakes
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: fly77 on October 21, 2019, 02:31:58 pm
I get wrong number of arguments error when I try   with
world.elevation_above_terrain_layers()  or  world.elevation_above_terrain_layers(ecef)
and when I try world.elevation_above_terrain_layers  I get
the string " function elevation_above_terrain_layers{ [native code] }"  but I still cannot understand how I should call the function
So I am just trying randomly ....

var elev = world.elevation_above_terrain_layers(ecef,world.water); 
var elev = world.elevation_above_terrain_layers(ecef,world); 
var elev = world.elevation_above_terrain_layers(ecef,true); 
var elev = world.elevation_above_terrain_layers(ecef,0); 
var elev = world.elevation_above_terrain_layers(ecef,10000);

seems to indicate that arguments need be two.

All gives me an object   but elev.water or   elev.whatever  is undefined   ... I guess I probably got at least one of the arguments wrong.

what should be the syntax ?  Is one of the arguments ecef ? ...and what is the second one?

Just to compare: In case of igc at least I am able to get out some numbers ....allthough also in this case I am still far from a positive result as numbers do not appear to make sense to me

var igc_data = $igc.info();   
var  altsea_cam = igc_data.alt_msl;                   
var altground_cam = igc_data.alt_grd;

I get values near zero ...like for instance  3.455.. e-39  for both igc_data.alt_msl and igc_data.alt_grd allthough location of camera is well above ground and well above sealevel
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: cameni on October 22, 2019, 02:57:23 am
Arguments are the ecef pos and max height below the distance to check.
The result is an object with .x, .y and .z properties (float3), with hard, soft and water surface distances.
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: cameni on October 22, 2019, 03:27:19 am
The second argument is used for optimization, if you do not really need to know how far the ground/water is, just if it's not to a certain distance from your position. Such limited raycast operation can be much faster.
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: fly77 on October 22, 2019, 12:55:05 pm
Thanks !  works   :) 
elev.y-elev.x seems to indicate how deep is  mud  ..or in case of snow ...snow coverage   nice ! 

how about the fact that with  igc.info().alt_msl  and igc.info().alt_grd i get those strange (very small) numbers wherever I move the ufo camera ?
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: cameni on October 22, 2019, 04:10:56 pm
That's because the body of that call is commented out for some reason and you are getting some uninitialized values :-[
Title: Re: Is it possible to detect if free camera is below lake waterlevel ?
Post by: fly77 on October 22, 2019, 04:50:44 pm
If I understand right that is something that doesn't depend on me doing something wrong.
Ok it was just a curiosity.