PVecroe 1D array question
in
Programming Questions
•
2 years ago
I am setting up a 1D array of PVectors and passing this information through into setup, as shown in the code extract below (Processing doesn't seem to want the PVectors declared inside the 1D array, so I set them up prior). However, when I run the code, Processing grabs only one value. When I uncomment the random setup of vectors, the code runs fine and produces four instances of the repel class. How do I amend the 1D array info so as to create four instances of predefined vectors?
//global variables
Repel [] repeller;
PVector attractVec1 = new PVector(width/2, height/2, width/2);
PVector attractVec2 = new PVector(width, height, width);
PVector attractVec3 = new PVector(width/4, height/4, width/4);
PVector attractVec4 = new PVector(width/8, height/8, width/8);
PVector [] vecPosArray = {attractVec1, attractVec2, attractVec3, attractVec4};
void setup()
{
repeller = new Repel[vecPosArray.length];
//repeller = new Repel[4];
for (int i = 0; i < repeller.length; ++i)
{
//vecPosRepel = new PVector (random(width), random(height), random(height));
//repeller[i] = new Repel(vecPosRepel);
repeller[i] = new Repel(vecPosArray[i]);
}
}
void draw()
{
for (int i = 0; i < repeller.length; ++i)
{
repeller[i].display();
}
}
1