Android OpenGL ES Line based circle -


can me logic of code? isn't drawing circle random lines.

#include <math.h> ... void drawcircle(){    glclear(gl_color_buffer_bit);    gluseprogram(programobject);    const float deg2rad = 3.14159f / 180.0f;    int totalvertices = 360;    const float radsperline = (360.f / totalvertices) * deg2rad;    float linevertices[(totalvertices * 4)];    int i;    int ii = 0;    float rad = 0.8f;    (i = 0; < (totalvertices); i++) {      float deginrad = radsperline * i;      float cosine = cos(deginrad);      float sine = sin(deginrad);      linevertices[ii++] = 0.0f;      linevertices[ii++] = 0.0f;      linevertices[ii++] = cosine * rad;      linevertices[ii++] = sine * rad;    }    glvertexattribpointer(0, 2, gl_float, gl_false, 0, linevertices);    glenablevertexattribarray(0);    gldrawarrays(gl_lines, 0, totalvertices * 4); } 

the fractalish pattern appears @ high number (such 360). other weird thing lines seem taller others strange well.

probably more useful able specify how many segments must approximate circle:

void fillwithcircledata(glfloat *linevertices, glint numlines, glfloat radius){     const glfloat deg2rad = 3.14159/180;     const glfloat radsperline = (360.f/(numlines)*deg2rad;     glint i;      (i=0; < numlines; ++i)     {         glfloat rads = radsperline*i;         linevertices[i*2] = cos(rads)*radius;              linevertices[i*2+1] = sin(rads)*radius;     } } 

be aware produces numlines vertices, won't repeat last vertex last vertex same first 1 (2pi == 0). means elements array must provide numlines+1 indexes, being last index same first one. saves processing same vertex twice. need change primitive gl_line gl_lines_strip.

edit: if don't want specify elements array, generate last point creating array hold numlines+1 , change above loop go until i < numlines+1.

note: code un-tested.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -