Oct 14, 2011 at 3:55pm UTC
I can't really see anything wrong in the posted code.
Are you sure they just look as one, rather than actually just being one due to faulty initialization?
Oct 14, 2011 at 4:05pm UTC
I don't see anything wrong here too. Do you think creature::draw() uses x_pos/y_pos that are motified by creature::move()?
Oct 14, 2011 at 4:29pm UTC
This is the draw function member:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void creature::draw(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(x_pos,y_pos,z_pos);
glColor3f(r,g,b);
glBegin(GL_QUADS);
glVertex3f(-maxCellSize, maxCellSize, 0.0f);
glVertex3f( maxCellSize, maxCellSize, 0.0f);
glVertex3f( maxCellSize,-maxCellSize, 0.0f);
glVertex3f(-maxCellSize,-maxCellSize, 0.0f);
glEnd();
}
And this is the init():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
void creature::init(void )
{
state=ALIVE;
foodTactics=CARBEATER;
age=0;
mode=MOVE;
spiecementId=1;
evolutionSteps=0;
r=0.0f; g=1.0f; b=0.0f;
energy=10000;
life=5000;
scope=10;
strength=10;
speed=0.05f;
maxCellSize=0.1f;
x_pos=0.0f; y_pos=0.0f, z_pos=-50.0f;
}
Last edited on Oct 14, 2011 at 4:33pm UTC
Oct 14, 2011 at 4:38pm UTC
Ah, at last I found it my self. Thank you Gaminic and EricDu for asking the right questions.
The glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); statement should be moved out of creatur::draw(), and into main() !!!
Last edited on Oct 14, 2011 at 4:40pm UTC
Oct 14, 2011 at 4:38pm UTC
sorry, I am really not familiar with GL interfaces. How about try this way, print out x/y values in move(), then we know if it's rand() issue.
Oct 14, 2011 at 4:48pm UTC
It was apparently not a rand() problem. I was sure it was - so I was looking at the same code over and over ... again thanks. :-)