Offset Forward vector of object based on Rotation

| | August 6, 2015

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.

One Response to “Offset Forward vector of object based on Rotation”

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

Leave a Reply