当前位置:编程学习 > wap >>

cocos2d-iphone画椭圆

 
添加到cocos2d下的CCDrawingPrimitives.h文件
 
[cpp] 
void ccDrawEllipse(CGPoint center, float rx, float ry, float a, int segs, BOOL drawLineToCenter);  
 
 
 
 
添加到cocos2d下的CCDrawingPrimitives.m文件
 
[cpp]  
void ccDrawEllipse(CGPoint center,float rx, float ry,float a, int segs,BOOL drawLineToCenter)  
{  
    lazy_init();  
      
   int additionalSegment = 1;  
   if (drawLineToCenter)  
        additionalSegment++;  
      
   const float coef =2.0f * (float)M_PI / segs;  
      
   GLfloat *vertices = calloc( sizeof(GLfloat)*2*(segs+2),1);  
   if(!vertices)  
       return;  
      
   float rads, distance, angle, j, k;  
   for(NSUInteger i =0; i <= segs; ++i)  
    {  
        rads = i * coef;  
        distance =sqrt(pow(sinf(rads) * rx,2) + pow(cosf(rads) * ry,2));  
        angle =atan2(sinf(rads) * rx,cosf(rads) * ry);  
        j = distance *cosf(angle + a) + center.x;  
        k = distance *sinf(angle + a) + center.y;  
          
        vertices[i*2] = j;  
        vertices[i*2+1] = k;  
    }  
    vertices[(segs+1)*2] = center.x;  
    vertices[(segs+1)*2+1] = center.y;  
  
    [shader_use];  www.zzzyk.com
[shader_setUniformsForBuiltins];  
[shader_setUniformLocation:colorLocation_with4fv:(GLfloat*) &color_.rcount:1];  
      
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position );  
      
glVertexAttribPointer(kCCVertexAttrib_Position,2, GL_FLOAT,GL_FALSE, 0, vertices);  
glDrawArrays(GL_LINE_STRIP,0, (GLsizei) segs+additionalSegment);  
      
free( vertices );  
CC_INCREMENT_GL_DRAWS(1);  
}  
 
补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,