Code to Draw FD on the HUD
Franz,
Here 'tis (draft code, not tested fully)
------------------------------------------------
void SomeClass:
rawFlightDirector(HDC hDC) {
// On input, the following variables are assumed to exist:
// int g_CEVHUD.width reference display width (pixels)
// int g_CEVHUD.height reference display height (pixels)
// double g_Data.RErr Roll Error (radians)
// double g_Data.PErr Pitch Error (radians)
// double g_Data.YErr Yaw Error (radians)
// double g_Data.XErr Left Error (display radians)
// double g_Data.YErr Down Error (display radians)
// double g_Data.ZErr Out Error (display radians, scaled so that zero error is six degrees)
// WORD g_Data.BMode 1st bit = Rotational Mode, 2nd bit = Translational Mode
// hDC Device Drawing Context
#define RAD 0.017453292519943295769236907684886 // (Radians Per Degree)
if(!g_Data.BMode) return; // exit if no flight director mode
int w = g_CEVHUD.width;
int h = g_CEVHUD.height;
double Sx = (double) h / oapiCameraAperture(); // Scale, pixels per radian
double Sy = Sx;
double sr, cr, xx, yy, x1, y1, x2, y2, x3, y3;
int xs1, ys1, xs2, ys2, xs3, ys3;
SelectDefaultPen (hDC, 2);
// Draw Rotational Flight Director
if(g_Data.BMode & 0x01) {
sr = -sin(g_Data.RErr); // sine roll angle
cr = cos(g_Data.RErr); // cosine roll angle
xx = -3.0*RAD+g_Data.YErr; // First Point (Left Wing)
yy = -3.0*RAD+g_Data.PErr;
x1 = xx*cr-yy*sr;
y1 = xx*sr+yy*cr;
xs1 = w/2+(int) (x1*Sx);
ys1 = h/2-(int) (y1*Sy);
xx = g_Data.YErr; // Second Point (Apex)
yy = g_Data.PErr;
x2 = xx*cr-yy*sr;
y2 = xx*sr+yy*cr;
xs2 = w/2+(int) (x2*Sx);
ys2 = h/2-(int) (y2*Sy);
xx = 3.0*RAD+g_Data.YErr; // Third Point (Right Wing)
yy = -3.0*RAD+g_Data.PErr;
x3 = xx*cr-yy*sr;
y3 = xx*sr+yy*cr;
xs3 = w/2+(int) (x3*Sx);
ys3 = h/2-(int) (y3*Sy);
MoveToEx(hDC,xs1,ys1,NULL);
LineTo( hDC,xs2,ys2);
MoveToEx(hDC,xs2,ys2,NULL);
LineTo( hDC,xs3,ys3);
}
// Draw Translational Flight Director
if(g_Data.BMode & 0x02) {
x1 = g_Data.XErr-0.5*g_Data.ZErr;
y1 = g_Data.YErr;
xs1 = w/2+(int)(x1*Sx);
ys1 = h/2-(int)(y1*Sy);
x2 = g_Data.XErr+0.5*g_Data.ZErr;
y2 = g_Data.YErr;
xs2 = w/2+(int)(x2*Sx);
ys2 = h/2-(int)(y2*Sy);
MoveToEx(hDC,xs1,ys1,NULL);
LineTo( hDC,xs2,ys2);
}
}