btCompoundShape добавил дополнительную форму

Привет у меня есть проблема с btCompoundShape,
Я создаю форму из 2 цилиндров, но когда я запускаю свое приложение, кажется, что в compundshape 3 элемента.
У кого-нибудь есть идея, почему?
Я добавляю картинку и код:
введите описание изображения здесь

Эта маленькая вещь ниже формы разрушит все …

Это мой код, где я добавляю форму:

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

Я не загружаю графическую модель специально, чтобы увидеть точно физическую форму.

1

Решение

Я понял, вы хотите знать, почему существует третий набор осей. Это центр сложной формы. Попробуйте не использовать 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;
2

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector