ios - Draw circle arc with GL_TRIANGLE_STRIP -


i trying write method draw arc start angle end angle using gl_triangle_strip. i've written following code have following problems:

  1. i can't seem proper angles working. seem offset should odd amount (not 90/45/180).
  2. if total angle between 2 more 180 degrees arc draw smaller angle on circle between two. i.e if total angle 200 degrees draw arc 160 degrees on other part of circle.

i've spent way time trying right , figured helpful have pair of eyes looking @ code. image below shows triangle strips trying create between angles. i'll applying texture after figure part out. help!

triangle strips

-(void) drawarcfrom:(cgfloat)startangle to:(cgfloat)endangle position:(cgfloat)position radius:(cgpoint)radius {      cgfloat segmentwidth = 10.0;     cgfloat increment = fabsf(endangle - startangle) / segmentwidth;     int numsegs = fabsf(endangle - startangle) / segmentwidth;     int direction = (endangle - startangle > 0) ? 1 : -1;      ccvertex2f vertices[numsegs * 2];      (int = 0; < numsegs; i++) {         cgfloat angle = startangle - (i * increment * direction);         cgpoint outsidepoint = ccpadd(position, ccp(sinf(cc_degrees_to_radians(angle)) * (radius + 4), cosf(cc_degrees_to_radians(angle)) * (radius + 4)));         cgpoint insidepoint = ccpadd(position, ccp(sinf(cc_degrees_to_radians(angle)) * (radius - 4), cosf(cc_degrees_to_radians(angle)) * (radius - 4)));          vertices[i * 2] = (ccvertex2f) {outsidepoint.x, outsidepoint.y };         vertices[i * 2 + 1] = (ccvertex2f) {insidepoint.x, insidepoint.y };     }      glvertexpointer(2, gl_float, 0, vertices);     gldrawarrays(gl_triangle_strip, 0, (glsizei) numsegs * 2);  } 

my code android full circle. segments = 20; coords [x,y,z]

    float w2 = width / 2f;     float h2 = height / 2f;      double radius = math.min(w2, h2);     double pi2 = math.pi * 2d;     coords = new float[segments * 2 * 3];     double angle;     int index = 0;     double min_radius = radius - circle_width;     double max_radius = radius + circle_width;     (int = 0; < segments; i++, index += 6) {         angle = (pi2 * (double) i) / (double) (segments - 1);         double sin_angle = math.sin(angle);         double cos_angle = math.cos(angle);         coords[index + 0] = (float) (cos_angle * max_radius);         coords[index + 1] = (float) (sin_angle * max_radius);         coords[index + 2] = 0f;         coords[index + 3] = (float) (cos_angle * min_radius);         coords[index + 4] = (float) (sin_angle * min_radius);         coords[index + 5] = 0f;     } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -