std::map<std::string, FuncDesc> func;
std::map<std::string, Gear*> gears;
- std::stack<Gear*> cur_gear;
+ std::vector<Gear*> cur_gear;
Motor *cur_motor;
};
static Gear *begin_gear(ParserState *ps);
static bool end_gear(ParserState *ps);
static Gear *this_gear(ParserState *ps);
+static Gear *find_gear(ParserState *ps, const char *name);
static void update_gear_vars(ParserState *ps, Gear *gear);
static bool set_gear_var(Gear *gear, const char *name, const Value &val);
expected(ps, "numbers as vector elements");
return false;
}
- vec.v[i] = tmp.v[0];
+ vec.v[nelem - i - 1] = tmp.v[0];
ps->val.pop();
}
static Gear *begin_gear(ParserState *ps)
{
Gear *res = new Gear;
- ps->cur_gear.push(res);
+ ps->cur_gear.push_back(res);
return res;
}
errmsg(ps, "parser error: unbalanced end_gear");
return false;
}
- Gear *gear = ps->cur_gear.top();
- ps->cur_gear.pop();
+ Gear *gear = ps->cur_gear.back();
+ ps->cur_gear.pop_back();
printf("DBG: end_gear: %s\n", gear->name.c_str());
ps->mcn->add_gear(gear);
if(!ps->cur_gear.empty()) {
- ps->cur_gear.top()->attach(gear);
+ ps->cur_gear.back()->attach(gear);
}
return true;
}
static Gear *this_gear(ParserState *ps)
{
- return ps->cur_gear.empty() ? 0 : ps->cur_gear.top();
+ return ps->cur_gear.empty() ? 0 : ps->cur_gear.back();
+}
+
+static Gear *find_gear(ParserState *ps, const char *name)
+{
+ // search progressively wider lexical scopes
+ std::vector<Gear*>::const_reverse_iterator it = ps->cur_gear.rbegin();
+ while(it != ps->cur_gear.rend()) {
+ Gear *g = *it++;
+ if(g->name == std::string(name)) {
+ return g;
+ }
+ }
+
+ return ps->gears[name];
}
static void update_gear_vars(ParserState *ps, Gear *gear)
ASSERT_TYPE(val, VAL_VEC);
gear->axis = VVEC3(val);
gear->pdist = val.v[3];
+ printf("setting plane eqn: %f %f %f %f\n", val.v[0], val.v[1], val.v[2], val.v[3]);
} else if(strcmp(name, "thickness") == 0) {
ASSERT_TYPE(val, VAL_NUM);
return false;
}
- Gear *gother = ps->gears[val_gear_name.s];
+ Gear *gother = find_gear(ps, val_gear_name.s.c_str());
if(!gother) {
errmsg(ps, "coaxial: gear \"%s\" not found", val_gear_name.s.c_str());
return false;
}
- Vec3 pos = gother->pos + gother->axis * val_dist.v[0];
+ float avg_thickness = (gthis->thickness + gother->thickness) * 0.5;
+ Vec3 pos = gother->pos + gother->axis * val_dist.v[0] * avg_thickness;
Value res;
res.type = VAL_VEC;