F
F
Flaker2013-12-25 18:13:42
C++ / C#
Flaker, 2013-12-25 18:13:42

(C++, GLUT) Drawing a circle. What's causing the discrepancy between radius and position?

I use GLUT to draw 2D graphics.
I draw a circle:

double _tmpPoint;
    glBegin(GL_TRIANGLE_FAN);
    glVertex2f(posX, posY);
    for( int i = 0; i <= radius; i++ ) 
    {
      _tmpPoint = (float)i / radius * 3.1415f * 2.0f;
      glVertex2f(posX + cos(_tmpPoint) * (radius / 10), 
        posY + sin(_tmpPoint) * (radius / 10));
    }
    glEnd();

Actually, the circle is drawn as it should, but when I set the position x=radius and y=radius , the circle is set to a position equal to 10 radii.
Roughly speaking:
// Устанавливается не так, как надо
Ball->setPosition(Ball->getRadius(), Ball->getRadius());

//Устанавливается верно:
Ball->setPosition(Ball->getRadius() / 10, Ball->getRadius() / 10);

The rest of the objects (rectangles) are rendered normally.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2013-12-25
@Flaker

glVertex2f(posX + cos(_tmpPoint) * (radius / 10), 
                posY + sin(_tmpPoint) * (radius / 10));

In your calculation of coordinates, not the radius itself is used, but the radius divided by 10.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question