Код: Выделить всё
void ControlSystem::MoveAlongPath(const float& elapsedTime)
{
if (!startMovement || selectedObject == nullptr || objectPath.empty() || pathIndex >= objectPath.size())
{
return;
}
auto banGame = BanGame::Get();
VECTOR2 currentPos = objectPath[pathIndex];
VECTOR2 nextPos = objectPath[pathIndex + 1];
VECTOR2 direction = nextPos - currentPos;
float distance = BanGame::Get()->Length(direction);
float t1 = speed * elapsedTime / distance;
VECTOR2 newPos = MathUltils::Lerp(currentPos, nextPos, t1);
float distanceToNextPoint = BanGame::Get()->Length(nextPos - newPos);
if (distanceToNextPoint = objectPath.size() - 1) {
selectedObject->SetPosition(objectPath.back());
startMovement = false;
return;
}
else
{
selectedObject->SetPosition(newPos);
}
}
float t2 = rotationSpeed * elapsedTime*0.1f;
if (t2 > 1.0f) t2 = 1.0f;
//TODO rotate object
/*VECTOR2 norDirection = BanGame::Get()->Normalize(direction);
float targetAngle = banGame->AngleBetweenVectorReturnRadian(nextPos, currentPos);
float currentAngle = banGame->ConvertToDegrees(selectedObject->GetAngle().z);
float angleDifference = banGame->ConvertToDegrees(targetAngle - currentAngle);
float interpolatedAngle = MathUltils::Lerp(currentAngle, currentAngle + angleDifference, t2);
selectedObject->SetAngle(VECTOR3(0, 0, banGame->ConvertToDegrees(interpolatedAngle)));*/
for (size_t i = 1; i < dragPoints.size(); ++i) {
banGame->DrawLine(dragPoints[i - 1], dragPoints[i], 5.0f, VECTOR3(0, 0, 1), COLOR::BLUE);
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... awn-path-c