我是子弹新手,我可能有一个基本问题。我试图模拟弓形销坠落,但它们在坠落后会自行爬起,没有任何外力。
我想知道我的错误在哪里,你们中的任何人都可以帮忙,我将不胜感激。
这是一个显示发生了什么的视频: https ://www.sendspace.com/file/78tncr
这是我添加地板的方式:
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);
这就是我添加bolwing pin的方式:
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;
}
我尝试改变销钉的形状,质量,摩擦和恢复,但没有任何帮助,有没有办法改变质心,也许会有所帮助?