[Resolved] Using BEPU with DrawUserIndexedPrimitives()

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
radishhoedown
Posts: 5
Joined: Fri Dec 09, 2011 1:14 pm

[Resolved] Using BEPU with DrawUserIndexedPrimitives()

Post by radishhoedown »

I'm working to adapt your 'getting started' demo.

I notice that in nearly all cases you load XNA Model files through the pipeline. At points in my program I am needing to render convex hulls with a shader. Since my methods only generate true vertex convex hulls, my plan was to use your GetShapeMeshData() method to get the vertices and indices for rendering and then run the shader pass, and then render the geometry using the DrawUserIndexedPrimitives. However it seems like this would take a slightly different approach to the one taken in the demo since I don't have a mesh to have any effects to use with the object world matrix. I just have these verts and indices which I need to transform to match the physics engine values in the world. I tried transforming each point by the object world matrix but this just gave weird results.
Last edited by radishhoedown on Tue Dec 13, 2011 12:15 pm, edited 1 time in total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Synchronising Physics with DrawUserIndexedPrimitives()

Post by Norbo »

The engine itself is pretty much blind to how the graphics are set up. The core idea is that there should be a graphical shape which matches the collision shape in local space. Then, you can apply the entity's world transform to the graphical shape so that the graphical shape matches the world shape at all times.

Of course, there's many different paths which will work. Constructing a vertex/index buffer pair and transforming the vertices by the world transform in software can work, but it is inefficient.

An effect can be created independently from a XNA mesh object. You can use the independent effect to render other geometry with the appropriate world transforms. Since this is all on the graphics side of things, I would recommend checking out some samples on the main XNA website which cover the topic with more breadth and depth.
radishhoedown
Posts: 5
Joined: Fri Dec 09, 2011 1:14 pm

Re: Synchronising Physics with DrawUserIndexedPrimitives()

Post by radishhoedown »

Yep, I figured so in the end. I have resolved this and for anyone else who might come here looking for the answer I used a BasicEffect. This can be passed into the entity via a constructor and the effect can be applied in the usual way inside the object Draw method.

Then I set the world view and and projection members to the object local world matrix and camera view and projection matrices. The vertices now transform correctly with the physics engine.
Post Reply