# Thread: How to resize and position a circle

1. ## 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. 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. Originally Posted by Carmine
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. Translate and Scale must come BEFORE glBegin.

5. #include <gl/gl.h>
#include <gl/glu.h>
#include <math.h>

void init()
{
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
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();
}
{
int i;
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);

for(i=0;i<360;i++)
{
}

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();