camera yaw and pitch

This commit is contained in:
2023-06-05 13:50:45 +02:00
parent 22e62df04d
commit a4fb56b549
2 changed files with 11 additions and 1 deletions

View File

@@ -16,6 +16,9 @@ struct Camera {
Mat4f InvProjectionMatrix;
Vec3f CamPos;
float m_Yaw = -3.141592653f / 2.0f;
constexpr static float m_Pitch = -3.141592653f / 2.0f + 0.0000001f;
};
class Renderer {

View File

@@ -97,8 +97,15 @@ void Renderer::SetCamMovement(const Vec2f& mov) {
}
void Renderer::SetCamPos(const Vec3f& newPos) {
Vec3f front = {
std::cos(m_Camera.m_Yaw) * std::cos(m_Camera.m_Pitch),
std::sin(m_Camera.m_Pitch),
std::sin(m_Camera.m_Yaw) * std::cos(m_Camera.m_Pitch)
};
m_Camera.CamPos = newPos;
m_Camera.viewMatrix = maths::Look(m_Camera.CamPos, {0, -1, -0.000000001}, {0, 1, 0});
m_Camera.viewMatrix = maths::Look(m_Camera.CamPos, front, {0, 1, 0});
m_Camera.InvViewMatrix = maths::Inverse(m_Camera.viewMatrix);
m_WorldShader->Start();
m_WorldShader->SetViewMatrix(m_Camera.viewMatrix);