嗨,我对 btCompoundShape 有疑问,我从 2 个圆柱体创建形状,但是当我运行我的应用程序时,它似乎是 3 个 compundshape 项目。有人知道为什么吗?我添加图片和代码:
这个波纹状的小东西摧毁了一切……
这是我添加形状的代码:
btRigidBody* Okno::addBolw(float x,float y,float z,float mass)
{
btTransform t; //position and rotation
t.setIdentity();
t.setOrigin(btVector3(x,y,z)); //put it to x,y,z coordinates
btCylinderShape * cylinder1 = new btCylinderShape(btVector3(1,1.7,1));
btCylinderShape * cylinder2 = new btCylinderShape(btVector3(0.5, 1, 0.5));
btCompoundShape * bolw = new btCompoundShape();
bolw->addChildShape(t,cylinder1);
t.setIdentity();
t.setOrigin(btVector3(x,y+2.7,z));
bolw->addChildShape(t, cylinder2);
btVector3 inertia(0,0,0);
btScalar masses[2] = { mass,mass/2};
bolw->calculatePrincipalAxisTransform(masses,t,inertia);
t.setIdentity();
btMotionState* motion=new btDefaultMotionState(t); //set the position (and motion)
btRigidBody::btRigidBodyConstructionInfo info(mass*2,motion,bolw,inertia); //create the constructioninfo, you can create multiple bodies with the same info
btRigidBody* body=new btRigidBody(info); //let's create the body itself
body->setFriction(1);
body->setRestitution(0);
world->addRigidBody(body); //and let the world know about it
bodies.push_back(body); //to be easier to clean, I store them a vector
return body;
}
我不是故意加载图形模型来准确查看物理形状。