Attempt at constant speed
Not working because linearly increasing t doesn't imply constant velocity within a segment between two points. Seems like a more complex approach will be necessary
This commit is contained in:
parent
09897240d1
commit
cf19af1142
@ -18,7 +18,12 @@ struct PathMove {
|
||||
std::vector<glm::quat> views;
|
||||
};
|
||||
|
||||
PathMove(double speed, Path path, Views views) : speed(speed), path(path), views(views) {}
|
||||
PathMove(double speed, Path path, Views views) : speed(speed), path(path), views(views) {
|
||||
// Calculate distances
|
||||
for (int i = 0; i < path.points.size() - 1; i++) {
|
||||
distances.emplace_back(glm::distance(path.points[i], path.points[i + 1]));
|
||||
}
|
||||
}
|
||||
|
||||
double speed;
|
||||
float time_passed = 0.0;
|
||||
@ -28,5 +33,6 @@ struct PathMove {
|
||||
|
||||
Path path;
|
||||
Views views;
|
||||
std::vector<float> distances;
|
||||
};
|
||||
#endif // __PATHMOVE_H__
|
@ -85,7 +85,8 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
||||
PathMove::Path path = pathmove->path;
|
||||
|
||||
// Add the passed time
|
||||
pathmove->time_passed += deltaTime;
|
||||
float desired_distance = deltaTime * pathmove->speed; // TODO
|
||||
pathmove->time_passed += desired_distance / pathmove->distances[pathmove->current_point_index];
|
||||
|
||||
// Shorthand for number of points in the path
|
||||
int num_points = path.points.size();
|
||||
@ -171,6 +172,8 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
||||
|
||||
// Apply
|
||||
transform->set_rotation_from_quat(result);
|
||||
|
||||
std::cout << pathmove->time_passed << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user