MotionPlatform

From X-Plane SDK
Jump to: navigation, search

This code calculates the MOTI packet. motion_dat is an array of 7 floats that receives the final data. This is paraphrased from the x-plane code; make sure to check this before using it! Also in production code DO NOT call XPLMFindDataRef every frame...call it once and save the results.

typedef	float	xflt;
xflt	V_msc = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/groundspeed"));
xflt	fnrml_prop = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fnrml_prop"));
xflt	fside_prop = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fside_prop"));
xflt	faxil_prop = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/faxil_prop"));
xflt	fnrml_aero = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fnrml_aero"));
xflt	fside_aero = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fside_aero"));
xflt	faxil_aero = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/faxil_aero"));
xflt	fnrml_gear = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fnrml_gear"));
xflt	fside_gear = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/fside_gear"));
xflt	faxil_gear = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/forces/faxil_gear"));
xflt	m_total = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/weight/m_total"))
xflt	the = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/theta"));
xflt	psi = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/psi"));
xflt	phi = XPLMGetDataf(XPLMFindDataRef("sim/flightmodel/position/phi"));

xflt ratio =fltlim (V_msc*0.2,0.0,1.0);
xflt a_nrml=fallout(fnrml_prop+fnrml_aero+fnrml_gear,-0.1,0.1)/fltmax2(m_total,1.0);
xflt a_side=       (fside_prop+fside_aero+fside_gear         )/fltmax2(m_total,1.0)*ratio;
xflt a_axil=       (faxil_prop+faxil_aero+faxil_gear         )/fltmax2(m_total,1.0)*ratio;
{
       motion_dat[ 0]=the;
       motion_dat[ 1]=psi;
       motion_dat[ 2]=phi;
       motion_dat[ 3]=a_side;
       motion_dat[ 4]=a_nrml;
       motion_dat[ 5]=a_axil;
// The sixth motion param is not available to plugins!!  But probably not that
// important.  If you need keys, use a key sniffer!!  XPLMDisplay.h for more info.
//       motion_dat[ 6]=(xflt)mnw.key_pressed;
}