Transitioning between XNA Vector3 and BEPU Vector3

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
aCallum
Posts: 13
Joined: Sat Jan 04, 2014 4:31 pm

Transitioning between XNA Vector3 and BEPU Vector3

Post by aCallum »

Hi there,

I've spent the day looking over BEPU as a solution to physics in our current project and I must say it looks great!

I've started to implement a few basic objects into the current project but am at a crossroads with how to neatly handle the conversion between BEPU and XNA Vector3 types (and others once I get to them).

It's worth mentioning that the project is already quite substantial, for example we have a very solid Transform system in place already..

So yeh, I'd love to hear how others have resolved this sort of neatness issue in the past!

Cheers
sergiusz308
Posts: 49
Joined: Mon Oct 08, 2012 4:57 pm

Re: Transitioning between XNA Vector3 and BEPU Vector3

Post by sergiusz308 »

You're familiar with MathConverter class? It handles conversion between BEPU and XNA types.

I'd recommend search-n-replace throughout your solution and replace types for most scenarios. Another option is to use aforementioned MathConverter but I'd recommend using it outside update, draw or other methods executed multiple times per frame to avoid GC and method call overhead.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Transitioning between XNA Vector3 and BEPU Vector3

Post by Norbo »

Other than the MathConverter and generally explicit approaches, there's also the option of tossing some implicit conversions into the BEPUutilities math types. That will make most interaction transparent.
Another option is to use aforementioned MathConverter but I'd recommend using it outside update, draw or other methods executed multiple times per frame to avoid GC and method call overhead.
While all of the conversion operations will indeed involve a little overhead from method calls and data copies, you don't have to worry about GC. The involved objects are all value types.

Unsurprisingly, I usually just use BEPUutilities for everything in my projects, and it's possible (but a bit tedious) to replace all the BEPUutilities math in BEPUphysics with XNA references if you really wanted to.
Post Reply