-
- // TODO: carry excess time over to next node? This is how it was done in camera.cpp:
- /*
- if(auto_t - elapsed_time >= 0) {
- translation += current_dir * elapsed_time;
- auto_t -= elapsed_time;
- } else {
- // do the rest of the old movement
- translation += current_dir * auto_t;
- elapsed_time -= auto_t;
- auto_t = 0;
-
- // construct path for next point
- if(auto_idx+1 >= scrollpoints.size()) {
- keep_in_bounds(translation);
- return;
- }
- Vector distance = scrollpoints[auto_idx+1].position
- - scrollpoints[auto_idx].position;
- current_dir = distance.unit() * scrollpoints[auto_idx].speed;
- auto_t = distance.norm() / scrollpoints[auto_idx].speed;
-
- // do movement for the remaining time
- translation += current_dir * elapsed_time;
- auto_t -= elapsed_time;
- auto_idx++;
- }
- */
-
- // advance to next node at scheduled time
- if (timeToGo <= 0) {
- position = pathNodes[destinationNode].position;
-
- // set destinationNode to next node
- if (forward) {
- destinationNode++;
- if (destinationNode >= (int)pathNodes.size()) {
- if (circular) {
- destinationNode = 0;
- } else {
- destinationNode = (int)pathNodes.size()-1;
- }
- }
- } else {
- destinationNode--;
- if (destinationNode < 0) {
- if (circular) {
- destinationNode = (int)pathNodes.size()-1;
- } else {
- destinationNode = 0;
- }
- }
+ int nearest_node_id = -1;
+ float nearest_node_dist = 0;
+ int id = 0;
+ for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) {
+ float dist = (i->position - reference_point).norm();
+ if ((nearest_node_id == -1) || (dist < nearest_node_dist)) {
+ nearest_node_id = id;
+ nearest_node_dist = dist;