Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411419 Posts in 69363 Topics- by 58416 Members - Latest Member: timothy feriandy

April 17, 2024, 09:44:16 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)SFML.net and Farseer and Vector2's
Pages: [1]
Print
Author Topic: SFML.net and Farseer and Vector2's  (Read 1167 times)
eyeliner
Level 10
*****


I'm afraid of americans...


View Profile
« on: December 11, 2014, 07:54:17 AM »

Hi guys.

If you use SFML.net, and use Farseer you have the marvelous things called Vector2i, Vector2u, Vector2i from SFML.net and Vector2 from Farseer.

Now this is way too messed up for me, and makes me use some freaky conversions back and forth so that I can use Vector2 from Farseer work with whatever Vector2 SFML wants (I swear, that crap is insane for me).

Now does anyone out there know how can I merge all of this madness? Or at least simplify all of this clutter?

Because something like this usually happens:

Code:
//Physics object
phy_Mainchar.Position = new Vector2(100, 100);

//SFML image
spr_MainChar.Position = new Vector2f(phy_Mainchar.Position.X, phy_Mainchar.Position.Y);
This is from the top of my mind so it might not be correct, I'm not currently at home but this question bugs me very much. I hope you understand my question.

Help?
Logged

Yeah.
rosholger
Level 1
*



View Profile
« Reply #1 on: December 12, 2014, 08:19:37 AM »

here is a tutorial on user-defined conversion in C# that you might find usefull http://msdn.microsoft.com/en-us/library/aa288476%28v=vs.71%29.aspx using this your code would look like this
Code:
phy_Mainchar.Position = new Vector2(100, 100);
//implicit
spr_MainChar.Position = phy_Mainchar.Position;
//explicit
spr_MainChar.Position = (Vector2f)phy_Mainchar.Position;

though as this thread on stack overflow states you can't overload operators with extension methods so unless you want to modify the farseer or SFML.net code you cant actually make a user-defined conversion.
What you can do though is to make ToFarseerVec2/ToSFMLVec2 extension methods for the classes that simplifies your code to
 
Code:
phy_Mainchar.Position = new Vector2(100, 100);
spr_MainChar.Position = phy_Mainchar.Position.ToSFMLVec2();
Logged
eyeliner
Level 10
*****


I'm afraid of americans...


View Profile
« Reply #2 on: December 12, 2014, 11:46:57 AM »

Walking to and from home, thinking about it, I actually though about creating a method stub that was overloaded with Farseer's Vector2 and returned a Vector2f and vice-versa, but not extension methods.

Gotta check your solution out.

Thanks mucho grande.
Logged

Yeah.
rosholger
Level 1
*



View Profile
« Reply #3 on: December 13, 2014, 03:07:49 AM »

Your welcome!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic