Advanced Question Drawing on a texture in VC

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
Iceland?

All tanks are full
Code:
	double level2 = GetPropellantMass(tank1);
	double level4 = GetPropellantMass(tank2);//hover
	double level5 = GetPropellantMass(tank3);//rcs


	//double level = GetThrusterLevel(th_main[0]);
//	double level2 = GetPropellantMass(tank);
	//double level3 = GetThrusterLevel(th_hover[0]);


	SelectObject(hDC, g_Param.hBrush[4]);//green box
	//Rectangle(hDC, 150, 144, (int)(150 + level * (351 - 150)), 187);//thrust

	//Rectangle(hDC, 150, 217, (int)(150 + level3 * (350 - 150)), 260);//thrust
	fuel1rate1 = ((455 - 325) / FUELMASS1);
	fuel1rate2 = ((455 - 325) / FUELMASS2);
	fuel1rate3 = ((455 - 325) / FUELMASS3);

	Rectangle(hDC, 131, 325, 174, (int)(455 - (level2)*fuel1rate1));  //fuel
	
	Rectangle(hDC, 241, 325, 284, (int)(455 - (level4)*fuel1rate2)); //fuel

	Rectangle(hDC, 350, 325, 394, (int)(455 - (level5)*fuel1rate3));  //rscfuel


	SetTextColor(hDC, RGB(0, 153, 0));
	SetTextAlign(hDC, TA_LEFT);
	SetBkMode(hDC, TRANSPARENT);

	SelectObject(hDC, g_Param.hFont[1]);
	sprintf(cbuf, "%0.1f", level2 );
	TextOut(hDC, 130, 474, cbuf, strlen(cbuf));
	

	sprintf(cbuf, "%0.1f", level4);
	TextOut(hDC, 244,474, cbuf, strlen(cbuf));
	

	sprintf(cbuf, "%0.1f", level5);
	TextOut(hDC, 352, 474, cbuf, strlen(cbuf));

Now I get no bars.
Code:
const double FUELMASS1 = 4000;
const double FUELMASS2 = 4000;
const double FUELMASS3 = 2000;
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
What type is "fuel1rate1"?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
double fuelrate1,fuelrate2,fuelrate3.

when I run the debugger :
fuel1rate1 0.032500000000000001 double
fuel1rate2 0.032500000000000001 double
fuel1rate3 0.065000000000000002 double

What is odd is in the debugger I don't see level2,4 just level 5
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
double fuelrate1,fuelrate2,fuelrate3.

when I run the debugger :
fuel1rate1 0.032500000000000001 double
fuel1rate2 0.032500000000000001 double
fuel1rate3 0.065000000000000002 double

What is odd is in the debugger I don't see level2,4 just level 5

Strange... are you showing the variables in auto view?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
Yes. Is wtched to autos versus locals
I also made it level 6

level6 4000.0000000000000 double
level5 2000.0000000000000 double
level4 4000.0000000000000 double

The value are correct in the box on screen but no bars.

Code:
void RANGER::RedrawPanel_CENTERFuelstatus(SURFHANDLE surf, int part)

{

	char cbuf[20];
	HDC hDC = oapiGetDC(surf);

	double level6 = GetPropellantMass(tank1);
	double level4 = GetPropellantMass(tank2);//hover
	double level5 = GetPropellantMass(tank3);//rcs


	//double level = GetThrusterLevel(th_main[0]);
//	double level2 = GetPropellantMass(tank);
	//double level3 = GetThrusterLevel(th_hover[0]);


	SelectObject(hDC, g_Param.hBrush[4]);//green box
	//Rectangle(hDC, 150, 144, (int)(150 + level * (351 - 150)), 187);//thrust

	//Rectangle(hDC, 150, 217, (int)(150 + level3 * (350 - 150)), 260);//thrust
	fuel1rate1 = ((455 - 325) / FUELMASS1);
	fuel1rate2 = ((455 - 325) / FUELMASS2);
	fuel1rate3 = ((455 - 325) / FUELMASS3);

	Rectangle(hDC, 131, 325, 174, (int)(455 - (level6)*fuel1rate1));  //fuel
	
	Rectangle(hDC, 241, 325, 284, (int)(455 - (level4)*fuel1rate2)); //fuel

	Rectangle(hDC, 350, 325, 394, (int)(455 - (level5)*fuel1rate3));  //rscfuel


	SetTextColor(hDC, RGB(0, 153, 0));
	SetTextAlign(hDC, TA_LEFT);
	SetBkMode(hDC, TRANSPARENT);

	SelectObject(hDC, g_Param.hFont[1]);
	sprintf(cbuf, "%0.1f", level6 );
	TextOut(hDC, 130, 474, cbuf, strlen(cbuf));
	

	sprintf(cbuf, "%0.1f", level4);
	TextOut(hDC, 244,474, cbuf, strlen(cbuf));
	

	sprintf(cbuf, "%0.1f", level5);
	TextOut(hDC, 352, 474, cbuf, strlen(cbuf));
	

	
	SelectObject(hDC, g_Param.hFont[3]);

	if (GEAR_status == GEAR_UP) {
		sprintf(cbuf, "GEAR UP", 7);
		TextOut(hDC, 250, 100, cbuf, strlen(cbuf));
		//TextOut(hDC, 400, 100, cbuf, strlen(cbuf));
		TextOut(hDC, 10, 100, cbuf, strlen(cbuf));
	}
	if (GEAR_status == GEAR_DOWN) {
		sprintf(cbuf, "GEAR DOWN", 9);
		TextOut(hDC, 50, 172, cbuf, strlen(cbuf));
	}




	oapiReleaseDC(surf, hDC);
}


---------- Post added at 06:00 AM ---------- Previous post was at 05:33 AM ----------

I change the code so I can see the what the right y value should be :
Code:
fuelboxy = (455 - (level6)*fuel1rate1);

	Rectangle(hDC, 131, 325, 174, (int)(fuelboxy));  //fuel

the math looks good:

fuelboxy 325.00000000000000 double

---------- Post added at 07:17 AM ---------- Previous post was at 06:00 AM ----------

I wonder if the mesh/texture not being mapped right might be an issue for the bars?

rangercentermesh2.jpg


I added text to the texture to see about the other areas?
rangerfrontdisplay6a.bmp


---------- Post added at 09:01 PM ---------- Previous post was at 07:17 AM ----------

I retextured and get the GEAR up on both sides. But on the bars if there fuel mass is 0 then it draws the full bar but if full it draws no bars. So it is backwards

---------- Post added 06-29-16 at 05:19 AM ---------- Previous post was 06-28-16 at 09:01 PM ----------

oK. I took the other black area out and made them a separate texture.

So what I don't understand is you get the value from the original texture. The texture is 512x512. But then when you paint it on the mesh wouldn't the points move as you stretch/shrink it?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
Ok I am trying to think of why the bars are not drawing correctly. the math seems good. But what if the points were off due to mapping on the mesh?

---------- Post added at 06:02 AM ---------- Previous post was at 05:35 AM ----------

Well its not the points. I had it just the bar and it was good.
Code:
	Rectangle(hDC, 131, 325, 174, 455);  //fuel
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Ok I am trying to think of why the bars are not drawing correctly. the math seems good. But what if the points were off due to mapping on the mesh?

---------- Post added at 06:02 AM ---------- Previous post was at 05:35 AM ----------

Well its not the points. I had it just the bar and it was good.
Code:
    Rectangle(hDC, 131, 325, 174, 455);  //fuel

I also doubt it is that simple. Your mapping might be strange, but then, you can always simply paint a colored pattern on the whole texture to check what goes where.

What I wonder is: Does Sketchpad like drawing rectangles from bottom to top? Usually the first coordinate is the upper left corner and the second the lower right corner.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
What I wonder is: Does Sketchpad like drawing rectangles from bottom to top? Usually the first coordinate is the upper left corner and the second the lower right corner.
I believe yes. That is how I did it on the others that work.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
So what would the math look like if it draw from top to bottom. We know the coordinates are ok. Just that it draws upside down
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
So what would the math look like if it draw from top to bottom. We know the coordinates are ok. Just that it draws upside down

Well, right now, you draw the wrong part of the diagram green.

You calculate the empty rectangle on top for painting, not the green rectangle below it.

Thus you should actually have the following instructions:

Code:
Rectangle(hDC, 131, 455 - (int)(level6*fuel1rate1), 174, 455);

Also, I recommend you to use oapi::Sketchpad instead of GDI drawing (HDC). Aren't you using VESSEL3 as base for your vessel?
 

GLS

Well-known member
Orbiter Contributor
Addon Developer
Joined
Mar 22, 2008
Messages
5,878
Reaction score
2,870
Points
188
Website
github.com
On Sketchpad, for the rectangle you must have x1 <= x2 and y1 <= y2, i.e. top-left and bottom-right coordinates, or nothing will show. On GDI it works with any 2 opposed corners of the rectangle.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
On Sketchpad, for the rectangle you must have x1 <= x2 and y1 <= y2, i.e. top-left and bottom-right coordinates, or nothing will show. On GDI it works with any 2 opposed corners of the rectangle.
Well the values seem right.

x1 = 131 y1 = 325
x2 = 174 y2= 455

But the y values should increase from 325 to 455 for the bar to go from full (325) to empty (455)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
I am going to try to do the MET meter by drawing on the MET texture.

I got the MET broke into parts. But for some reason the VC is not seen.
here the mettimer1 is being set as external and vc.

SetMeshVisibilityMode(MeshMain = AddMesh(METNUMBERS = oapiLoadMeshGlobal("mettimer1")), MESHVIS_EXTERNAL|| MESHVIS_VC);

I see it in the external but when I go to VC I see nothing.
same camera values:
SetCameraOffset(_V(0, 0, -.165));
bool METMETER::clbkLoadVC(int id) { // Register Camera (view) properties switch (id) { case 0: // Left Seat SetCameraOffset(_V(0, .0, -.165)); // Set camera position (x,y,z) SetCameraDefaultDirection(_V(0, 0, 1)); oapiVCSetNeighbours(0, 1, -1, -1); // Set adjacent cameras (Left, Right, Top, Bottom) break; } // end "switc SURFHANDLE const tex3 = oapiGetTextureHandle(METNUMBERS, 1); oapiVCRegisterArea(AID_METTIME, _R(0, 0, 256, 256), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3); return true; }
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
So I set the mesh to be seen at all times.
I can write the MET on the texture. But got an issue. It writes on the background. I have 8 mesh parts with a white texture. When I tell it to draw on that texture nothing.
 
Top