[ad_1]
I’m making an attempt to implement the gimbal lock repair described in this query, however I find yourself getting bizarre habits the place once I rotate on the X axis (or attempt to no less than) it rotates on each the X and Y axis on the similar time, however when i try to rotate on the Y axis nothing occurs in any respect.
I’m holding whole orientation in a quaternion and (making an attempt to) replace it with a rotation matrix constructed by ahead, proper, and up vectors. I’m deriving these vectors like so:
// From https://learnopengl.com/Getting-started/Camera
_forward.X = (float) (MathHelper.Cos(MathHelper.LevelsToRadians(_rotation.Y)) *
MathHelper.Cos(MathHelper.LevelsToRadians(_rotation.X)));
_forward.Y = (float) MathHelper.Sin(MathHelper.LevelsToRadians(_rotation.X));
_forward.Z = (float) (MathHelper.Sin(MathHelper.LevelsToRadians(_rotation.Y)) *
MathHelper.Cos(MathHelper.LevelsToRadians(_rotation.X)));
_forward.Normalize();
_right = Vector3.Cross(_forward, _worldUp).Normalized();
_up = Vector3.Cross(_right, _forward)
and updating the _rotation values like this:
public void RotateX(float rotation) {
_rotation.X += rotation * _sens;
}
public void RotateY(float rotation) {
_rotation.Y += rotation * _sens;
}
To get the rotation matrix I’m simply placing the three vectors right into a Matrix3 object:
var r1 = new Vector3(_right.X, _up.X, _forward.X);
var r2 = new Vector3(_right.Y, _up.Y, _forward.Y);
var r3 = new Vector3(_right.Z, _up.Z, _forward.Z);
var mat = new Matrix3(r1, r2, r3);
if (mat != _check) {
_orientation = Quaternion.FromMatrix(mat) * _orientation;
}
_orientation.Normalize();
after which I replace the orientation quaternion.
The _check
property is only a matrix that represents what ought to be created if there is no such thing as a change in rotation so _orientation
is not modified when it would not need to be.
This is a gif of what occurs once I simply use the RotateX operate, so it simply rotates on some bizarre axis. Any clue what I’m doing flawed? Am I initializing the rotation matrix flawed or is it one thing else fully?
[ad_2]