2015-01-04 42 views
1

您好我有一個問題,btCompoundShape, 我從2個氣瓶打造成型,但是當我跑我的應用程序,它似乎是在compundshape 3項。 任何人有一個想法,爲什麼? 我添加圖片和代碼: enter image description herebtCompoundShape添加了額外的形狀

這個小東西波紋形狀摧毀一切......

這是我的代碼,我添加形狀:

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; 
} 

我不加載圖形模型準確地看到物理形態。

回答

2

我明白了,你想知道爲什麼有第三套軸。這是複合形狀的中心。嘗試在變換中不使用x y z,直到您創建默認運動狀態。

這種方式,子對象位置是相對於該化合物和化合物軸將對象的附近。事實上,因爲其中一個對象現在將在0,0,0,我希望你不會看到第三個軸。但是如果你這樣做,它至少會和其他人保持一致的距離。

btTransform t; //position and rotation 
t.setIdentity(); 
//edit here (1/3): 
t.setOrigin(btVector3(0, 0, 0)); 
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(); 
//edit here (2/3): 
t.setOrigin(btVector3(0, 2.7, 0)); 
bolw->addChildShape(t, cylinder2); 
btVector3 inertia(0,0,0); 
btScalar masses[2] = { mass,mass/2}; 
bolw->calculatePrincipalAxisTransform(masses,t,inertia); 
t.setIdentity(); 
//edit here (3/3): 
t.setOrigin(btVector3(x, y, z)); //put it to x,y,z coordinates 

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;