Problem with Items being covered by the Terrain

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
CharlieCurry
Posts: 11
Joined: Sat Mar 10, 2012 5:36 pm

Problem with Items being covered by the Terrain

Post by CharlieCurry »

I have been having this problem where my vehicle and some other objects will seem to go under the terrain at various places, most places they do get positioned correctly on the terrain but some places they don't. I also noticed that everything works properly if I use the ModelDrawer to draw the terrain, I only have this problem when using my custom Terrain class to do the drawing. I tried drawing using both methods at the same time, and it did reveal that my Terrain class does draw the terrain at a slightly different position than the Model drawer, so I was able to reduce the problem by having my Terrain drawing code translating the Terrain by Vector3(-2.75f, 0.25f, -2.75f) (arbitrary values determined by trial and error). My question is, Is this normal to have to offset it like this, and if so how do I determine the proper amount of offset needed?

Thanks

Charlie Curry

P.S. BEPU is completely awsome, thanks for creating such a great product.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problem with Items being covered by the Terrain

Post by Norbo »

My question is, Is this normal to have to offset it like this, and if so how do I determine the proper amount of offset needed?
It is not normal to have an offset. I would recommend comparing the terrain graphics implementation against the DisplayTerrain in the BEPUphysicsDrawer (found in the main source download on codeplex).

Key differences would include the origin of the terrain and the individual quad triangle organization. Note that the terrain's QuadTriangleOrganization can be one of two options (bottom left upper right, or bottom right upper left) when constructing the TerrainShape for use with a Terrain. It can also be set in the terrain.Shape.QuadTriangleOrganization property.

Also, beware of any additional transforms which may be applied to either the shape or the graphics.
P.S. BEPU is completely awsome, thanks for creating such a great product.
Thanks and you're welcome :)
CharlieCurry
Posts: 11
Joined: Sat Mar 10, 2012 5:36 pm

Re: Problem with Items being covered by the Terrain

Post by CharlieCurry »

I checked my custom Terrain drawing code and did find a miscalculation that was causing the terrain to be scaled larger than it should be, once I fixed that, it now works perfectly. Thanks for all your help Norbo.
squimball
Posts: 7
Joined: Sat May 07, 2011 9:25 pm

Re: Problem with Items being covered by the Terrain

Post by squimball »

I too had an issue similar to this. My problem was the QuadTriangleOrganization. BEPU was using one way and my own custom terrain model mesh creator was doing it the other way. I am sort of a n00b at terrains, so I had no idea what was happening. LOL

The easiest way I found to see if they were both the same was to draw both the BEPU ModelDrawer terrain and your own custom terrain model/mesh/whatever at the same time using wireframe mode for both. Make a note of the way it looks and then turn off one of them and start the game again. If they look the same, then you might be good to go (assuming you have scaled and translated your custom terrain model correctly). If not, you should try using the alternate QuadTriangleOrganization for the BEPU terrain physics object. Below are some examples of the way it should look and the way it should not look. :)

Correct!
Image

Incorrect!
Image

NOTE! Both of the above images were drawn by rendering the 2 wireframe terrains on top of each other. The correct image looks different because the triangles that make up the terrain are the same on both terrains/models, so they line up perfectly with each other (overlapping lines appear as one). The incorrect image appears to have like twice as many triangles because the two terrains are not using the same organization and the triangles are backwards on one of them. If you don't use the correct organization, your heights will be all messed up because each triangle will get its starting position from the wrong side of the adjacent triangle than it should be getting it from. Hope that made sense... :shock:
Post Reply