Rotation + Translate causes camera shakes

UPDATE: I have found that the delays happen when i press a key in the keyboard and move the mouse at the same time, how can i solve it?

I checked it setting a constant speed to the camera(going forward) and disabled the interactions with the keyboard. The lag didnt appear when i was moving forward while rotating the camera, but happened when i pressed keys(with no functions because i disabled them) while i was moving the mouse

I will let here my initial question, but the problem is not because of the code, it is about the keyboard + mouse use. IGNORE WHAT FOLLOWS

=======================================================================

I am running out of ideas of what could be the reason for this, but when i move and rotate the camera an insane lag appers(but it doesnt show of in the FPS, they are always around 120). It doesnt happen when i just rotate the camera or translate it.

Video to show the problem:

What could be the reason for this? I tried:

• To use raw input, but because it didnt solve it i rolled back.
• Rewrite the camera view calculations.

I am using Vulkan, at the moment on Windows.

Ill include some code:

View update:

void Camera::UpdateView()
{
glm::mat4 rotate = glm::mat4_cast(GetRotation());
glm::mat4 translate = glm::mat4(1.0f);
translate = glm::translate(translate, -GetPosition());

Matrices.view = rotate*translate;

glm::mat4 matInverseView = glm::inverse(Matrices.view);
forward = glm::normalize(glm::vec3(matInverseView[2]));
right = glm::normalize(glm::vec3(matInverseView[0]));
}


Pitch and yaw update:

void Camera::ActiveMouseUpdate(Input * input, double deltaTime)
{
if (input->MouseMoved())
{
yaw -= MOUSE_SENSIBILITY * input->GetMouseSpeed().x*deltaTime;
pitch += MOUSE_SENSIBILITY * input->GetMouseSpeed().y*deltaTime;
CalculateComponents();
cameraChanged = true;
}

}


Rotation update:

void Camera::CalculateComponents()
{
glm::quat qPitch = glm::angleAxis(pitch, glm::vec3(1, 0, 0));
glm::quat qYaw = glm::angleAxis(yaw, glm::vec3(0, 1, 0));
glm::quat qRoll = glm::angleAxis(roll, glm::vec3(0, 0, 1));
glm::quat orientation = glm::normalize(qPitch * qYaw*qRoll);

SetRotation(orientation);
}


Movement:

void Camera::PassiveKeyboardUpdate(Input * input, double deltaTime)
{
cameraChanged = false;

glm::vec3 pos = GetPosition();

if (input->isKeyDown(KEY_W))
{
pos -= (float)deltaTime*forward*speed;
cameraChanged = true;
}
if (input->isKeyDown(KEY_S))
{
pos += (float)deltaTime*forward*speed;
cameraChanged = true;
}
if (input->isKeyDown(KEY_D))
{
pos += (float)deltaTime*right*speed;
cameraChanged = true;
}
if (input->isKeyDown(KEY_A))
{
pos -= (float)deltaTime*right*speed;
cameraChanged = true;
}
}


How my loop works:

void CoreEngine::Loop()
{
while (renderer->Run())
{
UpdateFPS();
UpdateInput();
Update();
Draw();
}
}


Update input:

void CoreEngine::UpdateInput()
{
input->Update();
if(input->KeyboardChanged())
root->ActiveKeyboardUpdate(input, deltaTime);
root->PassiveKeyboardUpdate(input, deltaTime);
if (input->MouseChanged())
root->ActiveMouseUpdate(input, deltaTime);
}


Update:

void CoreEngine::Update()
{
root->Update(deltaTime,enlapse);
}


Draw:

void CoreEngine::Draw()
{
renderer->PrepareFrame();
renderer->Draw();
renderer->DrawTextOverlay();
renderer->PresentDraw();
renderer->UpdateUniformBuffers(false);
}


Root is the root node of my object tree which call all objects(nodes) attached updates, which nodes also call their own nodes updates.

UPDATE: I found that if i change this:

case WM_MOUSEMOVE:
if (captureWindow)
{
mousePosition.x = LOWORD(lParam);
mousePosition.y = HIWORD(lParam);
mouseChangeState = true;
if (forcedMouseMove)
{
lastUpdatePosition = mousePosition;
forcedMouseMove = false;
}
else
SetCursorCenter();
}
break;


For this:

case WM_MOUSEMOVE:
if (captureWindow)
{
mousePosition.x = LOWORD(lParam);
mousePosition.y = HIWORD(lParam);
mouseChangeState = true;
if (forcedMouseMove)
{
lastUpdatePosition = mousePosition;
forcedMouseMove = false;
}
else if(glm::abs(mousePosition.x + screen.left - Middle.x ) > 400 || glm::abs(mousePosition.y + screen.top - Middle.y) > 300)
SetCursorCenter();
}
break;


Where:

void Input::SetCursorCenter()
{
SetCursorPos(Middle.x, Middle.y);
ForceMove(true);
}

• Middle: Is the center of the window
• screen: Is the rectangle that contains the window.

The effect is less appreciable, but still there(i still want to solve this less appreciation). I also interpolated the movement, rotation and forward and right vectors.

• Sometimes if your camera is updating out of step with other objects in your world, you can get a "judder" effect that looks like a choppy framerate, even if each part is updating frequently. For instance, if your character's walking and your camera rotation don't always happen in the same order, you might sometimes get two rotation steps between position updates or vice versa. This is especially prone to happen if your character movement is using a fixed timestep and the camera uses a variable timestep without interpolating. Can you show us the translation part & how your loop works? – DMGregory May 20 '17 at 14:06
• Thank you for reply. I updated the post if you need more information just ask for it. About the character, there is no character attached to the camara, right now it is just a free cam. I dont use interpolation, can it be the cause? – Haruko May 20 '17 at 16:16
• I interpolated it and it continue happening, i changed: orientation = glm::mix(GetRotation(), orientation, 0.5f); In the UpdateView method. – Haruko May 20 '17 at 17:12
• @DMGregory i added a video to show you how it looks like. Hope it helps. – Haruko May 20 '17 at 18:28
• @IanYoung deltaTime is not the right interpolation weight either. Approaching by 50% each tick is an exponential change, so we can't time correct it the same way we would a linear change. I show a formula for time-correcting an exponential blend in this answer. For maximum correctness we'd want a Slerp here, but the difference should be unnoticeably small for typical camera moves. – DMGregory May 30 '17 at 18:56

    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))