SDK Question Drawing on a texture for a HUD

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
Working on the Space 1999 eagle. Trying to duplicate the upper left HUD display.

Pretty much got everything to work but the main/retro

Using the orbiter source code for a guide.
Orbiter code
// Update main engine status vofs += 4; double th = g_focusobj->GetThrusterGroupLevel(THGROUP_MAIN); if (!th) th = -g_focusobj->GetThrusterGroupLevel(THGROUP_RETRO); if (th != engmain) { engmain = th; if (th >= 0.0) { grp->Vtx[vofs].x = grp->Vtx[vofs+2].x = dx+46.0f*scale; grp->Vtx[vofs+1].x = grp->Vtx[vofs+3].x = dx+(float)((46.0+engmain*94.0)*scale); for (i = 0; i < 4; i++) grp->Vtx[vofs+i].tu = 4.0f/texw; } else { grp->Vtx[vofs].x = grp->Vtx[vofs+2].x = dx+(140.0f+(float)engmain*94.0f)*scale; grp->Vtx[vofs+1].x = grp->Vtx[vofs+3].x = dx+140.0f*scale; for (i = 0; i < 4; i++) grp->Vtx[vofs+i].tu = 6.0f/texw; } } // Update main engine readout vofs += 4*5; th = (engmain >= 0.0 ? engmain*g_focusobj->GetThrusterGroupMaxth(THGROUP_MAIN) : -engmain*g_focusobj->GetThrusterGroupMaxth(THGROUP_RETRO));

and then mine:
double th = GetThrusterGroupLevel(THGROUP_MAIN); //get thrust main level if (!th) th = GetThrusterGroupLevel(THGROUP_RETRO); //get retro thrusters - 1 to 0 if (th != engmain) { engmain = th; if (th >= 0.0) { //draw thrust level //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); SelectObject(hDC, g_Param.hBrush[1]);//green box Rectangle(hDC, 130, 144, (int)(130 + engmain * (200)), 187);//thrust } //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); //retro else { //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); SelectObject(hDC, g_Param.hBrush[2]);//yellow box Rectangle(hDC, 130, 144, (int)(130 - engmain * (200)), 187);//thrust } } th = (engmain >= 0.0 ? engmain * th : -engmain * th);

What it is suppose to do is draw a green rectangle for main thrust and a yellow one for retro. But all I get is the green one
As I understand the code is if th >=0 (MAin) draw the rectangle start at the left and draw to the right. if th<0 then draw a yellow rectangle right to left.
But for me th is always 0 or 1.


API
The main/retro engine level has a range of [-1,+1]. A positive value indicates engaged main/disengaged retro thrusters, a negative value indicates engaged retro/disengaged main thrusters. Main and retro thrusters cannot be engaged simultaneously. For vessels without retro thrusters the valid range is [0,+1]. double main; // -1 (full retro) .. +1 (full main)
 

Attachments

  • eaglevcreadout.jpg
    eaglevcreadout.jpg
    52 KB · Views: 5

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
236
Reaction score
275
Points
78
Location
On my chair
I'd say GetThrusterGroupLevel(THGROUP_RETRO); returns something in [0;1] and not [-1;0]

API
The main/retro engine level has a range of [-1,+1]. A positive value indicates engaged main/disengaged retro thrusters, a negative value indicates engaged retro/disengaged main thrusters. Main and retro thrusters cannot be engaged simultaneously. For vessels without retro thrusters the valid range is [0,+1]. double main; // -1 (full retro) .. +1 (full main)

This is valid for the oapiGetEngineStatus. If you look more closely at its implementation you'll notice that it negates the retro thruster's level :

Code:
void Vessel::EngineStatus (ENGINESTATUS *es)
{
    es->main = GetThrusterGroupLevel (THGROUP_MAIN);
    if (!es->main) es->main = -GetThrusterGroupLevel (THGROUP_RETRO);
    es->hover = GetThrusterGroupLevel (THGROUP_HOVER);
    es->attmode = attmode;
}


Also you should use the sketchpad API instead of the old GDI stuff if you want to be futureproof.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
Thanks.

Not sure about the Sketchpad versus GDi

So how do I take that and get it to tell it to draw.

Should that be called?
void EAGLEUACS::EngineStatus(ENGINESTATUS* es) { es->main = GetThrusterGroupLevel(THGROUP_MAIN); if (!es->main) es->main = -GetThrusterGroupLevel(THGROUP_RETRO); es->hover = GetThrusterGroupLevel(THGROUP_HOVER); //es->attmode = attmode; }
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
So get thruster level returns 0 to 1 while get engine status return -1 to 0 to1.

So es->main get the main thruster level
if es not ->main then get -retro level

but how to use that to draw the rectangle.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
I looked at example is the Shuttle A and DG. The hud is sketchpad.
bool EAGLEUACS::clbkDrawHUD(int mode, const HUDPAINTSPEC* hps, oapi::Sketchpad* skp)

but shuttle A
void ShuttleA::RedrawPanel_Fuelstatus (SURFHANDLE surf, int part) { char cbuf[20]; int len; double m, m0, rate, lvl; HDC hDC = oapiGetDC (surf); SelectObject (hDC, g_Param.hFont[0]); SelectObject (hDC, g_Param.hBrush[1]); SelectObject (hDC, g_Param.hPen[2]); SetTextColor (hDC, RGB(224,224,224)); SetBkMode (hDC, TRANSPARENT); SetTextAlign (hDC, TA_RIGHT); Rectangle (hDC, 0, 57, 32, 19+(int)((1.0-lvl)*38.0));
I need to get the main engine level and draw a green rectangle and get the retro and draw a yellow rectangle
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
So how to get thrust level of main and do something with it and then get thrustlevel and retro and do something.

This draws the main thrust good:
th = GetThrusterGroupLevel(THGROUP_MAIN); //get thrust main level engmain = th; SelectObject(hDC, g_Param.hBrush[1]);//green box Rectangle(hDC, 130, 144, (int)(130 + engmain * (330 - 130)), 187);//thrust
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,771
Reaction score
2,758
Points
203
Location
Dallas, TX
VERY close
th = GetThrusterGroupLevel(THGROUP_MAIN); //get thrust main level if (!th) th = -GetThrusterGroupLevel(THGROUP_RETRO); //get retro thrustes - 1 to 0 //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, *es); //th = GetThrusterGroupLevel(THGROUP_MAIN); //get thrust main level // th = -1; // or get retro thrustes -1 to 0 //if (th != engmain) { engmain = th; if (th >= 0.0) { //draw thrust level //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); SelectObject(hDC, g_Param.hBrush[1]);//green box Rectangle(hDC, 130, 144, (int)(130 + engmain * (330 - 130)), 187);//thrust sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); } //sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); //retro else { sprintf(oapiDebugString(), "main %5f th %5f ", engmain, th); SelectObject(hDC, g_Param.hBrush[2]);//yellow box Rectangle(hDC, 130, 144, (int)(130 - engmain * (200)), 187);//thrust }
draw yellow for retro and green for main:)
th = (engmain >= 0.0 ? engmain * GetThrusterGroupLevel(THGROUP_MAIN)*4*MAX_MAIN_THRUST :
-engmain * GetThrusterGroupLevel(THGROUP_RETRO) * 4 * MAX_RETRO_THRUST);
and then display the thrust amount.
static char strbuf[16]; double absf1 = fabs(th);//thrust if (absf1 < 1e4) { if (absf1 < 1e2) sprintf(strbuf, "%5.2f", th); else if (absf1 < 1e3) sprintf(strbuf, "%5.1f", th); else sprintf(strbuf, "%4.2fk", th * 1e-3); } else if (absf1 < 1e7) { if (absf1 < 1e5) sprintf(strbuf, "%4.1fk", th * 1e-3); else if (absf1 < 1e6) sprintf(strbuf, "%4.0fk", th * 1e-3); else sprintf(strbuf, "%4.2fm", th * 1e-6); } else if (absf1 < 1e10) { if (absf1 < 1e8) sprintf(strbuf, "%4.1fm", th * 1e-6); else if (absf1 < 1e9) sprintf(strbuf, "%4.0fm", th * 1e-6); else sprintf(strbuf, "%4.2fG", th * 1e-9); } else { if (absf1 < 1e11) sprintf(strbuf, "%4.1fG", th * 1e-9); else if (absf1 < 1e12) sprintf(strbuf, "%4.0fG", th * 1e-9); else sprintf(strbuf, "%5e", th); } TextOut(hDC, 345, 145, strbuf, strlen(strbuf));
the only thing now is if no thrust is chosen it shows -0.00. if thrust is applied the thrust is positive.
but the display we get the Fabs (th)
 

Attachments

  • eagledisplay.jpg
    eagledisplay.jpg
    42.8 KB · Views: 2
Last edited:
Top