Dodane Driftowanie
This commit is contained in:
16
main.cpp
16
main.cpp
@@ -123,9 +123,9 @@ const float acceleration = 0.2f;
|
|||||||
|
|
||||||
float rotationVelocity = 0.0f; // Prędkość obrotu łazika
|
float rotationVelocity = 0.0f; // Prędkość obrotu łazika
|
||||||
|
|
||||||
const float rotationAcceleration = 0.1f; // Przyspieszenie obrotu
|
const float rotationAcceleration = 0.075f; // Przyspieszenie obrotu
|
||||||
const float rotationFriction = 0.1f; // Współczynnik tarcia obrotu
|
const float rotationFriction = 0.1f; // Współczynnik tarcia obrotu
|
||||||
const float maxRotationSpeed = 3.0f; // Maksymalna prędkość obrotu
|
const float maxRotationSpeed = 1.5f; // Maksymalna prędkość obrotu
|
||||||
|
|
||||||
// Struktura do reprezentacji płotu
|
// Struktura do reprezentacji płotu
|
||||||
struct Plot {
|
struct Plot {
|
||||||
@@ -200,7 +200,7 @@ void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obracanie
|
// Obracanie (rotacja z driftowaniem)
|
||||||
if (keyAPressed) {
|
if (keyAPressed) {
|
||||||
rotationVelocity += rotationAcceleration;
|
rotationVelocity += rotationAcceleration;
|
||||||
if (rotationVelocity > maxRotationSpeed) rotationVelocity = maxRotationSpeed;
|
if (rotationVelocity > maxRotationSpeed) rotationVelocity = maxRotationSpeed;
|
||||||
@@ -210,13 +210,14 @@ void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
if (rotationVelocity < -maxRotationSpeed) rotationVelocity = -maxRotationSpeed;
|
if (rotationVelocity < -maxRotationSpeed) rotationVelocity = -maxRotationSpeed;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Hamowanie obrotu (wytracanie prędkości z powodu tarcia)
|
// Jeśli żadna z klawiszy A/D nie jest wciśnięta, to stopniowo spowalniamy rotację (drift)
|
||||||
|
float driftFactor = 0.1f; // Mniejsza wartość = dłuższy drift
|
||||||
if (rotationVelocity > 0) {
|
if (rotationVelocity > 0) {
|
||||||
rotationVelocity -= rotationFriction;
|
rotationVelocity -= rotationFriction * driftFactor;
|
||||||
if (rotationVelocity < 0) rotationVelocity = 0;
|
if (rotationVelocity < 0) rotationVelocity = 0;
|
||||||
}
|
}
|
||||||
else if (rotationVelocity < 0) {
|
else if (rotationVelocity < 0) {
|
||||||
rotationVelocity += rotationFriction;
|
rotationVelocity += rotationFriction * driftFactor;
|
||||||
if (rotationVelocity > 0) rotationVelocity = 0;
|
if (rotationVelocity > 0) rotationVelocity = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,6 +290,9 @@ void UpdateRover(const std::vector<Plot>& fences) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Plot> fences = {
|
std::vector<Plot> fences = {
|
||||||
{-550.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0}, // 0 - pionowo
|
{-550.0f, 3.0f, 50.0f, 1310.0f, 4.0f, 0}, // 0 - pionowo
|
||||||
{ 50.0f, 3.0f, -600.0f, 1200.0f, 4.0f, 1}, // 1 - poziomo
|
{ 50.0f, 3.0f, -600.0f, 1200.0f, 4.0f, 1}, // 1 - poziomo
|
||||||
|
|||||||
Reference in New Issue
Block a user