Reputation: 54103
Here is what I'm trying to do. I have a font that is basically bitmap rectangles for each glyph. I'm trying to get arced text effect like this:
My plan is, given a center and a radius, I'm going to solve for the position and angle of each glyph.
I have a function that can find the position:
Vec2 Math::positionFromCenterToLineAt( Vec2 center, float dist,
float totalAngular, float angularDistance, float angularOffset )
{
float startAngle = -((totalAngular) / 2.0f);
float curAngle = startAngle + angularDistance;
curAngle -= angularOffset;
curAngle += angularDistance / 2.0f;
curAngle += CGE_PI;
Vec2 retVec = center;
Vec2 angVec = Vec2(sin(curAngle),cos(curAngle));
angVec *= dist;
retVec += angVec;
return retVec;
}
It requires me to know how much of the circle will be occupied in radians, and requires how many degrees from the start angle the current glyph should be drawn at.
What I cannot figure out is a function to find the angle a given glyph will occupy given the radius, center, and width and height of the glyph. Each glyph can have a different dimension.
See this:
As you can see, I'm looking for in radians, that sector of the circle.
How could I calculate it?
Thanks
Upvotes: 2
Views: 357
Reputation: 11910
2*pi*radius equals the circumference
You know radius as a pixel base(lets say it is 40 pixels)
You can find circumference(lets say it is 251 pixels)
Then, if you get width of a char(lets say it is 8)
You know the angle of arc: angle=2*pi*(8/251)=2*pi*0.03=0.2 radians
0.2 radians * 57.3 = 11.5 degrees
How to find width of a char according to current font?
LOGFONT lf;
int width=lf.lfWidth; //beware! this is average
You want precise option?
GetTextExtentPoint32() // search usage of this!
Its structure type is:
BOOL GetTextExtentPoint32(
__in HDC hdc,
__in LPCTSTR lpString,
__in int c,
__out LPSIZE lpSize
);
Upvotes: 2