I drew a circle to represent a human face. I am drawing an arc to represent the mouth but I am having troubling positioning it in the right place. I have checked the value of x and y in the computation of the arc but can't seem to figure out what I am doing wrong or what I should be doing. I tried to redraw it again with other specifications but that is not working. glRotatef() and glTranslatef() doesn't seem to be helping that much either. Attached is a screen shot. The triangles represent the eyes but I'll worry about that later. I figured if I can understand how to position the arc right, I can do the same with the rest. Please help. It's a simple project and I need to turn it in today! Thanks.

#include <Windows.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>


GLsizei winWidth = 600, winHeight = 600;
const float PI = 3.14159265;
const float Angle = 45;



void init(void)
{
    glClearColor (0.0, 0.0, 1.0, 0.0);
    glMatrixMode (GL_PROJECTION);
    gluOrtho2D (0.0, winWidth, 0.0, winHeight);
    glShadeModel (GL_SMOOTH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}


void triangles1()
{
    glBegin( GL_TRIANGLES);
    glColor3f(1.0, 0.0, 0.0);  
    glVertex2i(-25, 50);
    glVertex2i(50, 75);
    glVertex2i(20, 50);
    glEnd();

}

void drawTriangle()
{

    glPushMatrix();
    glTranslatef(160, 160, 0);
    glTranslatef(100, 10, 0); 
    glRotatef(Angle, 0, 0, 0);
//glScalef(1, 1, 1);
   glClear(GL_COLOR_BUFFER_BIT);

   glBegin( GL_TRIANGLES);
    glColor3f(1.0, 0.0, 0.0);  
    glVertex2i(100, 500);
    glVertex2i(0, 666);
    glVertex2i(200, 666);
   glEnd();


   glBegin( GL_TRIANGLES);
    glColor3f(1.0, 0.0, 0.0);  
    glVertex2i(600, 650);
    glVertex2i(450, 750);
    glVertex2i(300, 650);
   glEnd();

   glPopMatrix();
}



void circle(GLint x, GLint y, GLint radius)
{
    float angle;

        glTranslatef(170, 100, 0.0);
    glTranslatef(0.0,70, 1.0);

    glColor3f(0.0f, 1.0f, 0.0f);
    glBegin(GL_LINE_LOOP);
    for (int i = 0; i < 100; i++)
    {
        angle = i*2*PI/100;
        float X = x + (cos(angle) * radius);
        float Y = y + (sin(angle) * radius);
        glVertex2f(X, Y);
        //glVertex2f(x + (cos(angle) * radius), y + (sin(angle) * radius));
    }
    glEnd();

}



void drawArc(float x, float y, float r, float t0, float sweep)
{

    float t, dt; /* angle */
    int n = 100; /* # of segments */
    int i;

    t = t0 * PI/270.0; /* radians */
    dt = sweep * PI/(270*n); /* increment */

    glLoadIdentity(); 

    glTranslatef(50, 150, 0);
    glTranslatef(200, 50, 0);
    glRotatef(60, 0, 0, 0);

    glBegin(GL_LINE_STRIP);
    glColor3f(0.0, 1.0, 0.0);

    for(i=0; i<=n; i++, t += dt)
    glVertex2f(x + r*cos(t), y + r*sin(t));

    glEnd();
}



void display(void)
{

    glPushMatrix();
    glTranslatef(100, 100, 0);

   glClear(GL_COLOR_BUFFER_BIT);  
   /*   glPushMatrix();
    glTranslatef(100, 100, 0);
    glRotatef(100, 100, 100, 100);*/


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, 0.0);
    glRotatef(Angle, 0.0, 0.0, 0.0);

    drawTriangle();
    circle (250, 250, 350);
    drawArc(-50, 50, -180, -180, 180);




  glFlush();  /* Single buffered, so needs a flush. */
}



void reshape (int w, int h)
{
     glViewport(0, 0, (GLsizei) w, (GLsizei) h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluPerspective(-60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
     glMatrixMode(GL_MODELVIEW);

}



int main (int argc, char** argv)
{
    glutInit (&argc, argv);                         // Initialize GLUT
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition (100, 100);              
    glutInitWindowSize (winWidth, winHeight);       // Set the initial Window's width and height
    glutCreateWindow ("Facial Expression Program");// Create window with the given title

    init();                         // Our own OpenGL initialization
    glutDisplayFunc (display);      // Register callback handler for window re-paint event
    //glutReshapeFunc(reshape);
    glutMainLoop ( );                // Enter infinitely event-processing loop
}

Edited 3 Years Ago by Dani: Formatting fixed

Your problem is the factor PI/270.0 which you use to transform degrees into radians. It is wrong, to convert degrees into radians, you need to use the factor PI/180.0 . This explains why your arc is only 2/3 of the angular sweep that it should have (i.e. 120 degrees instead of 180 degrees).

Also, note that lines like glRotatef(60.0, 0, 0, 0); are completely useless. The glRotate function works by giving an angle (in radians, btw) and then the three components of the axis of rotation around which to perform the rotation (that's the last three numbers). If all the last three values are zero, then you won't get any rotation at all. So, lines like these have no effect at all.

Edited 5 Years Ago by mike_2000_17: n/a

Thank you so much. I've been trying to figure this out for days. I made the changes you suggested and it worked. Thank you again.

This question has already been answered. Start a new discussion instead.