- 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.

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());
