SFML community forums
Help => General => Topic started by: Xorlium on May 11, 2010, 04:20:47 am
-
Hi,
I'm working on a project using sfml, and I have a Vector2r (vector 2 real) with tons of different functions that I like. sf::Vector2f doesn't have many, so I prefer to use mine. My problem is that the sf functions all accept sf::Vector2f, but not of course Vector2r. I already made a constructor of Vector2r(sf::Vector2f), but how can I do it the other way around, so that I can cast implicitly the vectors?
My solution for now is to define a function
sf::Vector2f r2f(Vector2r v);
and use it everywhere, but that doesn't seem very clean. Is there another way?
Thanks!
-
I would simply extend the Vector2r class with this function:
sf::Vector2f getVector2f();
and ifyou want a 2f from your 2r, just write: sf::FunctThatRequiresVector2f(v2r.getVector2f());
(I hope I understood your problem correctly...)
-
Yeah, that's basically what I was doing, except defining it outside the class. But yeah.
Thanks
-
So that wasn't that much of a help... well, I have no other idea without providing a v2r version of sfml's functions :D
-
Heh, yeah. I was looking to see if there was a way to define a constructor for Vector2f outside the class declaration, like:
Vector2f(Vector2r vec);
or something.
-
You can define an implicit conversion operator.
class Vector2r
{
public :
...
operator sf::Vector2f() const
{
return sf::Vector2f(x, y);
}
};
-
Oh wow, thanks! it works! I hadn't checked this thread.
-
* Learned something usefull. *