Walking movement

hello I am new to opengl/glut and I think I am still using version 1.1 with visual studio 2013 C++
the problem I am having is that I cannot make the arm rotate back and forth with IdleFunc, I have tried glutTimerFunc but that is not really practice for what I intend to do.

In the reverse () function I need an alternative to the “else” statement


#include "stdafx.h"
#include "GL\glut.h"
#include <iostream>
GLdouble angle_1 = 0, angle_2 = 0;
static GLdouble sentinel = 0;

void reverse()
{
    if (angle_1 < 26 )// ||angle_2>-25)
    {
       angle_1 +=.01;
       angle_2-=.01;
    }
    else
    {
        angle_1 = .0;
        angle_2 = .0;
    }

    glutPostRedisplay();
}




void keyFunc(unsigned char key, int i, int u)
{
    switch (key)
    {
    case'l':
        glutIdleFunc(reverse);
        sentinel = 1;
        break;

    case'r':
        glutIdleFunc(NULL);
        break;
    }

}

void legs()
{
    glPushMatrix();
    glScaled(3, 2, 1);
    glutWireCube(1);

    //////////////////////////////////////////first joint
    glPushMatrix();
    glRotated(angle_1, 1, 0, 0);
    //glTranslated(0, 0, angle_1);
    glTranslated(1, 0, 0);
    glScaled(.5, 2, 1);
    glutWireCube(1);

    ////////////////leg
    glPushMatrix();
    glTranslated(0, -1, 0);
    
    glScaled(.5, 2, 1);
    glutWireCube(1);
    glPopMatrix();


    glPopMatrix();



    //////////////////////////////////////////first joint
    glPushMatrix();
    glRotated(angle_2, 1, 0, 0);
    glTranslated(-1, 0, 0);
    glScaled(.5, 2, 1);
    glutWireCube(1);

    ////////////////leg
    glPushMatrix();
    glTranslated(0, -1, 0);
    glScaled(.5, 2, 1);
    
    glutWireCube(1);
    glPopMatrix();

    glPopMatrix();



    glPopMatrix();
}

void general()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0, 0.5, 0, 0);
}

void reshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65, w / h, 1, 150);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(10, 10, 20, 0, 0, 0, 0, 1, 0);
}

void display()
{
    general();
    glPushMatrix();
    glRotated(95, 0, 1, 0);
    legs();
    glPopMatrix();
    glutSwapBuffers();
}

int _tmain(int argc, _TCHAR* argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(600, 600);
    glutCreateWindow("wind");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyFunc);
    //glutMouseFunc(mouse_Click);
    glutMainLoop();
    return 0;
}

if anyone could give me an idea on how to correct the code it will be really appreciated here is the copy of the code

What does your code do so far? Does it compile and run? What happens when you run it?
Are you getting any animation? If you want more people to help you, it would help if you
answer these questions.

It’s good that you posted code because it shows you’ve done some work.
It would far better if the code was posted within [ code] and [ /code] tags
and was indented for clarity. An example of this is in this post.

[QUOTE=Carmine;1281575]What does your code do so far? Does it compile and run? What happens when you run it?
Are you getting any animation? If you want more people to help you, it would help if you
answer these questions.

It’s good that you posted code because it shows you’ve done some work.
It would far better if the code was posted within [ code] and [ /code] tags
and was indented for clarity. An example of this is in this post.[/QUOTE]

Yes the code compile and run perfectly fine, the thing I am trying to do is to capture leg movement, however; as soon as it take the first step there will be no more movement; I try looking online for simple source code of “walking man” but I could not that I could learn from.

so to sum it up the code is suppose to represent legs motion back and forth. but if you have code for a “walking man” I will take that

[QUOTE=afrochan;1281578]Yes the code compile and run perfectly fine, the thing I am trying to do is to capture leg movement, however; as soon as it take the first step there will be no more movement; I try looking online for simple source code of “walking man” but I could not that I could learn from.

so to sum it up the code is suppose to represent legs motion back and forth. but if you have code for a “walking man” I will take that[/QUOTE]

One more thing if you try to run the program and it is not working
you have to right click the project, go to property, change “unicode character set” to “not set”

next got to “manage nuget” go to search type “glut” and install “nupengl core”

and add the heading “gl/glut”

after that it should work just fine

… it should work just fine
I’ll give it a try.

I was able to compile and run your program. An easy fix would be to replace your reverse() routine with the one below.
Note that I changed your angle increment from 0.01 to 0.5 to make the legs move faster.


void reverse ()
{
    static float delang = 0.5;

    if (fabs(angle_1) > 26.0)  delang *= -1.0;

    angle_1 += delang;
    angle_2 -= delang;

    glutPostRedisplay();
}

[QUOTE=Carmine;1281582]I was able to compile and run your program. An easy fix would be to replace your reverse() routine with the one below.
Note that I changed your angle increment from 0.01 to 0.5 to make the legs move faster.


void reverse ()
{
    static float delang = 0.5;

    if (fabs(angle_1) > 26.0)  delang *= -1.0;

    angle_1 += delang;
    angle_2 -= delang;

   glutPostRedisplay();
}

[/QUOTE]

thank alot, it is a little fast but I guess I will find a way to slow it down, Could you explain to me the principal behind the math. that will help me a lot

it is a little fast but I guess I will find a way to slow it down

Change the value of delang to control the speed of the animation.
delang = 0.1 would make it run 1/5 as fast as my version runs.
delang = 0.01 would make it run at your original speed.

Could you explain to me the principal behind the math. that will help me a lot

Print out the values of delang, angle_1, and fabs(angle_1) to get a feel for what’s going on.

[QUOTE=Carmine;1281584]Change the value of delang to control the speed of the animation.
delang = 0.1 would make it run 1/5 as fast as my version runs.
delang = 0.01 would make it run at your original speed.

Print out the values of delang, angle_1, and fabs(angle_1) to get a feel for what’s going on.[/QUOTE]

Thank a bunch it work just fine now