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);
}
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);
Can you tell me where is my silly error?
Many thanks!
Bye