Phewww, thanks you have seen and reply to this...I am still struggling :(
the code is long but let me try and get the important bits for you...
i need to be able to store and draw frozen individuals let me go backwards to be easier to understand:
class Population
{
ArrayList <Individual> m_popul;
Population()
{
m_popul = new ArrayList<Individual>();
m_popul.add(new Individual());
Individual ind = m_popul.get(0);
ind.evaluate();
println(m_popul.size());
}
}
class Individual
{
Genotype m_genotype;
Phenotype m_phenotype;
float m_fitness;
Individual()
{
m_genotype = new Genotype();
m_phenotype = new Phenotype(m_genotype);
m_fitness = 0.0;
}
void draw()
{
m_phenotype.draw();
}
void evaluate()
{
m_fitness = m_phenotype.evaluate();
}
}
class Phenotype
{
PVector n; // normal of the triangles
PVector g; // centroid of the traingles
// the real phenotype can only be defined with reference to its environment (Alasdair)
PVector s; // sun position
float angle; // agle between the normal of the traingles and the sun
Phenotype(Genotype ge)
{
n = new PVector();
g = new PVector();
s = new PVector();
}
void draw()
{
for(int i = 0; i < gen.triangles.size(); i++)
{
Triangle tr = (Triangle)gen.triangles.get(i);
// 1. calculate the cross product
n.x = (tr.p2.y * tr.p1.z) - (tr.p2.z * tr.p1.y);
n.y = (tr.p2.z * tr.p1.x) - (tr.p2.x * tr.p1.z);
n.z = (tr.p2.x * tr.p1.y) - (tr.p2.y * tr.p1.x);
n.normalize();
// 2. find the centroid
g.x = (tr.p1.x+tr.p2.x+tr.p3.x)/3;
g.y = (tr.p1.y+tr.p2.y+tr.p3.y)/3;
g.z = (tr.p1.z+tr.p2.z+tr.p3.z)/3;
// 3. draw the normal
stroke(0,100,100);
//line(g.x*factor, g.y*factor, factor-g.z*factor, g.x*factor + 0.03*(n.x*factor), g.y*factor + 0.03*(n.y*factor), factor-g.z*factor + 0.03*(factor-n.z*factor) );
// 4. pvector that follows the sun
s.x = sunny.currentPos.x;
s.y = sunny.currentPos.y;
s.z = sunny.currentPos.z;
s.normalize();
stroke(0);
//line(g.x*factor, g.y*factor, factor-g.z*factor, g.x*factor + 0.03*(s.x*factor), g.y*factor + 0.03*(s.y*factor), factor-g.z*factor + 0.03*(factor-s.z*factor));
// 5. calculate the angle between sun and normal vector
angle = PVector.angleBetween(n, s);
//println(degrees(angle));
// 6. map the angle to a color value anf fill the triangle to that value
// if it is above the horizon
if(angle <= HALF_PI)
{
float mapping = map(angle, 0, 90, 0, 255); //possible angles to possible colours
//println(mapping);
noStroke();
fill(mapping, 100, 100);
}
else
{
noStroke();
fill(0);
}
// 7. draw the mesh of triangles
beginShape();
vertex(tr.p1.x*factor, tr.p1.y*factor, factor-tr.p1.z*factor);
vertex(tr.p2.x*factor, tr.p2.y*factor, factor-tr.p2.z*factor);
vertex(tr.p3.x*factor, tr.p3.y*factor, factor-tr.p3.z*factor);
endShape();
}//normals for loop
}// void display()
float evaluate()
{
// to start with I will say that the best fit is the
// geometry that has the least sun radiation over the year
float fitness = 0.0;
fitness += degrees(sunny.yearlyAverage());
return fitness;
}//float evaluate
}//class Phenotype
class Genotype
{
// create array list of triangles for the delaunay
ArrayList triangles;
Genotype()
{
triangles = new ArrayList();
}
// had to put on a void to run all the points
// because I need to add the triangles to the array list
// because I dont know what size the array list has
void getTriangles()
{
// get the triangulated mesh FROM
// THE ARRAY LIST OF POINTS COMING FROM THE KINECT
///////////////////////////////////////////
triangles = Triangulate.triangulate(points);
//////////////////////////////////////////
//println(triangles.size());
}
}
hopefully its kind of understandable...let me know if not and thanks a lot :)
AH SORRY BTW HERE IS THE
void keyPressed()
{
if(key == ' ')
{
for (int i = 0; i < 1; i++)
{
if (pop.m_popul.size() < 100)
{
pop.m_popul.add(new Individual());
Individual ind = pop.m_popul.get(i);
ind.evaluate();
}
}
//
}
}