X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=antikythera;a=blobdiff_plain;f=src%2Fgear.cc;fp=src%2Fgear.cc;h=697610d9440cdb3d157f36e34e62992fd1236dbb;hp=c916e765c389519e8405ce3059f220ef3ed0406e;hb=080d7a779d43f549fc16c44e709cbf5989180fdf;hpb=b29d7193d03833109cfdda3ab576fe183efd8acf diff --git a/src/gear.cc b/src/gear.cc index c916e76..697610d 100644 --- a/src/gear.cc +++ b/src/gear.cc @@ -16,6 +16,8 @@ Gear::Gear() init_angle = 0; xform_valid = false; + supergear = 0; + mesh = 0; } @@ -24,6 +26,41 @@ Gear::~Gear() delete mesh; } +void Gear::attach(Gear *g) +{ + if(g->supergear) { + if(g->supergear == this) { + return; + } + g->supergear->detach(g); + } + g->supergear = this; + subgears.push_back(g); + + // make co-axial + g->axis = axis; + g->pos.x = pos.x; + g->pos.y = pos.y; +} + +bool Gear::detach(Gear *g) +{ + int nsubgears = (int)subgears.size(); + for(int i=0; isupergear = 0; + return true; + } + } + return false; +} + +Gear *Gear::get_super() const +{ + return supergear; +} + void Gear::set_angular_offset(float offs) { init_angle = offs; @@ -55,8 +92,15 @@ const Vec3 &Gear::get_axis() const void Gear::set_position(const Vec3 &pos) { - this->pos = pos; - xform_valid = false; + if(!supergear) { + this->pos = pos; + xform_valid = false; + } else { + if(fabs(this->pos.z - pos.z) > 1e-5) { + this->pos.z = pos.z; + xform_valid = false; + } + } } const Vec3 &Gear::get_position() const @@ -66,13 +110,8 @@ const Vec3 &Gear::get_position() const Vec3 Gear::get_global_position() const { - return pos; // TODO -} - -Vec3 Gear::get_planar_position() const -{ - Mat4 inv_xform = transpose(get_dir_matrix()); - return inv_xform * pos; + const Mat4 &m = get_matrix(); + return m * Vec3(0, 0, 0); } void Gear::set_angle(float angle) @@ -88,8 +127,7 @@ float Gear::get_angle() const float Gear::get_vis_rotation() const { - float fix_crooked_teeth = get_angular_pitch() * 3.0 / 8.0; - return fmod(init_angle + fix_crooked_teeth + angle, M_PI * 2.0); + return fmod(init_angle + angle, M_PI * 2.0); } const Mat4 &Gear::get_matrix() const @@ -224,8 +262,11 @@ bool Gear::gen_mesh() mesh->explode(); mesh->calc_face_normals(); + float fix_tooth_up = get_angular_pitch() * 3.0 / 8.0; + Mat4 rot; rot.rotation_x(M_PI / 2.0); + rot.rotate_z(fix_tooth_up); mesh->apply_xform(rot, rot); mesh->set_vis_vecsize(6.0); @@ -246,4 +287,7 @@ void Gear::calc_matrix() const xform = dir_xform; xform.rotate_z(get_vis_rotation()); xform.translate(pos); + + axel_xform = dir_xform; + axel_xform.translate(pos); }