2015-01-04 6 views
1

안녕하세요 btCompoundShape, 에 문제가 있습니다. 2 실린더에서 모양을 만들지 만, 내 응용 프로그램을 실행할 때 compundshape 3 항목 것으로 보인다. 누구나 이유가 무엇입니까?btCompoundShape 여분의 모양을 추가했습니다

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

나는 그래픽 모델을로드하지 않습니다 나는 모양을 추가 할 곳은 내 코드입니다

enter image description here

이 작은 것은 우는 모양이 모든 것을 파괴 ... : 나는 영상과 코드를 추가 정확한 물리 형태를보기 위해.

답변

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; 
관련 문제