Maybe I misunderstood, but you need to get direction? From sf::Transformable you can get direction via matrix:
this = something sf::Transformable.
const float* m = this->getTransform().getMatrix();
return sf::Vector2f(m[0], m[1]);
ChronicRat is right, normalize(V2 - V1) will give you the direction vector from V1 to V2.
If you want that in an angle, here's how you do it (radian): atan2(direction.y, direction.x), you can then convert to degrees if needed. :p
it looks like one of my function in npc[movable struct]:
#define toDegrees 57.32f //(180 / 3.14)
float gameEntityMove::coordsToAngle(sf::Vector2f start, sf::Vector2f end)
{
#pragma warning(disable : 4715) // not all control paths return a value
if (start.x != end.x && start.y != end.y)
return std::atan2(start.y - end.y, start.x - end.x) * toDegrees;
else
return -1;
}
am i right ?
If you don't want to reinvent the wheel, you can also use Thor.Vectors (http://www.bromeon.ch/libraries/thor/v2.0/doc/_vector_algebra2_d_8hpp.html), they provide already everything: angles, distances, normalization, ...
Computing the direction is then as simple as:
sf::Vector direction = thor::unitVector(b - a);
You usually don't want to work with angles unless you really need them, because the special cases (wraparound) are a bit annoying to handle.