btTransform transform; transform.setIdentity(); transform.setRotation(btQuaternion(btVector3(1, 0, 0), btRadians(45))); // rotate 45 degrees around x-axis btQuaternion rotation = transform.getRotation(); std::cout << "Rotation: (" << rotation.x() << ", " << rotation.y() << ", " << rotation.z() << ", " << rotation.w() << ")" << std::endl;
btRigidBody* body; // assume this is a pointer to a rigid body object btTransform transform = body->getWorldTransform(); btQuaternion rotation = transform.getRotation();This example retrieves the world transformation of a rigid body and retrieves its rotation as a quaternion using the getRotation() method. The quaternion can then be used to do further calculations or manipulate the object's orientation. In both examples, the btQuaternion and btVector3 classes are used, which are part of the Bullet Physics library as well.