around the X axis. When i move the first one it makes the other boxes rotate,
but when they come to rest and i try to move then in the oposite direction it does not work.
this code create the bodies:
Code: Select all
btCollisionShape* boxShape = new btBoxShape(btVector3(halfW,halfH,halfD));
for (int i=0;i<numBodies;i++)
{
btTransform bodyTransform;
bodyTransform.setIdentity();
bodyTransform.setOrigin(btVector3(0,-27+i*halfH,0));
btScalar mass(10.);
bool isDynamic = (mass != 0.f);
btVector3 localInertia;
if (isDynamic)
boxShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(bodyTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,boxShape,localInertia);
btRigidBody* boxBody=new btRigidBody(rbInfo);
boxBody->setActivationState(DISABLE_DEACTIVATION);
sBoxBodies.push_back(boxBody);
sDynamicsWorld->addRigidBody(boxBody);
btTransform frameInB;
frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(btScalar(0), btScalar(-halfH), btScalar(0.)));
btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*boxBody, frameInB, true);
pGen6DOF->setLimit(0, btScalar(0.), btScalar(0.));
pGen6DOF->setLimit(1, btScalar(0.), btScalar(0.));
pGen6DOF->setLimit(2, btScalar(0.), btScalar(0.));
pGen6DOF->setLimit(3, btScalar(0.), btScalar(SIMD_PI));
pGen6DOF->setLimit(4, btScalar(0.), btScalar(0.));
pGen6DOF->setLimit(5, btScalar(0.), btScalar(0.));
sDynamicsWorld->addConstraint(pGen6DOF);
}
i have these code to rotate the selected body
Code: Select all
sDynamicsWorld->rayTest(CameraPosition, Ray, rayCallback);
if (rayCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
if (body)
{
body->setActivationState(DISABLE_DEACTIVATION);
if(oldy > TouchScreen->LocationYTouchesMoved)
{
body->applyTorque(btVector3(25000,0,0));
}
else
{
body->applyTorque(btVector3(-25000,0,0));
}
}
}
I appreciate any help