#include "camera.h"
#include "math/math.h"
#include "render/window.h"
#include "object/component/transform.h"
namespace engineapi {
	Camera::Camera()
	{
	}
	Camera::~Camera()
	{
	}
	Matrix4 Camera::GetViewMatrix()
	{
		// Model矩阵是把顶点从模型空间转到世界空间，而相机的View矩阵，其实就是把场景中所有顶点从世界空间转到相机自己的模型空间
		// 所以这里直接返回Model矩阵的逆矩阵即可
		// 这里用glm::lookAt或者Math::GetLookToMatrix也是一样的
		Matrix4 model = GetTransform()->GetModelMatrix();
		return Math::Inverse(model);
	}
	Matrix4 Camera::GetProjectionMatrix()
	{
		auto window = Window::GetSingletonPtr();
		uint32_t width, height;
		window->GetSize(width, height);
		if (mAspect == 0.0f)
			return Math::Perspective(Math::Deg2Rad(mFov), static_cast<float>(width) / static_cast<float>(height), mNearClipDis, mFarClipDis);
		return Math::Perspective(Math::Deg2Rad(mFov), mAspect, mNearClipDis, mFarClipDis);
	}
}
