2025-04-01 16:53:23 +00:00
|
|
|
#ifndef CAMERA_H
|
|
|
|
#define CAMERA_H
|
|
|
|
|
|
|
|
#include "Component.h"
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
2025-04-02 00:19:53 +00:00
|
|
|
#include <yaml-cpp/yaml.h>
|
2025-04-01 16:53:23 +00:00
|
|
|
|
|
|
|
// A simple Camera component that inherits from Component.
|
|
|
|
class Camera : public Component {
|
|
|
|
public:
|
|
|
|
Camera();
|
|
|
|
virtual ~Camera();
|
|
|
|
|
|
|
|
// Override update (if needed, e.g. for smoothing or input handling).
|
|
|
|
virtual void Update(float deltaTime) override;
|
|
|
|
|
|
|
|
// Set the camera's position.
|
|
|
|
void SetPosition(const glm::vec3& pos);
|
|
|
|
// Set the camera's rotation in degrees.
|
|
|
|
void SetRotation(float yaw, float pitch);
|
|
|
|
|
|
|
|
// Get the view matrix calculated from position and rotation.
|
|
|
|
glm::mat4 GetViewMatrix() const;
|
|
|
|
// Get the projection matrix.
|
|
|
|
glm::mat4 GetProjectionMatrix() const;
|
|
|
|
|
|
|
|
// Set perspective projection parameters.
|
|
|
|
void SetPerspective(float fov, float aspect, float nearPlane, float farPlane);
|
|
|
|
|
|
|
|
// Getters.
|
|
|
|
glm::vec3 GetPosition() const;
|
|
|
|
float GetYaw() const;
|
|
|
|
float GetPitch() const;
|
|
|
|
|
2025-04-02 00:19:53 +00:00
|
|
|
// Save the camera state to a YAML node.
|
|
|
|
virtual YAML::Node Save() const override {
|
|
|
|
YAML::Node node;
|
|
|
|
node["position"] = YAML::Node();
|
|
|
|
node["position"].push_back(position.x);
|
|
|
|
node["position"].push_back(position.y);
|
|
|
|
node["position"].push_back(position.z);
|
|
|
|
|
|
|
|
node["yaw"] = yaw;
|
|
|
|
node["pitch"] = pitch;
|
|
|
|
node["fov"] = fov;
|
|
|
|
node["aspect"] = aspect;
|
|
|
|
node["nearPlane"] = nearPlane;
|
|
|
|
node["farPlane"] = farPlane;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the camera state from a YAML node.
|
|
|
|
virtual void Load(const YAML::Node &node) override {
|
|
|
|
if (node["position"]) {
|
|
|
|
position.x = node["position"][0].as<float>();
|
|
|
|
position.y = node["position"][1].as<float>();
|
|
|
|
position.z = node["position"][2].as<float>();
|
|
|
|
}
|
|
|
|
if (node["yaw"])
|
|
|
|
yaw = node["yaw"].as<float>();
|
|
|
|
if (node["pitch"])
|
|
|
|
pitch = node["pitch"].as<float>();
|
|
|
|
if (node["fov"])
|
|
|
|
fov = node["fov"].as<float>();
|
|
|
|
if (node["aspect"])
|
|
|
|
aspect = node["aspect"].as<float>();
|
|
|
|
if (node["nearPlane"])
|
|
|
|
nearPlane = node["nearPlane"].as<float>();
|
|
|
|
if (node["farPlane"])
|
|
|
|
farPlane = node["farPlane"].as<float>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// (Other Camera methods remain unchanged.)
|
|
|
|
|
2025-04-01 16:53:23 +00:00
|
|
|
private:
|
|
|
|
glm::vec3 position;
|
|
|
|
float yaw;
|
|
|
|
float pitch;
|
|
|
|
|
|
|
|
// Perspective projection parameters.
|
|
|
|
float fov;
|
|
|
|
float aspect;
|
|
|
|
float nearPlane;
|
|
|
|
float farPlane;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CAMERA_H
|