Triangle/TriangleShape location issue

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Triangle/TriangleShape location issue

Post by JusTiCe8 »

Hi and happy new year,

I play with Triangle(Shape)s and I get a big issue: despite giving the three vertices that define the triangle, and so it's location in space, triangle are not located in the expected place (which may have been to be defined more precisely).
Knowing the specificity of the triangle, which is designed by its three vertices for both size AND position, whereas other convex shapes are by design "position-less", ie: sphere or radius r, box of size w x l x h, etc.

TriangleShape constructor does:

Code: Select all

Vector3 center;
            var shape = new TriangleShape(v1, v2, v3, out center);
            Initialize(new ConvexCollidable<TriangleShape>(shape));
            Position = center;
which is bad. Because: "computing" ourselves triangle's center is very hard and uncommon, especially when working with primitives, which assemble triangle WHERE they're defined.
So building compound entity as we do with primitives just failed, because all triangles are stacked in a big mess located on origin of the compound entity.

Here is an example of two triangles defined as:

Code: Select all

Triangles.Add(new CompoundShapeEntry(new TriangleShape(new Vector3(-5, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 5))));
Triangles.Add(new CompoundShapeEntry(new TriangleShape(new Vector3(-5, 0, 0), new Vector3(-5, 0, 5), new Vector3(0, 0, 5))));
in a compound entity located in (0, 20, 0)

That should be defined a quad, instead, we've got a star !
Image

It is too far complicated to additionally get the right center coordinates and to either use AfineTransform in CompoundShapeEntry or, if possible, add it to the TriangleShape constructor.

What do you think about this ?
Is it possible to change that to handle the specific nature of triangle in constructor of TriangleShape ?
Attachments
TrianglesA.zip
a little demo to try (initially want to build a square based pyramid)
(579 Bytes) Downloaded 344 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Triangle/TriangleShape location issue

Post by Norbo »

It sounds like this would do the trick:

Code: Select all

        CompoundShapeEntry GetTriangleEntry(Vector3 a, Vector3 b, Vector3 c)
        {
            Vector3 center;
            var shape = new TriangleShape(a, b, c, out center);
            return new CompoundShapeEntry(shape, center);
        }
TriangleShapes are just like all the other shapes in this regard.

More pressingly, it turns out the triangle shape was incorrectly using a stub for its inertia tensor, so individual triangles actually had infinite inertia, oops. Fixed now.
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Triangle/TriangleShape location issue

Post by JusTiCe8 »

Thanks.

And glad to have accidentally help ;).

Does triangle have been intended to be public or just for internal use only ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Triangle/TriangleShape location issue

Post by Norbo »

It's supposed to be public, though its use is expected to be exceptionally rare. There's almost always another way that works better. (I think that bug snuck in during the shape constructor refactoring some months ago, and since direct use of TriangleShapes is so rare, no one ran into it.)
JusTiCe8
Posts: 52
Joined: Mon Jun 01, 2015 9:02 am

Re: Triangle/TriangleShape location issue

Post by JusTiCe8 »

ok, do you have any example of those other way which works better ?
I initially want to use them to make kind of truncated square based pyramid, and this is the easiest way I found to do it (I don't think using the modeldataextractor thing is good). I also plan to make a triangle "sandwich" shape (or a half box, no it's not a cheap chinese version of a xbox :P).

By the way, and quite off-topic, I play a bit with Minkowski sum and I wonder is in BEPU you have made what they are supposed to be as I read a definition of it to be the sum of of two sets the position vectors (see the wikipedia page), those shapes could intersect/overlap OR NOT, whereas in BEPU, it more likely to be a "mere" boolean intersection (example of the rounded corners box) as they are forced to share the same origin. Am I wrong ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Triangle/TriangleShape location issue

Post by Norbo »

I initially want to use them to make kind of truncated square based pyramid, and this is the easiest way I found to do it (I don't think using the modeldataextractor thing is good). I also plan to make a triangle "sandwich" shape (or a half box, no it's not a cheap chinese version of a xbox :P).
If they're not hollow, a ConvexHullShape (or perhaps more than one in a CompoundShape if necessary for concavity) would be a good choice.

If they really need to be actual triangle meshes, a MobileMeshShape would be better than a bunch of TriangleShapes in a CompoundShape.
By the way, and quite off-topic, I play a bit with Minkowski sum and I wonder is in BEPU you have made what they are supposed to be as I read a definition of it to be the sum of of two sets the position vectors (see the wikipedia page), those shapes could intersect/overlap OR NOT, whereas in BEPU, it more likely to be a "mere" boolean intersection (example of the rounded corners box) as they are forced to share the same origin. Am I wrong ?
MinkowskiSumShape doesn't bother including the position of the subshapes because its only effect is to translate the resulting minkowski sum. It has no effect at all on the actual shape. You can play with a visualization here: http://gerardmeier.com/minkowski-sums (technically this is A+(-B), as is common in collision detection, but the same principle applies)

Once upon a time, I think I had support for subshape positions, but I am pretty sure no one ever used anything but (0,0,0) for positions in practical code (if they used MinkowskiSumShapes at all). The resulting translation is just confusing in most cases, and there is virtually never a use for it. And, in those incredibly rare cases where it is useful, it is still trivial to set the position accordingly.

Boolean operations are something different. There is no single invocation of a boolean operation on volumes A and B which can express a minkowski sum of A and B in general.
Post Reply