Files
LEngine_deprecated/LEngine/Camera.cpp
T

32 lines
716 B
C++
Raw Normal View History

2025-05-13 02:50:08 +03:00
#include "Camera.h"
#include "Transform.h"
#include "Mathf.h"
#include "Archive.h"
float4x4 Camera::worldToCameraMatrix() {
auto world = transform()->GetGlobalTransform();
//TODO: why not affine ?
world = inverse(world, false);
// auto test = lookatlh(transform()->GetGlobalPosition(), float3(0, 1, 1), float3(0, 1, 0));
return world;
}
void Camera::serialize(Archive& archive) {
Component::serialize(archive);
archive << nearClipPlane << farClipPlane << fov << aspect;
}
void Camera::UpdateProjectionMatrix() {
_projection = matrix4x4Perspective(fov * Mathf::DegToRad(), aspect, nearClipPlane, farClipPlane);
}
float4x4 Camera::projectionMatrix() {
UpdateProjectionMatrix();
return _projection;
}