Machine::Machine()
{
meshing = 0;
+ meshing_valid = false;
visited = 0;
}
void Machine::add_gear(Gear *g)
{
gears.push_back(g);
+ meshing_valid = false;
}
void Machine::add_motor(int gearidx, float speed_hz)
motors.push_back(m);
}
+void Machine::invalidate_meshing()
+{
+ meshing_valid = false;
+}
+
void Machine::calc_meshing()
{
int ngears = (int)gears.size();
{
int ngears = (int)gears.size();
+ if(!meshing_valid) {
+ calc_meshing();
+ meshing_valid = true;
+ }
+
memset(visited, 0, ngears * sizeof *visited);
for(size_t i=0; i<motors.size(); i++) {
int gidx = motors[i].drive;
private:
std::vector<Gear*> gears;
bool **meshing;
+ bool meshing_valid;
bool *visited; /* used for update_gear */
std::vector<Motor> motors;
void add_gear(Gear *g); /* takes ownership */
void add_motor(int gearidx, float speed_hz);
+ void invalidate_meshing();
void calc_meshing();
void update(float dt);
machine->add_gear(gear3);
machine->add_motor(0, 1.0);
- machine->calc_meshing();
start_time = glutGet(GLUT_ELAPSED_TIME);
return true;