相机组件
#ifndef CameraComponent_H
#define CameraComponent_H
#include"Component.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
class CameraComponent : public Component
{
public:
const float YAW = -90.0f;
const float PITCH = 0.0f;
const float ZOOM = 45.0f;
CameraComponent(GameObject* gameObject);
glm::mat4 GetPerspective();
glm::mat4 GetViewMatrix();
void Active();
void Update()override;
void LateUpdate()override;
void Render()override;
};
#endif
------------------------
#include "CameraComponent.h"
#include "GameObject.h"
#include "Window.h"
#include "Scene.h"
CameraComponent::CameraComponent(GameObject* gameObject):Component(gameObject)
{
SetName("CameraComponent");
}
glm::mat4 CameraComponent::GetPerspective()
{
return glm::perspective(glm::radians(ZOOM), (float)Window::Instance->Width / (float)Window::Instance->Height, 0.1f, 1000.0f);
}
glm::mat4 CameraComponent::GetViewMatrix()
{
return glm::lookAt(gameObject->transform->GetWordPosition(), gameObject->transform->GetWordPosition() + gameObject->transform->GetWordForward() , gameObject->transform->GetWordUp());
}
void CameraComponent::Active()
{
Scene::MainCamera = this;
}
void CameraComponent::Update()
{
__super::Update();
}
void CameraComponent::LateUpdate()
{
__super::LateUpdate();
}
void CameraComponent::Render()
{
__super::Render();
}