Anteworld - Outerra Game > JavaScript development

Extended Controls

(1/3) > >>

Uriah:
I thought it might be helpful to do an overview of the new extended control system.

There is a readme document located in the build directory: Anteworld\defaults\iomap\readme.txt 

The config files located in your data directory iomap folder are the ones which are modified when you configure your controls using the UI, typically located in C:\Users\YourName\Outerra\iomap\

When you delete a config file from this folder, air.cfg for example, and run OT again it is replaced with the default config from Anteworld\defaults\iomap\readme.txt

When you open one of the config files, you'll see the following structure:


--- Code: ---"name": "controls",
            "actions": [
                {
                    "name": "elevator",
                    "comment": "Elevator up/center/down",
                    "bindings": [
                        {
                            "event_name": "W",
                            "mode": "-"
                        },
                        {
                            "event_name": "S",
                            "mode": "+"
                        },
                        {
                            "event_name": "Axis0",
                            "mode": "+"
                        }
                    ]
                },
--- End code ---

In this case "controls" is the action group, under which a number of controls are located, including "elevator", etc, which may have a number of different key bindings. Many of these controls use default handlers for aircraft, which means you do not need to implement them in JavaScript to set a JSBSim property. You'll notice the mode for each binding is either "-" or "+", there are a number of other modes you can learn more about in the readme, for increments and toggles.

Now let's say you want to implement a control to turn a light, or group of lights, on and off. In this case you'll use the method register_event to set the variable landing_light_switch to either 0 or 1. The register methods are always implemented in the initialize(reload) function of the script, and can be used to directly set a global variable or jsb property. You'll notice I set the variable to 0 above the register_event method, which in initialize(reload) sets the light switch to the off position when the aircraft script is initialized. Alternatively you could always set it to on, but I chose the initial state to be off for performance reasons, allowing users to turn on lights as desired. Remember to always declare your global variables at the top of the script.


--- Code: ---landing_light_switch = 0;
this.register_event("air/lights/landing_lights", function(v) { landing_light_switch ^= 1; });
--- End code ---

The first parameter is a string "air/lights/landing_lights", which specifies the config file, in this case air.cfg, the action group "lights", and the control "landing_lights". This method is setup to toggle the parameter v off/on (0/1), setting the variable landing_light_switch, which in this particular case is switched using the 'L' key.

A more complicated control is one I developed for dynamic in-cockpit zoom in/out function. It is already implemented on both the mig29 and c172.

First we must call the OT World Interface in initialize(reload) function, and set it to a global variable, in this case ot_world is declared at the top of the script.


--- Code: ---ot_world = this.$query_interface("ot::js::world.get");
--- End code ---

This interface will give the script access to a method to set the horizontal field of view (HFOV) later in update_frame(dt). Here is the extended control function.


--- Code: ---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;
});
--- End code ---

You'll notice I used the register_axis method instead of the register_event method, which increments the output between 0 and 1. I have included parameters to define; minval, maxval, vel, and center... read more about these in the readme doc. I have declared the global variable fov_cockpit_zoom at the top of the script, and here I am setting it to an initial value of 81.8, which will set the initial camera HFOV. In the function, I have a number of local variables. dec2int multiples the parameter v by a fixed value, transforming a decimal between 0 to 1 into an integer between 0 to 48. The next variable integer simply uses the math function Math.floor to force the number to be an integer, this is optional. The next variable string subtracts the integer from out initial value of 81.8, so as the parameter v increases our output decreases, therefore zooming in. Finally, our variable fov_cockpit_zoom is set to the output. The final step is to call a method in update_frame(dt) which sets the HFOV for the camera, using the method set_camera_fov. I use an if statement to only set the FOV is camera mode is 0 or FPS mode.


--- Code: ---//Set FPS camera FOV OT World Interface
if (this.get_camera_mode() == 0){
  ot_world.set_camera_fov(fov_cockpit_zoom);
}
--- End code ---

This should give you a small taste of what is possible with the extend controls.

Best regards,
Uriah



The default handlers for aircraft are as follow:

Key Bind:             Function:

W / S                    Elevator (longitudinal cyclic for heli)
A / D                     Aileron (lateral cyclic for heli)
Z / X                     Rudder (anti torque for heli)
Ctrl + W / S          Elevator Trim
Ctrl + A / D           Aileron Trim
Ctrl + Z / X           Rudder Trim
Insert                    Flaps Down
Delete                   Flaps Up
E                          Engine on/off
PgUp                    Throttle Up
PgDn                    Throttle Down
Period ( . )            Landing Gear
B                          Brakes         
Home                    Mixture Up
End                       Mixture Down
R / F                      Collective (heli)
Shift + A               Altitude Hold (heli)
Shift + S               Stability Augmentation System (heli)


I have added some basic extended controls to the mig29 and c172 scripts which are as follow.

Key Bind:             Function:

C                         Canopy open/close
L                         Landing Lights on/off
Shift + L              Cockpit Lights on/off
Shift + N             Nav Lights on/off
Ctrl + L               Strobe Lights on/off
Shift + W            Wing Level Autopilot on/off
NumAdd ( + )      Zoom In (Number Pad)
NumSub ( - )        Zoom Out (Number Pad)
P                         Deploy/Cut Braking Parachute (mig29)

andfly:
Thanks!....Thanks!......Thanks!...................   T H A N K S !!!!!   :)

SteelRat:
Hi Uriah!


--- Code: ---{
    name : "transmission",
    actions : [
{ name : "up_gear", comment : "Up gear", bindings : [{event_name:"PageUp"}], important:true },
{ name : "down_gear", comment : "Down gear", bindings : [{event_name:"PageDown"}], important:true }
    ]},
--- End code ---

What sets this property?

--- Code: ---important:true
--- End code ---

Uriah:
I believe that is for the "Show important actions only" check box in the Controls UI, which currently seems to not be functional. It is meant so you can filter the long list of controls to only the important ones, but currently you'll notice the check box says "Show advanced controls", and when that is not checked the list is blank. Cameni said it isn't finished yet.

Regards,
Uriah

SteelRat:
Thanks!

Navigation

[0] Message Index

[#] Next page

Go to full version