Menu

counter variable

Dany
2010-05-20
2013-04-30
  • Dany

    Dany - 2010-05-20

    Hi, if I wanted to know the number of iterations required for separation of agents with identical features,
    where should I put a counter variable?  In the update method? In the class Boid or in the BoidPlugin?
    My plugin is very similar to Boid.

     
  • Craig Reynolds

    Craig Reynolds - 2010-05-20

    Hi.  The issue would be whether you want a single global counter or a counter for each boid/agent.  A global counter should probably be a member of the class like BoidPlugin, a per-Boid counter would be a member of the class like Boid.  Both would be incremented from the update method of the same class.

     
  • Dany

    Dany - 2010-05-21

    thanks for the advice. I put the counter variable inside the method upadate in BoidPlugin.

    void update (const float currentTime, const float elapsedTime)
    {
    // update flock simulation for each boid
    for (iterator i = flock.begin(); i != flock.end(); i++)
    {
    (**i).update (currentTime, elapsedTime);
            contatore++;
    }
    }

    When I pause the application with the space, the number of iterations continues to increase. Why?
    The counter variable must be inside the loop in the update method?

     
  • Craig Reynolds

    Craig Reynolds - 2010-05-21

    Ah, quite so!  The contatore-ing should only happen when not paused.  You could get the Clock object from OpenSteerDemo and call getPausedState(), but I think it would work just as well to increment the counter only when elapsedTime is not zero:

    if (elapsedTime > 0.0) contatore++;

    If you are trying to count "frames" (simulation steps) you want it outside the loop.  Inside the loop you are counting the total number of agent updates which is agents*frames.

     
  • Dany

    Dany - 2010-05-23

    I take the dot product of each agent with its neighbors. if I wanted to calculate the total number of iterations I put this counter outside the loop right?

     

Log in to post a comment.

MongoDB Logo MongoDB