So I am currently trying to create a space combat game and am currently working on the players movement (as well as the camera) but I have run into a problem with doing the rotation for the player.
The main goal is to have 6 degrees of freedom for the player but I am currently just working on yaw and pitch. I am using the mouse to control the rotation with mouse up and down changing pitch and mouse left and right controlling yaw. For this I have been trying to understand Quaternion and am currently using the axis angle method (with the glm library) but I have hit a problem.
I'm not sure if this is to do with a lack of understanding or some other factor,
Currently I can just change the pitch and yaw of the ship perfectly fine but say for example I was to have a pitch change of 90 degrees (so the ship was looking up) and was the to try and change the yaw of the ship, what would happen is the roll of the ship would change instead. the opposite would happen with the yaw being 90 degrees and then changing the pitch.
It feels like I'm not understanding something or maybe my code is incorrect. Any help with the problem or understanding more about Quaternion would be very appreciated.
code for creating the axis change
ynewquat = glm::quat();
xnewquat = glm::quat();
if(currentmouse.x < 540)
{
int rotate = -(540 - currentmouse.x);
glm::quat tempquad = glm::angleAxis((rotate * 0.002f) * deltaTs,glm::vec3(0,1,0));
xnewquat = tempquad;
}
if(currentmouse.x > 740)
{
int rotate = (currentmouse.x - 740);
glm::quat tempquad = glm::angleAxis((rotate * 0.002f) * deltaTs,glm::vec3(0,1,0));
xnewquat = tempquad;
}
if(currentmouse.y > 400)
{
int rotate = (currentmouse.y - 400);
glm::quat tempquad = glm::angleAxis((rotate * 0.005f) * deltaTs,glm::vec3(1,0,0));
ynewquat = tempquad;
std::cout<<rotate<<'\n';
}
if(currentmouse.y < 320)
{
int rotate = -(320 - currentmouse.y);
glm::quat tempquad = glm::angleAxis((rotate * 0.005f) * deltaTs,glm::vec3(1,0,0));
ynewquat = tempquad;
std::cout<<rotate<<'\n';
}
newquat = xnewquat * ynewquat;
player->Update(deltaTs,newquat);
Then in the player update function
void Gamemodelimported::Update(float deltaTs, glm::quat rotation)
{
currentrotation = rotation * currentrotation;
temp = currentrotation * direction;
glm::vec3 tempvel = temp * speed * deltaTs;
position += tempvel * deltaTs;
glm::mat4 RotationMatrix = glm::toMat4(currentrotation);
glm::mat4 translationmatrix = glm::translate(glm::mat4(1.0f), position);
_modelMatrix = translationmatrix * RotationMatrix;
}