Hello I am trying to draw a bar which has curves on its either side but the curves are seem imperfect. Can anyone help me on the following code?
barValue gives the amount of value the bar should have with respect to the width.
the Bar should not be drawn fully but upto the value of barValue.
The posinfo contains the coordinates of the line to be drawn.
The drawTexture draws on to the screen take the line texture address, posinfo address and color addres.
Code:
define LINE_WIDTH 0.5f
void drawHUDBar(int texNum,float X,float Y,float width,float height,float barValue)
{
float newYScale=0.0f;
float radius=height/2.0f;
float l;
for ( l=0.0f;l<=barValue;l=l+LINE_WIDTH)
{
if (l<=radius)
{
newYScale=sqrtf(radius*radius-(radius-l)*(radius-l));
posInfo.x1=X+l;
posInfo.y1=Y+radius-newYScale;
posInfo.x2=posInfo.x1+LINE_WIDTH;
posInfo.y2=Y+radius+newYScale;
drawTexture(&texturePtr,&posInfo,&default_color);
}
else if (l<(width-radius))
{
posInfo.x1=X+radius;
posInfo.y1=Y;
if (barValue<=(width-radius)) posInfo.x2=posInfo.x1+barValue-radius;
else posInfo.x2=posInfo.x1+width-2*radius;
posInfo.y2=Y+2*radius;
drawTexture(&texturePtr,&posInfo,&default_color);
l=width-radius-LINE_WIDTH;
}
else if (l>=(width-radius))
{
newYScale=sqrtf(radius*radius-(radius-width+l)*(radius-width+l));
posInfo.x1=X+l;
posInfo.y1=Y+radius-newYScale;
posInfo.x2=posInfo.x1+LINE_WIDTH;
posInfo.y2=Y+radius+newYScale;
drawTexture(&texturePtr,&posInfo,&default_color);
}
}
}
If there is better or faster algorithm please do post