(1) When it comes to Euler angles my advice is: stay away from them when possible. My reasons are:
(a) There is no true "standard" for Euler angles. There are multiple ways to define them and the way they are used in game development doesn't even match with how Euler himself defined them. Therefore, if you compare how they are used in physics text books, engineering, game development, and whatever else you'll find discrepancies. Does the Bullet API use Euler angles the same way you do? If yes, then great. If not, headaches will ensue until you fully understand.
(b) Euler angles suffer from "gimbal lock" which is a zone of orientations where solving for Euler angles (however they are defined) from the rotation (either in Quaternion form or 3x3 Matrix form) becomes indeterminate because of a singularity.
(c) As a consequence of
(b) there are discontinuities in Euler angle values for objects that are experiencing smooth simple rotational motion. Derivatives in Euler space are meaningless.
In some cases (such as a Character whose axis is always aligned with "up") it becomes useful to talk about yaw + pitch + roll in that order. But I suggest you call these "yaw pitch roll" instead of "Euler angles". I don't have time right now to explain how I would proceed here but perhaps I'll find time later today to write it down.
(2) Your problem here is related to
(1)(a) through
(1)(c).
(3) Your problem here is related to
(1)(a) through
(1)(c).
(4) To apply "forward" motion in the local-frame of the object you first need to transform the local velocity to world frame.
btRigidBody::setLinearVelocity(v) expects
v to be in the world-frame. If "forward" is along the local z-axis then you would do something like:
Code: Select all
const btVector3 forward(0.0, 0.0, 1.0);
btVector3 localVelocity = speed * forward;
btTransform trans = body->getWorldTransform();
trans.setOrigin(btVector3(0.0, 0.0, 0.0)); // remove translation part so trans is just rotation
btVector3 worldVelocity = trans * localVelcocity;
body->setLinearVelocity(worldVelocity);
Note: I did not test that code so I don't know if it compiles or is even correct according to Bullet API.