Change position of a convex hull after creation

johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Change position of a convex hull after creation

Post by johnsonalpha »

How can i Change position of a convex hull after creation?

after i do

add points

how can i move/ rotate the entire hull?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Change position of a convex hull after creation

Post by drleviathan »

Do you want to change the transform of the body that uses the shape? If so, then you can just use btCollisionBody::setWorldTransform().

Or do you need to change the local transform of the btConvexHullShape itself? If this is the case then there are two ways to do it:

(1) Create an entirely new shape by transforming the input points and adding them to a new shape.

(2) Put the btConvexHullShape inside a btCompoundShape with a local transform.

Note that if you swap the shape out from under a btCollisionObject after it has been added to the simulation then you may introduce misbehavior (bad collisions, snagging) because the broadphase caches the axis-aligned bounding box (Aabb) of the object and assumes it will not change. To fix this you have to manually update its Aabb (e.g. call btCollisionWorld::updateSingleAabb(btCollisionObject*)) or remove/reinsert the object in the simulation, which will update the Aabb on insertion.
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Change position of a convex hull after creation

Post by johnsonalpha »

I want to set world transform really stupid so if you could can you give me an example of the world transform please :)
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Change position of a convex hull after creation

Post by johnsonalpha »

Is there a simple way to center the pivot/axis of convex hull?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Change position of a convex hull after creation

Post by Flix »

johnsonalpha wrote:Is there a simple way to center the pivot/axis of convex hull?
Do you mean its center of mass ?

Well I'd do that before feeding the vertices to the btConvexHullShape (although making a helper method that does that inside the btConvexHullShape itself shouldn't be too difficult).

The center of a (triangle) mesh can be calculated in two ways:
1) the Aabb (axis aligned bounding box) center (find the aabbmin/aabbmax - pretty simple, but search google for it - and C = (aabbmin+aabbmax)/2).
2) the "real" center of mass (assuming the body is made of an uniform material). To calculate this, you can use the volume integration formula by Stan Melax http://melax.github.io/volint.html (BTW: he recently posted an interesting video in this post: http://www.bulletphysics.org/Bullet/php ... =6&t=10526).

Once you get the center you need (I usually prefer method 1, that keeps the shape's aabb smaller) you must subtract it from all the vertices of the convex hull.

Hope it helps.
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: Change position of a convex hull after creation

Post by johnsonalpha »

yeah the abb bounding box is what i need but i could find a simple example