Rotation + Translate causes camera shakes
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.
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;
pitch = glm::clamp(pitch, glm::radians(-85.0f), glm::radians(85.0f));
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));
//For a FPS camera we can omit roll
glm::quat orientation = glm::normalize(qPitch * qYaw);
orientation = glm::mix(GetRotation(), orientation, 0.5f);
//order matters,update camera_quat
SetRotation(glm::mix(GetRotation(),orientation,0.5f));
}
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;
}
}
Mouse input:
case WM_MOUSEMOVE:
if (captureWindow)
{
mousePosition.x = LOWORD(lParam);
mousePosition.y = HIWORD(lParam);
mouseChangeState = true;
if (forcedMouseMove)
{
lastUpdatePosition = mousePosition;
forcedMouseMove = false;
mouseChangeState = false;
}
else if(glm::abs(mousePosition.x + screen.left - Middle.x ) > 400 || glm::abs(mousePosition.y + screen.top - Middle.y) > 300)
SetCursorCenter();
}
break;
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.