I'm working on a flight simulator, but I'm stuck with my airplane orientation. I tried some things but noone worked correctly. This is what I have :
To be able to move it and roll it around himself, I need two vectors, forward and up, and use them to create quaternions I need for the rotation :
void Plane::Update()
{
m_position += ( m_forward * m_speed );
mat4 translation = translate( mat4( 1.0f ), m_position );
float angle = dot( vec3( 1.0f, 0.0f, 0.0f ), m_forward );
quat direction = angleAxis( acos( angle ), cross( vec3( 1.0f, 0.0f, 0.0f ), m_forward ) );
m_matrix = translation * mat4_cast( direction );
}
vec3( 1.0f, 0.0f, 0.0f ) is my model orientation. Note that in this code, I don't have quaternion for rolling the plane, because I first want to have a correct direction.
This works great, what doesn't work is when I want to make him taking off. To do that, I first get the right vector, then use it to create my quaternion with the angle I need, and I apply the rotation to the forward and up vector.
void Plane::FlyUp()
{
vec3 right = cross( m_forward, m_up );
quat temp = angleAxis( radians( 1.0f ), right );
m_up = temp * m_up;
m_up = normalize( m_up );
m_forward = temp * m_forward;
m_forward = normalize( m_forward );
}
Using debugger and an online vector visualizer, It seems to give me the good vectors, but the plane is rotating weirdly ( in fact, that's not even only rotating, he's scaled too for some reasons... ).
What am I doing/understanding wrong?
Edit :
To be more precise, here is screenshoots of what I have :

And what I'm trying to have, whatever the m_forward vector is pointing to :
