Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: OpenGL Android
Can anyone help me how to draw a circle similar to one in the image, such that M is greater than N using open gl v1.5 for android
 
[IMG]http://i49.tinypic.com/254y5bs.png[/IMG]
Posted 7-Jul-12 0:37am
Comments
Sandeep Mewara at 7-Jul-12 6:05am
   
What have you tried so far?
Amarnath S at 7-Jul-12 9:37am
   
Though I can't tell you the exact function names in OpenGL, there are basically two functions you'll have to use:
1. Line function (two calls) - to draw two radial lines shown in your figure
2. Arc function - to draw the circular arc in your figure.
 
One thing still needs clarification - You mention that M is greater than N - this means that their meeting point is not at the centre of the arc. Have you got a mathematical formula for that point?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Lots of suggestions easy to find[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please try this...
 
    int RADIUS = 2;
    float DEGREE_TO_RAD = 3.14 / 180;
    glBegin( GL_LINE_LOOP );
    glVertex2f( 0,0 );
    int M_IN_DEGREE = 370;
    int N_IN_DEGREE = 100;
    for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
    {
        float fX = sin((float)nR * DEGREE_TO_RAD ) ;
        float fY = cos((float)nR * DEGREE_TO_RAD );
        glVertex2f( fX, fY );
    }
    glEnd();
 
With glDrawArrays
int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float stVertexArray[2*360];
 
stVertexArray[0] = 0.0;
stVertexArray[1] = 0.0;
 
for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
    float fX = sin((float)nR * DEGREE_TO_RAD ) ;
    float fY = cos((float)nR * DEGREE_TO_RAD );
    stVertexArray[nCount*2] = fX;
    stVertexArray[nCount*2 + 1] = fY;
    nCount++;
}
 
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, stVertexArray );
glDrawArrays( GL_LINE_LOOP, 0, nCount );
  Permalink  
v2
Comments
monerajesh at 10-Jul-12 9:34am
   
hi, I cant use the glBegin and glEnd in my code..I draw to the surface view using gl.glDrawArrays and use gl. in every line to usea property in the onDrawFrame(GL10 gl) method..please guide me as to how to draw using the code you gave..I am a beginner in openGL..help is appreciated.
Santhosh_G at 10-Jul-12 12:48pm
   
Please prepare vertex buffer with fX and fY values, and call it with glDrawArrays. Please try the following code..
 

int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float stVertexArray[2*360];
 
stVertexArray[0] = 0.0;
stVertexArray[1] = 0.0;
 
for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = sin((float)nR * DEGREE_TO_RAD ) ;
float fY = cos((float)nR * DEGREE_TO_RAD );
stVertexArray[nCount*2] = fX;
stVertexArray[nCount*2 + 1] = fY;
nCount++;
}
 
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, 0, stVertexArray );
glDrawArrays( GL_LINE_LOOP, 0, nCount );
monerajesh at 15-Jul-12 16:39pm
   
this is how I implemented your code..but the result is a light green colored screen with no circle
int M_IN_DEGREE = 370;
int N_IN_DEGREE = 100;
int nCount = 1;
float[] stVertexArray=new float[2*360];
FloatBuffer sampleBuffer;
 
stVertexArray[0] = (float) 0.0;
stVertexArray[1] = (float) 0.0;
 
for( int nR =N_IN_DEGREE; nR < M_IN_DEGREE; nR++ )
{
float fX = (float) Math.sin((float)nR * (45*(Math.PI/180)) ) ;
float fY = (float)Math.cos((float)nR * (45*(Math.PI/180)) ) ;
stVertexArray[nCount*2] = fX;
stVertexArray[nCount*2 + 1] = fY;
nCount++;
}
ByteBuffer bBuff = ByteBuffer.allocateDirect(stVertexArray.length * 4);
bBuff.order(ByteOrder.nativeOrder());
sampleBuffer = bBuff.asFloatBuffer();
sampleBuffer.put(stVertexArray);
sampleBuffer.position(0);
 
gl.glEnableClientState( GL10.GL_VERTEX_ARRAY );
gl.glVertexPointer( 2, GL10.GL_FLOAT, 0, sampleBuffer );
gl.glDrawArrays( GL10.GL_LINE_LOOP, 0, nCount );

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 PIEBALDconsult 110
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 10 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100