I'm using the Bullet 3D physics engine in a iOS application running openGL ES 1.1

Currently I'm accepting info from the gyroscope to allow the user to "look around" a 3d world that follows a bouncing ball (note: it only takes in the yaw to look around 360 degrees). Im also accepting information from the accelerometer based on the tilt to push the ball. As of right now, to move forward, the user tilts the devise forward (using the accelerometer); to move to the right, the user tilts the devise to the right and so on. The forward vector is currently along it's local Z-axis.

The problem is that I want to change the ball bounce based on where the user has changed the view. If I change the view, the ball bounces in the fixed direction.

I want to change the forward facing direction so that when a user changes the view (say to the look at the right of the world, the user rotates the device), tilting the devise forward will result in a forward force in that direction.

Basically, I want the forward vector to take the rotation into consideration.

Sorry if I didn't explain the issue well enough, its kind of confusing to write down.


Figured out the answer for anyone who gets the same issue.

If you get your RigidBody's btTransform and then multiply it by your force btVector3 and subtract the RigidBody origin from that, the return will be your force relative to your object's orientation. Now just apply this as a centeralForce/Impulse and it goes in the new direction.

  • 1
    \$\begingroup\$ Don't multiply with the full btTransform, only multiply with it's 3x3 orientation matrix member btTransform::getBasis(), then you don't need to subtract the origin afterwards. \$\endgroup\$ – Maik Semder Nov 13 '12 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.