rotating bodies

Post Reply
wolverineun
Posts: 2
Joined: Fri Jan 06, 2012 7:28 pm

rotating bodies

Post by wolverineun »

I'm trying to simulate bodies that are stacked and has a 6d0f constraint that lets you rotate it
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);
}
and then when i make my object pickup
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));
                        }
                        
                    }
                    
                   
                }
if these is not the way to go please tell me what should i do.
I appreciate any help
Post Reply