Working with Bepu?

Sep 17, 2012 at 9:20 PM

Hey, so far Xen is amazing. I've been getting a feel for how it works over the last week or so and I've decided I want to add Bepu's physics, do you know how I would have Xen render it? For example, I just want to add a box to tutorial 15 (the disk with two lights). Any ideas would be helpful, thanks.

Sep 17, 2012 at 9:32 PM

We have BEPU working with Xen, but the interaction between Xen and BEPU needs to be handled fairly elegantly if you want to avoid writing code to spawn the physics representation for each Xen model.

We have a customized Xen model pipeline that stores the physics shapes like cylinders, spheres, boxes in the source model file which is deserialized and passed over to spawn BEPU entities when the model is being loaded. I can't really post the code here because it's extremely long and non-straightforward. Even though BEPU supports triangulated models to be used as collision primitives, we didn't use that since we don't need the fidelity and we don't want the CPU overhead of calculating the collision for such objects.

If you want to just have a primitive like a sphere, then you need to spawn a Xen sphere primitive and a BEPU sphere primitive separately with each update call, pass the BEPU primitive's world transformation over to the Xen primitive. The idea is that the BEPU sphere's position and orientation would be updated each frame thru the physics system, and Xen would just take that and use it to render the sphere that is set to be the same radius.

Things get  more complicated if you start to deal with animated objects, or objects that are made up of several physics primitives that use a different render model which doesn't have a 1-to-1 association (like a light bulb shape that might be made up of a sphere and a cylinder in BEPU, but just use the light bulb model in Xen).

I hope that helps.

Sep 17, 2012 at 9:45 PM

Yes, it does a bit. I'm aiming at just rendering a few models I made and a single level. I take it there are no example projects or simple ways to do this?

Sep 17, 2012 at 10:01 PM
Edited Sep 17, 2012 at 10:01 PM

There aren't that many people using Xen (especially not the latest version of Xen). Given that BEPU has also been fairly recently (relatively speaking) announced as "free to use", I don't think you'll see any examples lying around. Even though its a bit older, you might want to try and find some examples using Xen and JiglibX together. JiglibX is no longer supported (the original author moved over to his new physics system called Jitter), but since it's been around a bit longer it might help finding more info on that.

That said, having BEPU work together with Xen won't be that different than having vanilla XNA models work with BEPU. The ideas would be similar, but the difference would be pretty much on the level of how one uses the Xen API as opposed to XNA graphics.

Like I had said previously, if you want to attach a model to a BEPU primitive shape like a box or sphere, simply spawn the primitive/entity in BEPU (has plenty of samples on how to do it), then spawn your model in Xen (has samples in it as well), and then each frame, get the BEPU entitiy's world transform into the Xen model. I can't really say more than that because I have no idea about what you know and don't know when it comes to 3D gfx, xna shaders or C#.

Also look at the BEPU forums. You can find plenty of info there on how to tie physics to rendering (be it plain XNA or Xen). If you can't figure out how to do it, then I'm sorry to say that working with Xen will only slow you down because there really isn't a community that you can bounce questions off of. I've had to figure out, fix and improve mutliple aspects of Xen for my own purposes and I can't really blame the original author of Xen for not responding since he has also moved on to other things it seems.

Sep 18, 2012 at 12:30 AM

Alright, thanks for your time. I'm going to work through the tutorials again (they're really helpful!) until I get it down.