飞机的初始位置信息一般包括,经度、纬度、高度、航向、速度、横滚、俯仰。通过xPlane11的SDK来设置本机的初始位置信息,一般需要使对应的sdk接口;
经度:
XPLMDataRef plane_lon = XPLMFindDataRef("sim/flightmodel/position/longitude");
纬度:
XPLMDataRef plane_lat = XPLMFindDataRef("sim/flightmodel/position/latitude");
高度:
XPLMDataRef plane_alt = XPLMFindDataRef("sim/flightmodel/position/elevation");
航向:
XPLMDataRef plane_head = XPLMFindDataRef("sim/flightmodel/position/psi");
速度:
XPLMDataRef plane_speed = XPLMFindDataRef("sim/flightmodel/position/indicated_airspeed");
横滚:
XPLMDataRef plane_roll = XPLMFindDataRef("sim/flightmodel/position/phi");
俯仰:
XPLMDataRef plane_pith = XPLMFindDataRef("sim/flightmodel/position/theta");
注意有时在设置经纬高时,需要对经纬高进行转换,需要使用函数XPLMWorldToLocal进行转化
/*
* XPLMWorldToLocal
*
* This routine translates coordinates from latitude, longitude, and altitude
* to local scene coordinates. Latitude and longitude are in decimal degrees,
* and altitude is in meters MSL (mean sea level). The XYZ coordinates are in
* meters in the local OpenGL coordinate system.
*
*/
XPLM_API void XPLMWorldToLocal(
double inLatitude,
double inLongitude,
double inAltitude,
double * outX,
double * outY,
double * outZ);
使用sdk进行设置xPlane11飞机初始位置信息:
/*经度*/
XPLMSetDatad(plane_lon, m_dLon);
/*纬度*/
XPLMSetDatad(plane_lat, m_dLat);
/*高度*/
XPLMSetDatad(plane_alt, m_dAlt);
/*航向*/
XPLMSetDataf(plane_head, m_head);
/*俯仰*/
XPLMSetDataf(plane_pith, m_pith);
/*横滚*/
XPLMSetDataf(plane_roll, m_roll);
/*速度*/
XPLMSetDataf(plane_speed, m_speed);
注:如果初始速度和航向设置失败,则可以使用XPLMPlaceUserAtLocation进行设置
/*
* XPLMPlaceUserAtLocation
*
* Places the user at a specific location after performing any necessary
* scenery loads.
*
* As with in-air starts initiated from the X-Plane user interface, the
* aircraft will always start with its engines running, regardless of the
* user's preferences (i.e., regardless of what the dataref
* `sim/operation/prefs/startup_running` says).
*
*/
XPLM_API void XPLMPlaceUserAtLocation(
double latitudeDegrees,
double longitudeDegrees,
float elevationMetersMSL,
float headingDegreesTrue,
float speedMetersPerSecond);
版权声明:本文为博主原创文章,转载请附上博文链接!