Using GLUT for a science project

Member
Posts: 61
Joined: 2007.01
Post: #1
Hi,

I'm having some trouble trying to work out how to display a simulation run at each step using GLUT.

I'm trying to evolve a neural network that will guide a bot towards a target.

I've tried to put my simulation code within the display function but that runs through the simulation and does not display the world until the _end_ of the simulation.

My simulation loop is like this

Code:
for (i = 0; i < EXPERIMENT_LOOPS; i++)
{
    for (j = 0; j < TRIAL_LOOPS; j++)
    {
         for (k = 0; k < NUM_BOTS; k++)
         {
              pass world info to bot[k]'s neural network
              update bot[k] position based on neural network's output
             [b][i]I'd like to then draw the bot[k] at new position[/i][/b]
         }
    }
  
    // trial run is over
    run the genetic algorithm
   // reset loop counter
   j = 0

}

Actually, I guess this is an animation problem. At the moment I've been starting at this neural network code for ages and my brain is a bit fried. So may be it's something very simple that I'm missing Wacko

Thanks in advance for any help!

Anthony
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You should structure your code like this:

Code:
int experimentCounter = 0;
int trialCounter = 0;
void idle(void) { glutPostRedisplay(); }
void display(void) {
    /* update bots, draw them */
    glutSwapBuffers();
    ++trialCounter;
    if (trialCounter == TRIAL_LOOPS) {
        trialCounter = 0;
        ++experimentCounter;
    }
}

Use glutIdleFunc to set idle as your idle function.
Quote this message in a reply
Member
Posts: 61
Joined: 2007.01
Post: #3
OneSadCookie thanks a million! :]
Quote this message in a reply
nikomaster
Unregistered
 
Post: #4
If you want an evolving Neural Network you may use the ART Neural Network, find the algorithm and implement it into your code.
Quote this message in a reply
Post Reply