clamp camera + pi

This commit is contained in:
2023-06-06 17:15:44 +02:00
parent e984ed9085
commit c95c8b7fde
3 changed files with 7 additions and 4 deletions

View File

@@ -4,6 +4,8 @@
namespace td {
static constexpr float PI = 3.14159265358979323846264338327950288f;
template<typename T>
struct Vec2 {
union {

View File

@@ -19,13 +19,14 @@ struct Camera {
Vec3f CamPos {0, CamDistance, 0};
Vec2f CamLook {};
float m_Yaw = -3.141592653f / 2.0f;
float m_Pitch = -3.141592653f / 2.0f - 0.0000001f;
float m_Yaw = -PI / 2.0f;
float m_Pitch = -PI / 2.0f + 0.0000001f;
};
class Renderer {
public:
static constexpr float m_AnimationSpeed = 2.0f;
static constexpr float m_MouseSensitivity = 100.0f;
struct Model {
GL::VertexArray* vao;

View File

@@ -93,8 +93,8 @@ void Renderer::SetZoom(float zoom) {
}
void Renderer::SetCamMovement(const Vec2f& mov) {
m_Camera.m_Pitch -= mov.y / 50.0f;
m_Camera.m_Yaw += mov.x / 50.0f;
m_Camera.m_Pitch = std::clamp(m_Camera.m_Pitch - mov.y / m_MouseSensitivity, -PI / 2.0f + 0.0000001f, -PI / 12.0f );
m_Camera.m_Yaw += mov.x / m_MouseSensitivity;
SetCamLook(m_Camera.CamLook);
}