-2

I have a problem with this :

"expected primary-expression before ‘/’ token"

Help me please Thanks

the error shows on : angle = i * 2.0f * PI / numSegments;

Here is my code:

void display() {
    glClear(GL_COLOR_BUFFER_BIT);  // Clear colour buffer
    glMatrixMode(GL_MODELVIEW);     // To operateon the model-view matrix
    glLoadIdentity();               // Reset model-view matrix

    glTranslatef(ballX, ballY, 0.0f);   //translate to (xPos, yPos)
    // use triangular segments to form a circle
    glBegin(GL_TRIANGLE_FAN);
    glColor3f(0.0f, 0.0f, 1.0f);    // Biru
    glVertex2f(0.0f, 0.0f);         // center of circle
    int numSegments = 100;
    GLfloat angle;
    for (int i = 0; i <= numSegments; i++) {    // last vertex same as first vertex
        angle = i * 2.0f * PI / numSegments;
        glVertex2f(cos(angle) * ballRadius, sin(angle) * ballRadius);
    }
    glEnd();

    glutSwapBuffers(); // Swap front and back buffers (of double buffered mode)

    // animation control - compute the location for the next refresh
    ballX += xSpeed;
    ballY += ySpeed;
    //Check if the ball exceeds the edges
    if (ballX > ballXMax) {
        ballX = ballXMax;
        xSpeed = -xSpeed;
    }
    else if(ballX < ballXMin) {
        ballX = ballXMin;
        xSpeed = -xSpeed;
    }
    if (ballY > ballYMax) {
        ballY = ballYMax;
        ySpeed = -ySpeed;
    }
    else if (ballY < ballYMin) {
        ballY = ballYMin;
        ySpeed = -ySpeed;
    }
}
NathanOliver
  • 171,901
  • 28
  • 288
  • 402

1 Answers1

4

Maddeningly, neither the C nor the C++ Standards define a value for pi, and the compiler error you're getting is entirely consistent with PI not being defined.

If you're not using Boost with C++, the easiest thing to do is to define PI yourself, to a very large number of decimal places in order to guard yourself against future precision changes in your types. In POSIX you could use M_PI, but then your code is not strictly portable.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483