Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: Zooming in vehicles, planes and boats  (Read 11857 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Zooming in vehicles, planes and boats
« on: September 25, 2018, 04:14:44 pm »

I'd like to add  ability to zoom when inside a vehicle cockpit, as is possible in airplanes. Is it possible using the code of aiplane scripts ?
I tried as below but I get the following error:

TypeError: Object [object Object] has no method 'jsb' (ot::js::vehicle_physics.init_vehicle(): :

Am I doing wrong something or simple is it impossible now ?

Code: [Select]

var jsbsim,fov_cockpit_zoom,ot_world;
........

function init_vehicle(){
...
this.jsbsim = this.jsb();
ot_world = this.$query_interface("ot::js::world.get");
fov_cockpit_zoom = 81.8;
this.register_axis("air/sensor/fov_zoom", {minval:0, maxval:1, vel:1, center:0}, function(v){
    var dec2int = v*48;
    var integer = Math.floor(dec2int);
    var string = 81.8 - integer.toString();
    fov_cockpit_zoom = string;
  });

....
}


function update_frame(dt, engine, brake, steering)
{
...
  if (this.get_camera_mode() == 0){
  ot_world.set_camera_fov(fov_cockpit_zoom);
.......

 }






« Last Edit: November 08, 2019, 12:25:40 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Possible to use JSBSIM in vehicles ?
« Reply #1 on: September 26, 2018, 03:18:38 am »

Vehicles do not have jsbsim, but you do not need it for zooming. The zoom control handler just modifies fov_cockpit_zoom variable, which is then used in update_frame:

Code: [Select]
  this.set_fps_camera_fov(fov_cockpit_zoom);
Also you can remove ot_world, dunno why it goes through it when it can just set the fov directly on vehicle, does not even need to check camera mode (applies only in FPS).
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Possible to use JSBSIM in vehicles ?
« Reply #2 on: September 26, 2018, 12:29:01 pm »

Thanks. Got it working like that:
 
Code: [Select]

var fov_cockpit_zoom;
....
function init_chassis()
{
 fov_cockpit_zoom = 81.8;
    this.register_axis("air/sensor/fov_zoom", {minval:0,    maxval:1, vel:1, center:0}, function(v){
       var dec2int = v*48;
       var integer = Math.floor(dec2int);
       var string = 81.8 - integer.toString();
       fov_cockpit_zoom = string;
     });
...
}

function update_frame(dt, engine, brake, steering)
{
  this.set_fps_camera_fov(fov_cockpit_zoom);
....
}



How can I increase the max zoom level correctly ? what are the numbers 81.8 and 48 ?  Do I need to change these also or just set maxval:1   to  say maxval:5   ?
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Possible to use JSBSIM in vehicles ?
« Reply #3 on: September 26, 2018, 01:41:25 pm »

Action values have some limited range beyond 1, but it's best to use them in normalized range 0..1 or -1..1, and compute the desired values from that.

The FOV value is field-of-view in degrees. Zoom is related to the original FOV you are using, see for example https://gamedev.stackexchange.com/questions/141700/how-to-convert-fov-into-zoom-2x-3x-4x
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Possible to use JSBSIM in vehicles ?
« Reply #4 on: November 07, 2019, 10:44:25 am »

Hi cameni !

I would like to add zoom to vehicles and boats. But if I just copy the code from the cessna 172  putting  this.register_axis("air/sensor/fov_zoom", {minval:0, maxval:1, vel:1, center:0}, function(v) ....
into init_chassis where it belongs I well can get the zoom to work but when exiting the vehicle or boat the zoom remains as last set..which is very annoying... whereas for the cessna it resets automatically to the default zoom. Seems that exiting a plane behaves differently from exiting a vehicle/boat ..from the camera view perspective.
I tried to solve this issue using the code below and it works for a single vehicle/boat but when I spawn a second one I get a black screen. Also I need to set the default FOV manually in the script .copying the FOV value of the menu into the script. Is it possible to get it via the world interface ?  OR is there a completely different way to set FOV to get the default FOV back when exiting a vehicle/boat ?

Code: [Select]
function init_chassis(){

 ...
  this.fov=83;// as set in the outerr amenu


      this.fov_cockpit_zoom = this.fov;
       this.register_axis("air/sensor/fov_zoom", {minval:0,    maxval:1, vel:1, center:0}, function(v){
       var dec2int = v*80;
       var integer = Math.floor(dec2int);
       var string = this.fov - integer.toString();
       this.fov_cockpit_zoom = string;
     });

}




function update_frame(dt, engine, brake, steering, parking){
..
 
  if (this.get_camera_mode() == 256){             // if not inside the vehicle
    this.fov_cockpit_zoom=this.fov;
  }
 
  this.set_fps_camera_fov(this.fov_cockpit_zoom);
 ..

}
« Last Edit: November 07, 2019, 12:20:43 pm by fly77 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Possible to use JSBSIM in vehicles ?
« Reply #5 on: November 08, 2019, 04:58:07 am »

init_chassis is called only on the first instance, that means there's no this.fov on other instances. You should make it a global variable. Basically, anything that doesn't vary per instance should be set as a global variable or constant.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Possible to use JSBSIM in vehicles ?
« Reply #6 on: November 08, 2019, 12:25:02 pm »

Thank you cameni ! It works using const fov_cockpit_zoom =default value.    :)  ( still don't know how to use global variables :'(
« Last Edit: November 08, 2019, 05:14:45 pm by fly77 »
Logged