#pragma once

#include <GLFW/glfw3.h>

struct Vec3 {
    float x, y, z;
};

class Camera {
public:
    Vec3 position{0.0f, 20.0f, 0.0f};

    // Current gravity "up" direction (points away from planet center).
    // Updated every frame by App before physics.
    Vec3 worldUp{0.0f, 1.0f, 0.0f};

    // Actual camera facing direction (world space, normalized).
    // Replaces yaw/pitch: rotated via Rodrigues around worldUp/right.
    Vec3 orientForward{0.0f, 0.0f, -1.0f};

    float moveSpeed = 4.0f;
    float mouseSensitivity = 0.1f;

    // Fly-mode movement using worldUp as the vertical axis.
    void update(GLFWwindow* window, float dt);

    // Rotate orientForward based on mouse delta (gravity-aware yaw/pitch).
    void processMouse(double xoffset, double yoffset);

    Vec3 forward() const;
    Vec3 right()   const;
    Vec3 up()      const; // actual camera up (perpendicular to forward & right)

    void buildViewMatrix(float out[16]) const;
    // Rotation-only view matrix (zero translation) — used for camera-relative rendering.
    void buildViewRotationMatrix(float out[16]) const;
};
