Overflow in AABB

skol81
Posts: 4
Joined: Wed Dec 02, 2009 8:32 am

Overflow in AABB

Post by skol81 »

Hi,

I am currently writing a Collada parser for a robot simulator and I am working on the constraint parsing right now. When creating Hinge and Slider constraints my objects are disappearing from the scene. I created a simple example that includes basically the same code as the Collada parser (see below). You can simply add it to the ConstraintDemo for instance.

When I start this simple example I get an AABB overflow error. However, when I remove the hinge constraint, it works.

I am really stuck here and would appreciate any help. I checked the forum and I saw that many AABB overflows are due to uninitialized transforms. However, I checked and could not find the bug in my code.

Code: Select all

#if 1
	{
		btCollisionShape* boxShapeA = new btBoxShape(btVector3(btScalar(2.0), btScalar(1.0), btScalar(3.0)));
		btCollisionShape* boxShapeB = new btBoxShape(btVector3(btScalar(2.0), btScalar(1.0), btScalar(3.0)));

        btRigidBody::btRigidBodyConstructionInfo infoA(0, NULL, boxShapeA);
        btTransform frameA;
        frameA.setIdentity();
        frameA.setOrigin(btVector3(10, 10, 0));
        infoA.m_startWorldTransform = frameA;
        btRigidBody* bodyA = new btRigidBody(infoA);
        m_dynamicsWorld->addRigidBody(bodyA);

        btRigidBody::btRigidBodyConstructionInfo infoB(1.0, NULL, boxShapeB);
        btTransform frameB;
        frameB.setIdentity();
        frameB.setOrigin(btVector3(0, 10, 0));
        infoB.m_startWorldTransform = frameB;
        btRigidBody* bodyB = new btRigidBody(infoB);
        btVector3 localInertia(0.0, 0.0, 0.0);
        boxShapeB->calculateLocalInertia(1.0 / bodyB->getInvMass(), localInertia);
        std::cout << localInertia.getX() << ", " << localInertia.getY() << ", " << localInertia.getZ() << std::endl;
        bodyB->setMassProps(1.0 / bodyB->getInvMass(), localInertia);
        m_dynamicsWorld->addRigidBody(bodyB);

        btTransform frameInA, frameInB;
        frameInA.setIdentity();
        frameInB.setIdentity();
        frameInA.setOrigin(btVector3(-5, 0, 0));
        frameInB.setOrigin(btVector3(5, 0, 0));
        btHingeConstraint* hinge = new btHingeConstraint(*bodyA, *bodyB, frameInA, frameInB, true);
        m_dynamicsWorld->addConstraint(hinge, true);
        hinge->setDbgDrawSize(btScalar(7));
	}
#endif
RESOLVED
I found the problem. I have to call updateInertiaTensor() after the setMassProps() call. Should this call maybe added automatically to setMassProps()? Would this make sense or are there any implementation-specific reasons why it's separated?