Agents

Hi

I have a a screen 512x512 all contained in a lookup table so i am able to pin point any cell i want and assign a colour to it. What i need to do now is to be able to make these coloured squares move accross the screen following set rules. I am modelling salmon migration so the first objective is to get the salmon to ‘swim’ up the screen from their starting postion. The code i have to do what i have so far is;

#define checkImageWidth 512
#define checkImageHeight 512
GLubyte checkImage[checkImageHeight][checkImageWidth][3];

void makeCheckImage(void)
{
int i,j,r,g,b,x,y;

 for (i = 0; i< checkImageHeight; i++) {
 for (j = 0; j< checkImageWidth; j++) {

// r = j%4 * 255;
// r = i%255;
// g = j;
// b = 50;
checkImage[i][j][0] = (GLubyte) r;
checkImage[i][j][1] = (GLubyte) g;
checkImage[i][j][2] = (GLubyte) b;
}
}

int sea, fish, pred, nents;

sea = 0; fish = 1; pred = 2; nents = 3;

GLubyte lutr[nents], lutg[nents], lutb[nents];

lutr[sea] = 20;
lutg[sea] = 80;
lutb[sea] = 200;

lutr[fish] = 150;
lutg[fish] = 200;
lutb[fish] = 230;

lutr[pred] = 200;
lutg[pred] = 50;
lutb[pred] = 50;

for (y = 0; y < 512; y++) 
{
  for (x = 0; x < 512; x++) 
  {
    checkImage[y][x][0] = lutr[sea];
checkImage[y][x][1] = lutg[sea];
checkImage[y][x][2] = lutb[sea];
  }
}

for (y = 0; y < 110; y++) 
{
  for (x = 200; x < 310; x++) 
  {
    checkImage[y][x][0] = lutr[fish];
checkImage[y][x][1] = lutg[fish];
checkImage[y][x][2] = lutb[fish];
 }
}

for (y = 383; y < 433; y++) {
  for (x = 128; x < 178; x++) {
    checkImage[y][x][0] = lutr[pred];
checkImage[y][x][1] = lutg[pred];
checkImage[y][x][2] = lutb[pred];
 }
}

}

Do i use agents to do this? I want a ticker system that carries out a set of rules on each cell every tick. Does anyone have any idea on how to do this?

What do you mean when you say “agent” (Smith?) and “ticker system” (stockmarket ticker?)?

Any system that controls something else can be labeled an ‘agent’. It could be something as simple as “salmon.position.x++”, or as complex as the human brain. It all depends on what you want it to do. So, yes, you will need an ‘agent’, but that doesn’t really mean much

As for the ‘ticker system’, that also depends on what you want to do. Can this be done in fixed steps, or do you want real time action like a game? If you’re using glut, then check out glutTimerFunc() to have things occur at regular intervals, otherwise call glutGet(GLUT_ELAPSED_TIME) and act based on that.

That was the reason why I asked what he meant by saying so…

Originally posted by Honk:
That was the reason why I asked what he meant by saying so…

Yeah, but he probably wouldn’t ask if he needed an agent if he knew what one was

True

The reason I put ‘smith’ and ‘stockerticker’ into my question was to make clear that this discription is a bit vague and he should elaborate about it more detailed.

Maybe you could try a more game-like aproach? Like have each square have a vector defining its speed. Then every frame, knowing the speed, update the position and then re-draw the square in its new position. I’m not sure if this is what you want. To move the squares, it is a simple glTranslatef command if this is what you where asking for.

Originally posted by moucard:
Maybe you could try a more game-like aproach? Like have each square have a vector defining its speed. Then every frame, knowing the speed, update the position and then re-draw the square in its new position. I’m not sure if this is what you want. To move the squares, it is a simple glTranslatef command if this is what you where asking for.

Thanks so much this really helps a lot.

As u seem to have guessed i am only a begginner and trying to do something i dont really understand.

I basically want to perform a set of rules on every square in my lookup table over and over again. Depending on what inhabits that square depends on what rule will be followed. For example the Fish will follow a rule saying that 40% go North, 15% go East 15% go West 5% go South and 25% Remain.

I know im being a pain but could u give me an example on how to start this? Your concept of a game is right, it is a game really but i dont know how to use vectors. Someone has suggested that before and i think thats the way to go. By looking at the code i have so far can u see where i need to add the vectors?

Also very helpful!

Originally posted by hh10k:
As for the ‘ticker system’, that also depends on what you want to do. Can this be done in fixed steps, or do you want real time action like a game? If you’re using glut, then check out glutTimerFunc() to have things occur at regular intervals, otherwise call glutGet(GLUT_ELAPSED_TIME) and act based on that.

I need a series of operatations done on every cell in my grid done very quickly, do u know the basic structure of the code i would need to use to put this in my program?