Question oapi.get_windvector() only returns single numerical value

Thunder Chicken

Resident Lua Script Rabble-Rouser
Donator
Joined
Mar 22, 2008
Messages
5,847
Reaction score
5,509
Points
188
Location
Massachusetts
So I am looking to make a wind sock for a visual indication of wind speed and direction for an airfield. I am making it as a stationary vessel. I am attempting to use oapi.get_windvector to get the local wind velocity vector and magnitude. This is the documentation for it:

get_windvector (hPlanet, lng, lat, altitude, frame) Returns the wind velocity at a given position in a planet's atmosphere.

The frame flag can be used to specify the reference frame to which thereturned vector refers. The following values are supported:
  • 0: surface-relative (relative to local horizon)
  • 1: planet-local (relative to local planet frame)
  • 2: planet-local non-rotating (as 1, but adds the surface velocity, see \ref oapiGetGroundVector)
  • 3: global (maps to global frame and adds planet velocity)
Warning: Local wind velocities are not currently implemented. The surface-relativewind velocity is always (0,0,0). To ensure forward compatibility, pluginsshould not rely on this limitation, but use this function instead.

Parameters:​

  • hPlanet handle planet handle
  • lng number longitude [rad]
  • lat number latitude [rad]
  • altitude number above mean planet radius [m]
  • frame number reference frame flag

Returns:​

  1. vector wind velocity vector relative to surface [m]
  2. number wind speed magnitude in the local horizon frame, independent of the frame selected [m/s]
This is the code in Interpreter.cpp that implements it, which seems to show the two returns of a vector and a number:

C++:
int Interpreter::oapi_get_windvector(lua_State *L)
{
    OBJHANDLE hRef;
    ASSERT_SYNTAX(lua_islightuserdata(L, 1), "Argument 1: invalid type (expected handle)");
    ASSERT_SYNTAX(hRef = lua_toObject(L, 1), "Argument 1: invalid object");
    double lng = luaL_checknumber(L, 2);
    double lat = luaL_checknumber(L, 3);
    double alt = luaL_checknumber(L, 4);
    int frame = luaL_checkinteger(L, 5);
    double windspeed;
    VECTOR3 gv = oapiGetWindVector(hRef, lng, lat, alt, frame, &windspeed);
    lua_pushvector(L, gv);
    lua_pushnumber(L, windspeed);
    return 1;
}

This is my attempt to use it:

Code:
function clbk_prestep(simt,simdt,mjd)
    pos, hPlanet = vi:get_equpos()
    altitude = vi:get_altitude(ALTMODE.MEANRAD)
    wind_vector, wind_speed = oapi.get_windvector(hPlanet, pos.lng, pos.lat, altitude, 1)
end

This runs without any errors, but it doesn't provide two returns as indicated.

oapi.dbg_out(wind_vector) returns a number when a vector was expected.
oapi.dbg_out(type(wind_vector)) returns "number".
oapi.dbg_out(wind_speed) returns nil

Output for altitude, pos.lng, pos.lat all return correct values. oapi.dbg_out(hPlanet) returns some hexadecimal number with a tag [data], which I don't know is correct or not, but I am not getting any errors related to oapi.get_windvector so there doesn't seem to be a type mismatch for the first argument at least. I don't see how I could be getting the correct lat and lng coordinates if the planet handle was wrong.

I don't know if the text of the warning is relevant:
Warning: Local wind velocities are not currently implemented. The surface-relativewind velocity is always (0,0,0). To ensure forward compatibility, pluginsshould not rely on this limitation, but use this function instead.
Does "Local wind velocities are not currently implemented" mean that this function is currently useless? I have atmospheric wind effects applied in Options/Physical Settings.

If I set the flag to 0, I would still expect to get a (0,0,0) vector as stated in the warning, but it doesn't return a vector at all, with any flag.

I have no idea what to make of "To ensure forward compatibility, plugins should not rely on this limitation, but use this function instead." in the context of this function. What limitation and what function is it referring to?
 
Last edited:
Opened as issue #565: https://github.com/orbitersim/orbiter/issues/565

A workaround to get the local windspeed in general for moving vessels is to take the vessel airspeed vector and the vessel ground speed vector, both in the horizontal frame (vi:get_airspeedvector(REFFRAME.HORIZON) and vi:get_groundspeed(REFFRAME.HORIZON)), and subtract them (vec.sub(vecA, vecB)) to isolate the wind speed vector. I did this for my sailing skiff.

As the wind sock is stationary the airspeed vector will be equal to the local windspeed vector.
 
A workaround to get the local windspeed in general for moving vessels is to take the vessel airspeed vector and the vessel ground speed vector, both in the horizontal frame (vi:get_airspeedvector(REFFRAME.HORIZON) and vi:get_groundspeed(REFFRAME.HORIZON)), and subtract them (vec.sub(vecA, vecB)) to isolate the wind speed vector. I did this for my sailing skiff.

As the wind sock is stationary the airspeed vector will be equal to the local windspeed vector.
It actually seems that this workaround isn't viable for some reason. The vessel status is inactive/landed and doesn't have any engines, so vi:get_airspeedvector() and vi:get_airspeed() both return 0 even with atmospheric wind effects turned on. oapi.get_airspeedvector() and oapi.get_airspeed() seem to also not work. They would only work for a flag or wind sock if they were the focus vessel, but the idea is that I want it to visually indicate the wind speed and direction when I am in another vessel flying around the flag.

oapi.get_windvector() does give me the wind velocity magnitude even in the landed state, but I am still missing the direction information. So close...grr.
 
So standard animation transformations still work on the modified mesh groups, so I can do this:

flag_waving_in_a_circle-gif.42570


The last piece is getting the wind direction, and then I would have an effective wind visual reference. 🎏
 
I tried putting an airfoil on it so it would weathervane without an animation or having data about wind direction, but because it is Inactive/Landed, the airfoils don't work. I need to break out of Inactive/Landed status somehow.
 
A windsock is a great idea!
Could you use an invisible dummy object that moves and resets it's position to read the wind vector?
 
Could you use an invisible dummy object that moves and resets it's position to read the wind vector?
Well, the flag itself is a dummy object. If I can't use that, how does adding another object help? I need to get it out of an inactive/landed state to register airspeeds.
 
Well, the flag itself is a dummy object. If I can't use that, how does adding another object help? I need to get it out of an inactive/landed state to register airspeeds.
What about giving it a thruster to lift it sufficiently, then it should be no longer “landed”, in that scenario anyway.
 
Back
Top