so desired result is: have some abstract object(like btCompoundObject), attach some primitives(preferably positioned by offset from compound object) to it, simulate physics, get resulting object transofrmation, not child geometry(unacceptable, useless in most cases), but whole object transformation, custom render.
how i try to do stuff:
init:
Code: Select all
//Bullet World
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
overlappingPairCache = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, Gravity, 0));
for(unsigned int f = 0; f < 1000; f++)
{
if(!physObjects[f].Enabled)
continue;
physObjects[f].compoundShape = new btCompoundShape();
for(unsigned int d = 0; d < 16; d++)
{
if(physObjects[f].SubGeom[d].Enabled)
{
//Init Shape
btCollisionShape* tShape;
if(physObjects[f].SubGeom[d]._Type == 0)//box
tShape = new btBoxShape(btVector3(physObjects[f].SubGeom[d].Size.x, physObjects[f].SubGeom[d].Size.y, physObjects[f].SubGeom[d].Size.z));
else //sphere
tShape = new btSphereShape(physObjects[f].SubGeom[d].Size.x);
if(!physObjects[f].Static)
tShape->calculateLocalInertia(physObjects[f].Mass, btVector3(0,0,0));
//Child geometry offset
btTransform tTransform;
tTransform.setIdentity();
tTransform.setOrigin(btVector3(physObjects[f].SubGeom[d].Pos.x, physObjects[f].SubGeom[d].Pos.y, physObjects[f].SubGeom[d].Pos.z));
if(physObjects[f].SubGeom[d]._Type == 0)
tTransform.setRotation(physObjects[f].SubGeom[d].Rot);
physObjects[f].compoundShape->addChildShape(tTransform, tShape);
}
}
btTransform gTransform;
//Whole object transformation
gTransform.setIdentity();
gTransform.setOrigin(btVector3(physObjects[f].Pos.x, physObjects[f].Pos.y, physObjects[f].Pos.z));
gTransform.setRotation(physObjects[f].Rot);
btDefaultMotionState* myMotionState = new btDefaultMotionState(gTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(physObjects[f].Mass, myMotionState, physObjects[f].compoundShape, btVector3(0,0,0));
physObjects[f].body = new btRigidBody(rbInfo);
//kinematic
if(physObjects[f].Static)
{
physObjects[f].body->setCollisionFlags(physObjects[f].body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
physObjects[f].body->setActivationState(DISABLE_DEACTIVATION);
}
//add the body to the dynamics world
dynamicsWorld->addRigidBody(physObjects[f].body);
}
Code: Select all
dynamicsWorld->stepSimulation(1.f/60.f, 10);
and render(removed unnecessary stuff):
Code: Select all
//in physObjects
body->getMotionState()->getWorldTransform(bTransform);
bTransform.getOpenGLMatrix(R);
glMultMatrixf(R);
for(unsigned int f = 0; f < 16; f++)
{
if(SubGeom[f].Enabled)
{
if(SubGeom[f]._Type == 0)
{
glPushMatrix();
//Child shape transform
glTranslatef(SubGeom[f].Pos.x, SubGeom[f].Pos.y, SubGeom[f].Pos.z);
glRotatef(SubGeom[f].Rot.x, 1, 0, 0);
glRotatef(SubGeom[f].Rot.y, 0, 1, 0);
glRotatef(SubGeom[f].Rot.z, 0, 0, 1);
glScalef(SubGeom[f].Size.x, SubGeom[f].Size.y, SubGeom[f].Size.z);
//Draw Cube
glSolidCube(1.0);
glPopMatrix();
}
else
{
glPushMatrix();
//Child shape transform
glTranslatef(SubGeom[f].Pos.x, SubGeom[f].Pos.y, SubGeom[f].Pos.z);
//Draw Sphere
gluSphere(gluq, SubGeom[f].Size.x, 32, 32);
glPopMatrix();
}
}
}
So i would be very glad if you don't mind spending your time on explaining what am i doing wrong and how it meant to work or point out actually acceptable documentation.