Rotate a btConvexHullShape via btCompoundShape problem.

Post Reply
Dox
Posts: 24
Joined: Thu Oct 18, 2018 5:16 pm

Rotate a btConvexHullShape via btCompoundShape problem.

Post by Dox »

Hello,

Normally, I build a btConvexHullShape from an HACD generated model like this:

Code: Select all

  
   //...Retrieve a geometry list from OpenSceneGraph....
   .....
   .....
   for(unsigned int i = 0; i < l_GeometryList.size(); i++) {
    osg::Vec3Array* l_GfxVertices = dynamic_cast<osg::Vec3Array*>(l_GeometryList[i]->getVertexArray());
    if(!l_GfxVertices) {
      continue;
    }

    btAlignedObjectArray<btVector3> l_PhyVertices;

    //Calc centroid
    btVector3 l_Centroid = btVector3(0,0,0);
    for(unsigned int i = 0; i < l_GfxVertices->size(); i++) {
      btVector3 l_Vertex((*l_GfxVertices)[i].x(), (*l_GfxVertices)[i].y(), (*l_GfxVertices)[i].z());
      l_Centroid += l_Vertex;
    }
    l_Centroid *= 1.f/(double(l_GfxVertices->size()));

    //Shift vertices around centroid
    for(unsigned int i = 0; i < l_GfxVertices->size(); i++) {
      btVector3 l_Vertex((*l_GfxVertices)[i].x(), (*l_GfxVertices)[i].y(), (*l_GfxVertices)[i].z());
      l_Vertex -= l_Centroid;
      l_PhyVertices.push_back(l_Vertex);
    }

    //Create the convex hull shape
    btConvexHullShape* l_ConvexHullShape = new btConvexHullShape(&(l_PhyVertices[0].getX()), l_PhyVertices.size());
    l_ConvexHullShape->setMargin(0.001f);

    btTransform l_PhyTransform;
    l_PhyTransform.setIdentity();
    l_PhyTransform.setOrigin(l_Centroid);
    
    btCompoundShape* l_PhyCompoundShape = new btCompoundShape();
    l_PhyCompoundShape->addChildShape(l_PhyTransform, l_ConvexHullShape);  
  }
This code basically works and place the convex hull in the correct position.

Now I need a rotation, so I have simple added the rotation to the l_PhyTransform (for example, after the l_PhyTransform.setOrigin(l_Centroid) line):

Code: Select all

      PhyQuaternion l_quat;
      l_quat.setEulerZYX(0, 0, M_PI_2);
      l_PhyTransform.setRotation(l_quat);
This code doesn't works as expected (for me): a simple convex shape rotation of 90° (on X). Instead, the rotation there is, but I can see a sort of "degenerated" mesh: some polygons are corrects, some others are like "deformed" and moved in weird position.

Can you tell me where is my silly error?

Many thanks!

Bye
Post Reply