working controller
This commit is contained in:
parent
8d45088064
commit
38db780844
10 changed files with 317 additions and 44 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "PosTracker.hpp"
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
using sf::Vector2f;
|
||||
using sf::Transform;
|
||||
|
@ -7,12 +8,12 @@ void PosTracker::reset(Vector2f initialPos, float initialRot) {
|
|||
transform = transformFromPosRot(initialPos, initialRot);
|
||||
}
|
||||
|
||||
void PosTracker::update(float newLeftValue, float newRightValue) {
|
||||
auto leftDistance = (newLeftValue - _lastLeftValue) * wheelIncrementDistance();
|
||||
auto rightDistance = (newRightValue - _lastRightValue) * wheelIncrementDistance();
|
||||
void PosTracker::update(std::size_t value_left, std::size_t value_right) {
|
||||
auto leftDistance = (value_left - _lastLeftValue) * wheelIncrementDistance() * _wheel_dir_left;
|
||||
auto rightDistance = (value_right - _lastRightValue) * wheelIncrementDistance() * _wheel_dir_right;
|
||||
updateTransform(leftDistance, rightDistance);
|
||||
_lastLeftValue = newLeftValue;
|
||||
_lastRightValue = newRightValue;
|
||||
_lastLeftValue = value_left;
|
||||
_lastRightValue = value_right;
|
||||
}
|
||||
|
||||
void PosTracker::updateTransform(float leftDistance, float rightDistance) {
|
||||
|
@ -26,3 +27,13 @@ void PosTracker::updateTransform(float leftDistance, float rightDistance) {
|
|||
);
|
||||
transform = new_;
|
||||
}
|
||||
|
||||
Vector2f PosTracker::get_pos() { return this->transform.getPosition(); }
|
||||
float PosTracker::get_rot() { return this->transform.getRotation(); }
|
||||
|
||||
void PosTracker::hint_right(bool forward) {
|
||||
_wheel_dir_right = forward ? 1 : -1;
|
||||
}
|
||||
void PosTracker::hint_left(bool forward) {
|
||||
_wheel_dir_left = forward ? 1 : -1;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue