Results 1 to 4 of 4

Thread: I want to make a circle

  1. #1
    Guest

    I want to make a circle

    i need to aproximate a circle with Ogl. and i need to draw it in any place of the screen without using the translatef command.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: I want to make a circle

    Well, you could use a for loop to generate your coordinates with sin and cos... Then you can simply provide the way you want to draw with glBegin( GL_LINE_STRIP ); or somtehing...

    So it could be like this:

    glBegin( GL_LINE_STRIP );

    for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )
    {
    x = cos(angle);
    y = sin(angle);

    glVertex3f( x, y , -1 ); // I dont know you coordinate system, so this -1 maybe wrong.
    }

    glEnd();


    This should give and idea... For a better approximation, you simply increment the angle by a smaller unit...
    I have not tested this 'cause i just worte it.
    I hope this helps.

  3. #3
    Member Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: I want to make a circle

    Originally posted by mancha:
    for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )
    It's better to use something like:

    angle+=2.f*PI/Segments

    This way all circle segments will be equal.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: I want to make a circle

    Also you need to have an offset varible, if you want to draw anywhere without glTranslate. I think you maybe having a problem a lot of people have using glTranslate and not also using glPop/push matrix with it, making things not translate the way you want.


    Here are a few things missing from mancha's example:

    ox, oy, oz = location of center of circle anywhere on screen.
    r = radius of circle.

    x = r * cos(angle);
    y = r * sin(angle);

    glVertex3f( ox - x, oy - y , oz ); // you may need to change ether ox or oy to plus instead of minus.

    Originally posted by mancha:
    Well, you could use a for loop to generate your coordinates with sin and cos... Then you can simply provide the way you want to draw with glBegin( GL_LINE_STRIP ); or somtehing...

    So it could be like this:

    glBegin( GL_LINE_STRIP );

    for( float angle = 0.0f; angle <= (2.0f*PI); angle += 0.1f )
    {
    x = cos(angle);
    y = sin(angle);

    glVertex3f( x, y , -1 ); // I dont know you coordinate system, so this -1 maybe wrong.
    }

    glEnd();


    This should give and idea... For a better approximation, you simply increment the angle by a smaller unit...
    I have not tested this 'cause i just worte it.
    I hope this helps.

Similar Threads

  1. Make object circle a world every Y seconds
    By xorserq in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-26-2014, 12:22 PM
  2. Make sphere move in a circle
    By uberweiss in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-21-2010, 12:07 AM
  3. Easy way to make a circle?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-12-2001, 05:40 PM
  4. How do you make a Circle?
    By CanEHdien in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-08-2001, 08:36 PM
  5. how to make a nurb circle or cylinder?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-24-2000, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean