X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fmanipulator.cpp;h=b61d9a7ae5e28642344554f01b001f9887480c12;hb=18c529dfdd34e07f4f6021151ddce29fa85437bc;hp=2ee967679428ebdf1595b74669128a194b31291a;hpb=bde934f7d5ba07a9442a305192e10024820d13ed;p=r2c2.git diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index 2ee9676..b61d9a7 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -101,9 +101,9 @@ void Manipulator::flatten() float z = 0; for(vector::iterator i=objects.begin(); i!=objects.end(); ++i) { - z += i->object->get_position().z; - if(Track *track = dynamic_cast(i->object)) - z += track->get_slope()/2; + unsigned nsn = i->object->get_n_snap_nodes(); + for(unsigned j=0; jobject->get_snap_node(j).position.z/nsn; } z /= static_cast(objects.size()); @@ -112,7 +112,7 @@ void Manipulator::flatten() Vector p = i->object->get_position(); i->object->set_position(Vector(p.x, p.y, z)); if(Track *track = dynamic_cast(i->object)) - track->set_slope(0); + track->set_tilt(Angle::zero()); } update_objects(); @@ -177,27 +177,26 @@ void Manipulator::even_slope(bool smooth) while((end_z-start_z)*dir/total_len>cur_slope+0.025 && order.size()>2) { cur_slope += 0.025; + Angle tilt = Geometry::atan(cur_slope); + + set_slope(order.front(), start_z, tilt); + start_z += order.front().track->get_type().get_path_length(0)*dir*cur_slope; + total_len -= order.front().track->get_type().get_path_length(0); + order.pop_front(); - float dz = order.front().track->get_type().get_total_length()*dir*cur_slope; - set_slope(order.front(), start_z, dz); - start_z += dz; - total_len -= order.front().track->get_type().get_total_length(); - order.erase(order.begin()); - - dz = order.back().track->get_type().get_total_length()*dir*cur_slope; - set_slope(order.back(), end_z-dz, dz); - end_z -= dz; - total_len -= order.back().track->get_type().get_total_length(); - order.erase(--order.end()); + end_z -= order.back().track->get_type().get_path_length(0)*dir*cur_slope; + set_slope(order.back(), end_z, tilt); + total_len -= order.back().track->get_type().get_path_length(0); + order.pop_back(); } } float cur_z = start_z; + Angle tilt = Geometry::atan((end_z-start_z)/total_len); for(list::iterator i=order.begin(); i!=order.end(); ++i) { - float dz = i->track->get_type().get_total_length()*(end_z-start_z)/total_len; - set_slope(*i, cur_z, dz); - cur_z += dz; + set_slope(*i, cur_z, tilt); + cur_z += i->track->get_type().get_path_length(0)*(end_z-start_z)/total_len; } update_objects(); @@ -322,7 +321,7 @@ void Manipulator::button_press(unsigned btn) j->object->break_link(**i); } - const set <racks = designer.get_layout().get_tracks(); + const set <racks = designer.get_layout().get_all(); for(set::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) { bool ok = true; @@ -366,7 +365,7 @@ void Manipulator::axis_motion(unsigned axis, float value, float) i->object->set_rotation(i->rot); } - const set <racks = designer.get_layout().get_tracks(); + const set <racks = designer.get_layout().get_all(); float limit = max(designer.get_layout().get_catalogue().get_gauge(), designer.get_camera_controller().get_view_scale()/100.0f); MObject *snapped = 0; @@ -544,18 +543,19 @@ void Manipulator::update_neighbors() } } -void Manipulator::set_slope(TrackOrder &track, float z, float dz) +void Manipulator::set_slope(TrackOrder &track, float z, const Angle &tilt) { const Vector &p = track.track->get_position(); + float dz = tan(tilt)*track.track->get_type().get_path_length(0); if(track.rev) { track.track->set_position(Vector(p.x, p.y, z+dz)); - track.track->set_slope(-dz); + track.track->set_tilt(-tilt); } else { track.track->set_position(Vector(p.x, p.y, z)); - track.track->set_slope(dz); + track.track->set_tilt(tilt); } }