Files
Editor2D/include/Editor/EditorCamera.hpp

72 lines
1.7 KiB
C++

#pragma once
#include <J3ML/LinearAlgebra.hpp>
#include <Re2DLevelAPI.hpp>
struct EditorCamera {
Lerped<Vector2> translation;
Lerped<float> rotation;
Lerped<float> scale;
Vector2 origin{0,0};
Vector2 screenSize{1024,768};
[[nodiscard]] Matrix4x4 CurrentTranslationMatrix() const;
[[nodiscard]] Matrix4x4 GoalTranslationMatrix() const;
Matrix4x4 CurrentRotationMatrix() const;
Matrix4x4 GoalRotationMatrix() const;
Matrix4x4 CurrentScaleMatrix() const;
Matrix4x4 GoalScaleMatrix() const
{
return Matrix4x4::Scale({scale.goal, scale.goal, 1});
}
Matrix4x4 CurrentViewMatrix() const
{
return CurrentTranslationMatrix() * CurrentScaleMatrix();
}
Matrix4x4 GoalViewMatrix() const
{
return GoalTranslationMatrix() * GoalScaleMatrix();
}
void DefaultState()
{
this->rotation.goal = 0.f;
this->rotation.current = 0.f;
this->rotation.rate = 5.f;
this->translation.goal = {0.f, 0.f};
this->translation.current = {0.f, 0.f};
this->translation.rate = 5.f;
this->scale.goal = 1.f;
this->scale.current = 1.f;
this->scale.rate = 5.f;
}
Vector2 ScreenToCameraSpace(const Vector2& ssv) const {
return {
(ssv.x + translation.current.x) / scale.current,
(ssv.y + translation.current.y) / scale.current
};
}
Vector2 CameraToScreenSpace(const Vector2& csv) const{
return {
(csv.x * scale.current) - translation.current.x,
(csv.y * scale.current) - translation.current.y
};
}
void Update(float elapsed)
{
translation.Step(elapsed);
rotation.Step(elapsed);
scale.Step(elapsed);
}
};