Created
December 22, 2015 15:16
-
-
Save yasuharu519/2d754559571a4101d0ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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