I have a problem I’m tring to change the rotation of an odejava body by using a joystick. The problem is I think I’m getting Gimble Lock.
Here is my code:
private Matrix3f turn;
private Matrix3f pitch;
private Matrix3f roll;
/*
turn, pitch, roll are call in order
rot = the rotation being passed from the jostick to body
*/
void turn(float rot){
turn.setZero();
turn.rotY(rot);
}
void pitch(float rot){
pitch.setZero();
pitch.rotX(rot);
}
void roll(float rot){
roll.setZero();
roll.rotZ(rot);
rotate(); // turn, pitch, roll done now call rotate() to apply them
}
private void rotate(){
Matrix3f m = new Matrix3f();
m.setZero();
m.mul(turn, pitch);
m.mul(m, roll);
m.mul(m, shipBody.getRotation());
shipBody.setRotation(m);
}
This code works if I only use 1 axis but as soon as I add in the 2 other axis it gets totaly confused and rotates all wrong. I’ve been doing a bit of reading into gimble lock but havnt found a solution yet. Does somone have a method that will fix this problem.