MouseAircraft
The MouseAircraft
aircraft is a module of the WASMAircraft modular aircraft, illustrates how to obtain mouse information from a WebAssembly gauge. Additionally, it showcases how to trigger sound events using local variables from WebAssembly. Once the WASM Aircraft package has been built, this module will be available for flying from the aircraft selection screen:
Note that if you make changes to the C++ code and recompile the mouse aircraft WASM module, you will have to build your package again (using the Build Package button in the Edit Package window). This can be done while the plane is used within the simulation.
Mouse Callback
As described in the Handling Mouse Events section, mouse events can be obtained from a Gauge by declaring the corresponding mouse callback, eg:
MSFS_CALLBACK void GAUGENAME_mouse_callback(float fX, float fY, unsigned int iFlags)
{
switch (iFlags)
{
case MOUSE_MOVE:
...
break;
case MOUSE_LEFTSINGLE:
...
break;
case MOUSE_LEFTDOUBLE:
...
break;
case MOUSE_LEFTDRAG:
...
break;
case MOUSE_LEFTRELEASE:
...
break;
case MOUSE_RIGHTSINGLE:
...
break;
case MOUSE_RIGHTDOUBLE:
...
break;
case MOUSE_RIGHTDRAG:
...
break;
case MOUSE_RIGHTRELEASE:
...
break;
case MOUSE_MIDDLESINGLE:
...
break;
case MOUSE_MIDDLEDOUBLE:
...
break;
case MOUSE_MIDDLEDRAG:
...
break;
case MOUSE_MIDDLERELEASE:
...
break;
case MOUSE_WHEEL_DOWN:
...
break;
case MOUSE_WHEEL_UP:
...
break;
}
}
Gauge Files
The following files are used for the gauges in this example:
Toggle.cpp
: displays how to detect mouse events inside of an on-gauge rectangle
MouseInformation.cpp
: provides debug information of mouse displacement and button actions
TriggerSound.cpp
: provides a sample on how to control both single and continuous sound events
It is worth noting that the sound event is first declared in sounds\sound.xml
, linking the WwiseEvent
with the LocalVar
as described in the WwiseSampleProject. Then, the LocalVar
is controlled from the WebAssembly module:
int sound_lvar_id = lvarregister_named_variable("LocalVar_in_sound.xml");
...
set_named_variable_value(sound_lvar_id, trigger_value);