CSEngine
Loading...
Searching...
No Matches
CameraMgr.cpp
1#include "CameraMgr.h"
2
3#include "../Util/GLProgramHandle.h"
4#include "../Util/Render/ShaderUtil.h"
5#include "../Util/AssetsDef.h"
6
7using namespace CSE;
8
9CameraMgr::CameraMgr() = default;
10
11
12CameraMgr::~CameraMgr() = default;
13
14
15void CameraMgr::Init() {
16 std::string cubemap_vert = CSE::AssetMgr::LoadAssetFile(CSE::AssetsPath() + "Shader/PBR/IBL/cubemap.vert");
17 std::string cubemap_frag = CSE::AssetMgr::LoadAssetFile(CSE::AssetsPath() + "Shader/PBR/IBL/cubemap.frag");
18
19 m_skyboxProgram = ShaderUtil::CreateProgramHandle(cubemap_vert.c_str(), cubemap_frag.c_str());
20}
21
22void CameraMgr::DeleteCameraComponent(CameraComponent* object) {
23 if (object == nullptr) return;
24
25 auto iGameObj = std::find(m_objects.begin(), m_objects.end(), object);
26
27 if (iGameObj != m_objects.end()) {
28 m_size--;
29 m_objects.erase(iGameObj);
30 object->GetGameObject()->DeleteComponent(object);
31 //MemoryMgr::getInstance()->ReleaseObject(object);
32 }
33}
34
35
36const float* CameraMgr::GetProjectionRatio() const {
37 return &m_projectionRatio;
38}
39
40
41void CameraMgr::SetProjectionRatio(float ratio) {
42 m_projectionRatio = ratio;
43
44 for (auto camera : m_objects) {
45
46 if (camera == nullptr) continue;
47
48 camera->SetProjectionMatrix();
49
50 }
51}
52
53
54CameraComponent* CameraMgr::GetCurrentCamera() const {
55 if (m_currentCamera == nullptr && m_size > 0)
56 return m_objects.front();
57
58 return m_currentCamera;
59}
60
61
62void CameraMgr::ChangeCurrentCamera(CameraComponent* camera) {
63
64 m_currentCamera = camera;
65
66}
67
68GLProgramHandle* CameraMgr::GetSkyboxProgram() const {
69 return m_skyboxProgram;
70}
static GLProgramHandle * CreateProgramHandle(const GLchar *vertexSource, const GLchar *fragmentSource, GLProgramHandle *handle=nullptr)
Creates a program handle.