So far, the class only has 4 functions.
Vector2f ToVector(), Creates a vector from the Polar
FromVector(Vector2f), Creates new Polar co-ordinate from a Vector
Rotate(float Angle), Increments t, then adds or subtracts 360 untill its in the 0 to <360 range
SetRotation(float Angle), Sets t, then puts it in the 360 range.
Where is the radius? And why not a single function instead of a class?
sf::Vector2f polarToVector(float angle, float radius);
My library Thor provides the class template thor::PolarVector2<T> (http://www.bromeon.ch/libraries/thor/v2.0/doc/structthor_1_1_polar_vector2.html). It has two members r (radius) and phi (polar angle) and can be implicitly converted to and from SFML vectors. Maybe it helps you.
By the way, I also implement a lot of functions on top of SFML vectors. Sometimes it's just easier to write
sf::Vector2f vector(...);
thor::rotate(vector, 45.f);
instead of constructing a polar vector each time.
So far, the class only has 4 functions.
Vector2f ToVector(), Creates a vector from the Polar
FromVector(Vector2f), Creates new Polar co-ordinate from a Vector
Rotate(float Angle), Increments t, then adds or subtracts 360 untill its in the 0 to <360 range
SetRotation(float Angle), Sets t, then puts it in the 360 range.
Where is the radius? And why not a single function instead of a class?
sf::Vector2f polarToVector(float angle, float radius);
Thats not the entire class, just the functions. it has the local members of r and t for radius and angle, plus constructors.
I originally did have it as just a pair of functions, PolarToVector and VectorToPolar, but when I actually tried to put it into practice, I found myself using a structure that contained floats r and t to store my values, and realised it was probably just easier to store it all in 1 class.
Rotate and SetRotation came later when i discovered that after pretty much every "Polar.t += angle;" incrementation, I was using a "while(Polar.t >= 360.f) Polar.t -= 360.f;" check to keep it below 360, so included that in the class as a pair of functions. of course my check that was only for positive incrementations, because thats all I was doing, the function also includes a check for negative incrementations.
so the same code can now be replaced with "Polar.Rotate(angle);" instead.
Here's the entire class definition in my Polar.h file
// Note: This is not a true Polar representation.
// Y is inverted to match screen co-ordinates vs graph style co-ordinates.
// T (Angle) is measured from North vs from East.
// This should make it more useful for calculating sprite rotation from an X and Y movement.
class Polar
{
public :
Polar();
Polar(float r, float t);
Polar(const sf::Vector2f& vector);
float r; // Radial. aka force or speed
float t; // Turn, Angular measurement in Degrees
void Rotate(float angle); // increment t by angle. corrects to 0 - 360.
void SetRotation(float angle); // sets t to angle. corrects to 0 - 360.
const sf::Vector2f ToVector();
void FromVector(const sf::Vector2f& vector);
void FromVector(float x, float y);
};
As said, I purposely limited it to float only, since the only other type I'd use for something like this would be double, and SFML seems to be geared to be using floats over doubles.