Merge pull request #3056 from DarraghCoy/cc_draw_solid_circle

Add ccDrawSolidCircle
This commit is contained in:
minggo 2013-07-03 00:24:20 -07:00
commit 34d4594df3
3 changed files with 57 additions and 0 deletions

View File

@ -383,6 +383,52 @@ void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsign
ccDrawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f);
}
void ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY)
{
lazy_init();
const float coef = 2.0f * (float)M_PI/segments;
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
if( ! vertices )
return;
for(unsigned int i = 0;i <= segments; i++) {
float rads = i*coef;
GLfloat j = radius * cosf(rads + angle) * scaleX + center.x;
GLfloat k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i*2] = j;
vertices[i*2+1] = k;
}
vertices[(segments+1)*2] = center.x;
vertices[(segments+1)*2+1] = center.y;
s_pShader->use();
s_pShader->setUniformsForBuiltins();
s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);
ccGLEnableVertexAttribs( kVertexAttribFlag_Position );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, sizeof(GLfloat)*2*(segments+2));
glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segments+1);
free( vertices );
CC_INCREMENT_GL_DRAWS(1);
}
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments)
{
ccDrawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f);
}
void ccDrawQuadBezier(const Point& origin, const Point& control, const Point& destination, unsigned int segments)
{
lazy_init();

View File

@ -113,6 +113,10 @@ void CC_DLL ccDrawSolidPoly( const Point *poli, unsigned int numberOfPoints, ccC
void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
void CC_DLL ccDrawCircle( const Point& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
/** draws a solid circle given the center, radius and number of segments. */
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
void CC_DLL ccDrawSolidCircle( const Point& center, float radius, float angle, unsigned int segments);
/** draws a quad bezier path
@warning This function could be pretty slow. Use it only for debugging purposes.
@since v0.8

View File

@ -172,6 +172,13 @@ void DrawPrimitivesTest::draw()
CHECK_GL_ERROR_DEBUG();
// draw a pink solid circle with 50 segments
glLineWidth(2);
ccDrawColor4B(255, 0, 255, 255);
ccDrawSolidCircle( VisibleRect::center() + ccp(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f);
CHECK_GL_ERROR_DEBUG();
// open yellow poly
ccDrawColor4B(255, 255, 0, 255);
glLineWidth(10);