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:
This is my attempt to use it:
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:
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?
This is the code in Interpreter.cpp that implements it, which seems to show the two returns of a vector and a number: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:
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.
- 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)
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:
- vector wind velocity vector relative to surface [m]
- number wind speed magnitude in the local horizon frame, independent of the frame selected [m/s]
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:
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.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.
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: