question

Visakh Sakulan avatar image
2 Likes"
Visakh Sakulan asked Matt Long answered

change color of the fluid level display

fluid.fsmfluid.png

I want to change the initial color of the fluid level display to white from the grey color(not the fluid color, which is green), is there a way to do that?

FlexSim 16.0.1
visualcolor changefluid object
fluid.png (204.2 KiB)
fluid.fsm (14.5 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matt Long avatar image
4 Likes"
Matt Long answered

Unfortunately the Fluid Level Display bar is hard coded to the grey color. However, by copying the draw code from the fluid object in the library, you can customize the color. Either place the following code directly in the On Draw Trigger of your object or create a User Command and call that from multiple objects. Be sure to return 1 at the end as this will cause the object to not draw its default level display.

fglPushMatrix();
glPushAttrib(GL_ENABLE_BIT);
fglDisable(GL_TEXTURE_2D);


double percentfull = 0;
if (getvarnum(current, "maxcontent") > 0)
	percentfull = getvarnum(current, "curcontent") / getvarnum(current, "maxcontent");
double red = getcolorcomponent(current, 1);
double green = getcolorcomponent(current, 2);
double blue = getcolorcomponent(current, 3);


double xlen = xsize(current) * getvarnum(current, "barsizex");
double ylen = ysize(current) * getvarnum(current, "barsizey");
double zlen = zsize(current) * getvarnum(current, "barsizez");
double barlen = zlen * percentfull;


// Scale the world to model space
fglScale(1 / xsize(current), 1 / ysize(current), 1 / zsize(current));


spacetranslate(getvarnum(current, "barlocx") * xsize(current), -getvarnum(current, "barlocz") * zsize(current), -getvarnum(current, "barlocy") * ysize(current));
spacerotate(getvarnum(current, "barrotx"), getvarnum(current, "barrotz"), getvarnum(current, "barroty"));


drawcube(0, 0, 0, xlen, ylen, barlen, 0, 0, 0, red, green, blue);
spacetranslate(0, 0, barlen);
drawcube(0, 0, 0, xlen, ylen, zlen - barlen, 0, 0, 0, 255, 255, 255); //Change the last three components to your desired RGB color
glPopAttrib();
fglPopMatrix();


return 1;
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.