I have a simple c++ class that basically just holds a couple of objects
Group.h
class Group {
public:
Mover anchor;
Spring spring;
ofColor color;
void init(ofVec3f location);
};
Group.cpp
void Group::init(ofVec3f location) {
color = mRandomColor();
anchor.location = location;
spring.setTarget(&anchor);
spring.location = location;
}
I then access the anchor and spring properties directly calling methods on them. This works fine if I have just once instance of Group, but if I add multiple, then things stop working.
Here is how I instantiate the instances and store in a vector:
int GRID_SIZE = 20;
for(int y = 0; y < (bounds.height / GRID_SIZE) - 1; y++) {
for(int x = 0; x < (bounds.width / GRID_SIZE) - 1; x++) {
ofVec3f l;
l.x = (x + 1) * GRID_SIZE;
l.y = (y + 1) * GRID_SIZE;
Group g;
g.init(l);
groups.push_back(g);
}
}
Here is an example how I access the properties in my code:
float dist = (mouseMover.location - g.spring.location).length();
if(dist < 20) {
ofVec3f force = mouseMover.repel(g.spring);
g.spring.applyForce(force);
}
I am still learning C++, and wanted to see if someone could give me a sanity check on my class to see if I am doing anything obviously wrong.