How can i Change position of a convex hull after creation?
after i do
add points
how can i move/ rotate the entire hull?
Change position of a convex hull after creation
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Change position of a convex hull after creation
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.
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.
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Change position of a convex hull after creation
I want to set world transform really stupid so if you could can you give me an example of the world transform please
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Change position of a convex hull after creation
Is there a simple way to center the pivot/axis of convex hull?
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Change position of a convex hull after creation
Do you mean its center of mass ?johnsonalpha wrote:Is there a simple way to center the pivot/axis of convex hull?
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.
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Change position of a convex hull after creation
yeah the abb bounding box is what i need but i could find a simple example