My idea is that SFML has something similar to
sf::Rect<typename T> that is based on circle (
sf::Circle<typename T>)...
So what I mean, is to have sf::Circle<typename T> class that holds middle position(X, Y) and radius.
Meh... coding says more then my words
Here is how it should look:
namespace sf
{
template <typename T>
class Circle
{
public:
T x, y;
T radius;
Circle<T>()
{
this->x = T(0);
this->y = T(0);
this->radius = T(0);
}
Circle<T>(T _x, T _y, T _radius)
{
this->x = _x + _radius;
this->y = _y + _radius;
this->radius = _radius;
}
Circle<T>(sf::CircleShape cShape)
{
this->x = T(cShape.getRadius() + cShape.getPosition().x);
this->y = T(cShape.getRadius() + cShape.getPosition().y);
this->radius = T(cShape.getRadius());
}
bool intersects(sf::Circle<T> circle)
{
bool ret = true;
if (sqrt(pow(this->x - circle.x, 2) + pow(this->y - circle.y, 2)) >= this->radius + circle.radius)
ret = false;
return ret;
}
bool contains(sf::Vector2<T> vecT)
{
bool ret = false;
if (sqrt(float(pow(float(this->x - vecT.x), (float)2) + pow(float(this->y - vecT.y), (float)2))) <= this->radius)
ret = true;
return ret;
}
};
typedef sf::Circle<int> IntCircle;
typedef sf::Circle<double> DoubleCircle;
typedef sf::Circle<float> FloatCircle;
typedef sf::Circle<unsigned int> UintCircle;
}
It probably says all...
And here is small example of usage:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <typeinfo>
#include "SFML\Graphics.hpp"
#include "SFML\System.hpp"
#include "SFML\Window.hpp"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
sf::RenderWindow window;
window.create(sf::VideoMode(600, 400), "FloatCircle");
sf::CircleShape sfCircle(20);
sfCircle.setPosition(100, 100);
sfCircle.setFillColor(sf::Color::Blue);
sf::FloatCircle myCircle(sfCircle);
// or:
// sf::FloatCircle myCircle(100, 100, 20);
// ---------------------------------------
// or:
// sf::FloatCircle myCircle;
// myCircle.radius = 20;
// myCircle.x = 100 + myCircle.radius;
// myCircle.y = 100 + myCircle.radius;
while(window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if (myCircle.contains((sf::Vector2f)sf::Mouse::getPosition(window)))
sfCircle.setFillColor(sf::Color::Red); //Collision.
else
sfCircle.setFillColor(sf::Color::Blue); //No collision.
window.clear();
window.draw(sfCircle);
window.display();
}
return 0;
}
I hope it helps.
Well its not that good idea, but its easy to use.
Btw, sorry for my bad english.