Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: How to resize and position a circle

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    4

    How to resize and position a circle

    Hi new to OpenGL, my question is how to resize and position a circle object, ive created a door(a rectangle) and need a circle to be a door knob. Below is the code i found online to make a circle and im not familiar to what the code is doing can someone please assist me to goal is the have to knob place in the middle far left side. thank you!

    //DOOR KNOB
    glBegin(GL_TRIANGLE_FAN);
    glColor3f(SkyBlue);
    for (int i = 0; i <= 180; i++){
    double angle = 2* M_PI * i / 180;
    double x = cos(angle);
    double y = sin(angle);
    glVertex3d(x, y, -0.5);
    }
    glEnd();

    //DOOR side - FRONT Rectangle
    glBegin(GL_POLYGON);
    glColor3f(White);
    glVertex3f(0.1, -0.5, -0.5); // P1 Bottom Right
    glVertex3f(0.1, -0.1, -0.5); // P2 Top Right
    glVertex3f(-0.1, -0.1, -0.5); // P3 Top left
    glVertex3f(-0.1, -0.5, -0.5); // P4 Bottom Left
    glEnd();

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    188
    You say you've 'created a door'. Does that mean you see the rectangle when you run the code? Do you seen any part of the circle? Generally speaking, use glScalef to resize things and glTranslatef to move things.

  3. #3
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    4
    Quote Originally Posted by Carmine View Post
    You say you've 'created a door'. Does that mean you see the rectangle when you run the code? Do you seen any part of the circle? Generally speaking, use glScalef to resize things and glTranslatef to move things.
    I tried adding the following code but its doesn't really work. I see the white door and then i see the circle ahead of the door.

    //DOOR KNOB
    glBegin(GL_TRIANGLE_FAN);
    glColor3f(SkyBlue);
    for (int i = 0; i <= 300; i++){
    double angle = 2* M_PI * i / 300;
    double x = cos(angle);
    double y = sin(angle);
    glVertex3d(x, y, -0.5);
    }
    glTranslatef(-0.2, -0.2, -0.5);
    glScalef(0.5, 0.5, 0.5);
    glEnd();

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    188
    Translate and Scale must come BEFORE glBegin.

  5. #5
    Newbie Newbie
    Join Date
    Jul 2014
    Posts
    1
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <math.h>
    #define DEG2RAD 3.14159/180.0
    void circl(float radiusX,float radiusY);

    void init()
    {
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(1.0,0.0,0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-10.0,10.0,-10.0,10.0,-10.0,10.0);//change diff values here to position
    //glViewport(0, 0,100,100);
    }
    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT);

    circl(2.0,2.0);
    glEnd();
    glFlush();
    }
    void circl(float radiusX,float radiusY)
    {
    int i;
    glColor3f(1.0,0.0,0.0);
    glBegin(GL_LINE_LOOP);

    for(i=0;i<360;i++)
    {
    float rad = i*DEG2RAD;
    glVertex2f(cos(rad)*radiusX,sin(rad)*radiusY);
    }

    glEnd();
    }
    void main( int argc, char **argv )
    {
    glutInit( &argc, argv );
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize( 800, 800 );
    glutInitWindowPosition(100,100);

    glutCreateWindow("cool");
    glutDisplayFunc(display);
    init();
    glutMainLoop();

    } //Anuroop,kongad,pkd
    Last edited by dewdrops39; 07-12-2014 at 10:02 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
  •