Bullet Physics bounding box alignment[Fixed]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Bullet Physics bounding box alignment[Fixed]

Postby jwatson1993 » Tue Jan 17, 2012 10:46 pm

I'm trying to get it to where the position of a btRigidBody is the same as the center of a mesh's bounding box. In other words, for every timestep I want to set the position of the node in a way that the edges of its bounding box matches up with the bounding box of the physics object. I have what I call a "debugNode" which is a cubenode that is scaled to the same size as the original node's bounding box, and since its (0,0,0) local position is its center, I use that to know where the physics object is. Problem is, I can't get the original node to position correctly. Here's the relevant code:

cpp Code: Select all
 
       
        btVector3 Point = collObj->getCenterOfMassPosition();//collObj is the btrigidbody
                debugNode->setPosition(core::vector3df((f32)Point.getX(), (f32)Point.getY(), (f32)Point.getZ()));
                aabbox3df box = getMesh()->getBoundingBox();
                vector3df center = box.getCenter();
                vector3df poz = getPosition();
                vector3df poz2 = debugNode->getPosition();
                setPosition(poz2+=debugNode->getRotation().rotationToDirection(center)*offset2);//offset2 is a value that is changed during runtime by the z/c keys, but it hasn't worked so far.
                // Set rotation
                btVector3 EulerRotation;
                myGame->QuaternionToEuler(collObj->getOrientation(), EulerRotation);//the code is on the wiki page for first time bullet/irrlicht integration
                debugNode->setRotation(core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
                setRotation(debugNode->getRotation());
 

The scale and rotation are spot on, but I can't position it right. Sorry to bug you guys for help with math, but I've been tinkering with this code for a couple days and I can't get it anywhere.
Image

Edit:
Fixed it. This code accomplishes what I wanted:
cpp Code: Select all
 
                btVector3 Point = collObj->getCenterOfMassPosition();
                debugNode->setPosition(core::vector3df((f32)Point.getX(), (f32)Point.getY(), (f32)Point.getZ()));      
                vector3df poz2 = debugNode->getPosition();
                setPosition(poz2);
                aabbox3df box = getMesh()->getBoundingBox();
                vector3df center = box.getCenter();
                center*=getScale();
                vector3df poz = debugNode->getRotation().rotationToDirection(center);
                setPosition(poz2-poz);
                btVector3 EulerRotation;
                myGame->QuaternionToEuler(collObj->getOrientation(), EulerRotation);
                debugNode->setRotation(core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
                setRotation(debugNode->getRotation());
 
jwatson1993
 
Posts: 31
Joined: Fri Nov 04, 2011 12:15 am

Return to Beginners Help

Who is online

Users browsing this forum: suliman and 1 guest