Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
Created December 22, 2015 15:16
Show Gist options
  • Save yasuharu519/2d754559571a4101d0ad to your computer and use it in GitHub Desktop.
Save yasuharu519/2d754559571a4101d0ad to your computer and use it in GitHub Desktop.
void drawSector(cocos2d::DrawNode* node, cocos2d::Vec2 origin, float radius, float angle_degree,
cocos2d::Color4F fillColor, float borderWidth, cocos2d::Color4F bordercolor,
unsigned int num_of_points = 100)
{
if (!node)
{
return;
}
const cocos2d::Vec2 start = origin + cocos2d::Vec2{radius, 0};
const auto angle_step = 2 * M_PI * angle_degree / 360.f / num_of_points;
std::vector<cocos2d::Point> circle;
circle.emplace_back(origin);
for (int i = 0; i <= num_of_points; i++)
{
auto rads = angle_step * i;
auto x = origin.x + radius * cosf(rads);
auto y = origin.y + radius * sinf(rads);
circle.emplace_back(x, y);
}
node->drawPolygon(circle.data(), circle.size(), fillColor, borderWidth, bordercolor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment