//I need to say, the code is quick and dirty ... thats only for playing
//The mother in this case is a point, who moves on x, y, and z-achsis
//like a ping/pong (Think at mystify in 2D, but here in 3D)
//In every pass of the infinity-loop, the mother ist on the next step and
//150 of this childfishes follow the mother
//the length of the traces are 300
void CChildFish::Paint(CCoord mother)
{
//This is the calculting of the mov of the childfish
//with acceleration und velocity fpr smoothed moves
//every fish has another accelertation an max-velocity
//so the fishswarm-move ist realy naturell
//you see, there are many many lines in every way
if(mother.GetX() > m_Coord[pos].GetX())
{
m_VX += m_A;
if(m_VX > m_MaxV)
{
m_VX = m_MaxV;
}
}
else if(mother.GetX() < m_Coord[pos].GetX())
{
m_VX -= m_A;
if(m_VX < -m_MaxV)
{
m_VX = -m_MaxV;
}
}
if(mother.GetY() > m_Coord[pos].GetY())
{
m_VY += m_A;
if(m_VY > m_MaxV)
{
m_VY = m_MaxV;
}
}
else if(mother.GetY() < m_Coord[pos].GetY())
{
m_VY -= m_A;
if(m_VY < -m_MaxV)
{
m_VY = -m_MaxV;
}
}
if(mother.GetZ() > m_Coord[pos].GetZ())
{
m_VZ += m_A;
if(m_VZ > m_MaxV)
{
m_VZ = m_MaxV;
}
}
else if(mother.GetZ() < m_Coord[pos].GetZ())
{
m_VZ -= m_A;
if(m_VZ < -m_MaxV)
{
m_VZ = -m_MaxV;
}
}
int posMem = pos;
pos++;
if(pos >= length)
{
pos = 0;
}
m_Coord[pos].SetX(m_Coord[posMem].GetX() + m_VX);
m_Coord[pos].SetY(m_Coord[posMem].GetY() + m_VY);
m_Coord[pos].SetZ(m_Coord[posMem].GetZ() + m_VZ);
float x = 0;
float y = 0;
float z = 0;
glBegin( GL_LINE_STRIP );
//This is only for blending in and out the strips/traces of fishes
float length2 = length / 2;
for(int i = 0; i < length; i++)
{
//this is nessecary, to begin and end at the right point in the array
//the pos moves in every step, so i need to begin at over poses
int currentPos = pos - i;
if(currentPos < 0)
{
currentPos += length;
}
x = m_Coord[currentPos].GetX();
y = m_Coord[currentPos].GetY();
z = m_Coord[currentPos].GetZ();
//This is only for blending in and out the strips/traces of fishes
float transparency = ((float)((length2 - abs(length2-i))/length))*5;
if(transparency > 1.0)
{
transparency = 1.0;
}
transparency *= 0.4;
//This color works fine, believe me :)
glColor4f((x+1000)/2000, (y+1000)/2000, (z+1000)/2000, transparency);
//This you need at the beginning
if(x != -9999)
{
//Here, the lines
//they are everywhere and in everey direction
glVertex3f(x, y, z);
}
}
glEnd();
}