我是新手,可能有一个基本问题。
我尝试模拟弓形销掉落,但它们掉落后,无需任何力即可自行站起来。
我想知道我的错误在哪里,你们谁能帮忙,我将不胜感激。
这是一段视频,显示发生了什么:
https://www.sendspace.com/file/78tncr
这是我添加floor的方式:
tTransform l;
l.setIdentity();
l.setOrigin(btVector3(0,0,0));
btStaticPlaneShape* plane=new btStaticPlaneShape(btVector3(0,1,0),0);
btMotionState* motion=new btDefaultMotionState(l);
btRigidBody::btRigidBodyConstructionInfo info(0.0,motion,plane);
btRigidBody* body=new btRigidBody(info);
world->addRigidBody(body);
bodies.push_back(body);
这就是我添加螺栓的方式:
btRigidbodyaddBolw (float x, float y , float z,float mass)
{
btTransform t;
t.setIdentity();
t.setOrigin(btVector3(x,y,z));
btTriangleMesh * tmptri= new btTriangleMesh();
//this is simply reading from std::vector, where I have vertex of a shape
for(int i=0;i<=faces.size()-3;i=i+3)
{
if(faces[i].wektor==-100)
{
i=i-2;
continue;
}
btVector3 vertex1(vertexy[faces[i].wektor].GetX(), vertexy[faces[i].wektor].GetY(), vertexy[faces[i].wektor].GetZ());
btVector3 vertex2(vertexy[faces[i+1].wektor].GetX(), vertexy[faces[i+1].wektor].GetY(), vertexy[faces[i+1].wektor].GetZ());
btVector3 vertex3(vertexy[faces[i+2].wektor].GetX(), vertexy[faces[i+2].wektor].GetY(), vertexy[faces[i+2].wektor].GetZ());
tmptri->addTriangle(vertex1, vertex2, vertex3);
}
btConvexShape *tmpshape = new btConvexTriangleMeshShape(tmptri);
btShapeHull *hull = new btShapeHull(tmpshape);
btScalar margin = tmpshape->getMargin();
hull->buildHull(margin);
btConvexHullShape* simplifiedConvexShape = new btConvexHullShape();
for (int i=0;i<hull->numVertices();i++)
{
simplifiedConvexShape->addPoint(hull->getVertexPointer()[i]);
}
delete tmpshape;
delete hull;
btMotionState * motion = new btDefaultMotionState(t);
btVector3 inertia(0,0,0);
if(mass!=0.0)
simplifiedConvexShape->calculateLocalInertia(mass,inertia);
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,simplifiedConvexShape,inertia);
btRigidBody* body=new btRigidBody(info);
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;
}
我尝试改变销钉的形状,质量,摩擦和恢复原状,但没有任何帮助,有什么方法可以改变质心,也许会有所帮助?
最佳答案
这是由于您的模型在保龄球杆的底部或附近具有枢轴点/变换原点。在Bullet中,刚体变形是重心,因此您所看到的是重的重心,可以通过重力进行自我校正,从而将销钉竖直拉起。
您有两种选择:
关于collision-detection - 子弹物理质心和奇怪的物体 react ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27712973/