Skip to content

Commit 595d1a5

Browse files
committed
Added demo project for upcoming pathfinding implementation
1 parent 7766408 commit 595d1a5

13 files changed

Lines changed: 100 additions & 50 deletions

MP-APS/.vs/MP-APS/v15/.suo

14 KB
Binary file not shown.

MP-APS/.vs/MP-APS/v15/Browse.VC.db

12 KB
Binary file not shown.

MP-APS/.vscode/settings.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

MP-APS/Camera.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ Camera::Camera(const glm::vec3& position, const glm::vec3& up, const float yaw,
1818
updateVectors();
1919
}
2020

21+
/***********************************************************************************/
22+
void Camera::SetNear(const float near) {
23+
m_near = near;
24+
}
25+
26+
/***********************************************************************************/
27+
void Camera::SetFar(const float far) {
28+
m_far = far;
29+
}
30+
31+
/***********************************************************************************/
32+
void Camera::SetSpeed(const double speed) {
33+
m_speed = speed;
34+
}
35+
2136
/***********************************************************************************/
2237
void Camera::Update(const double deltaTime) {
2338

MP-APS/Camera.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ class Camera {
77
public:
88
Camera(const glm::vec3& position = { 0.0f, 0.0f, 0.0f }, const glm::vec3& up = { 0.0f, 1.0f, 0.0f }, const float yaw = -90.0f, const float pitch = 0.0f, const float FOV = 70.0f) noexcept;
99

10+
void SetNear(const float near);
11+
void SetFar(const float far);
12+
void SetSpeed(const double speed);
13+
1014
void Update(const double deltaTime);
1115

1216
auto GetViewMatrix() const { return lookAt(m_position, m_position + m_front, m_up); }
13-
auto GetProjMatrix(const float width, const float height) const { return glm::perspective(m_FOV, width / height, 1.0f, 100.0f); }
17+
auto GetProjMatrix(const float width, const float height) const { return glm::perspective(m_FOV, width / height, m_near, m_far); }
1418
auto GetPosition() const noexcept { return m_position; }
1519

1620
private:
@@ -39,10 +43,12 @@ class Camera {
3943
glm::vec3 m_right;
4044
const glm::vec3 m_worldUp = glm::vec3(0.0f, 1.0f, 0.0f);
4145

46+
float m_near = 1.0f, m_far = 100.0f;
47+
4248
// Eular Angles
4349
double m_yaw, m_pitch;
4450

45-
const double m_speed = 5.0;
51+
double m_speed = 5.0;
4652
const double m_sensitivity = 0.3;
4753
const float m_FOV;
4854

MP-APS/Demos/DemoCrytekSponza.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ void DemoCrytekSponza::Init(const std::string_view sceneName) {
1414
auto model = ResourceManager::GetInstance().GetModel("Sponza", "Data/Models/crytek-sponza/sponza.obj");
1515
model->Translate(glm::vec3(0.0f));
1616
model->Scale(glm::vec3(0.01f));
17-
m_sceneModels.push_back(model);
17+
AddModel(model);
1818

1919
// Sun
20-
m_staticDirectionalLights.emplace_back(StaticDirectionalLight(glm::vec3(5.0f, 5.0f, 4.5f), { 25.0f, 50.0f, 10.0f }));
20+
AddLight(StaticDirectionalLight({ 5.0f, 5.0f, 4.5f }, { 25.0f, 50.0f, 10.0f }));
2121
}
2222

MP-APS/Demos/DemoPathfinding.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "DemoPathfinding.h"
2+
3+
#include "../ResourceManager.h"
4+
5+
6+
/***********************************************************************************/
7+
DemoPathfinding::DemoPathfinding(const std::size_t width, const std::size_t height) : SceneBase(width, height) {
8+
}
9+
10+
/***********************************************************************************/
11+
void DemoPathfinding::Init(const std::string_view sceneName) {
12+
SceneBase::Init(sceneName);
13+
14+
m_camera.SetNear(0.1f);
15+
m_camera.SetSpeed(2.0);
16+
17+
auto model = ResourceManager::GetInstance().GetModel("Plane", "Data/Models/plane.obj");
18+
model->Translate(glm::vec3(0.0f));
19+
model->Scale(glm::vec3(4.0f, 2.0f, 4.0f));
20+
AddModel(model);
21+
22+
// Sun
23+
AddLight(StaticDirectionalLight({ 5.0f, 5.0f, 4.5f }, { 25.0f, 50.0f, 10.0f }));
24+
}

MP-APS/Demos/DemoPathfinding.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include "../SceneBase.h"
3+
4+
class DemoPathfinding : public SceneBase {
5+
6+
public:
7+
DemoPathfinding(const std::size_t width, const std::size_t height);
8+
~DemoPathfinding() = default;
9+
10+
void Init(const std::string_view sceneName) override;
11+
};

MP-APS/SceneBase.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ void SceneBase::Update(const double delta) {
3131
cullViewFrustum();
3232
}
3333

34+
/***********************************************************************************/
35+
void SceneBase::AddLight(const StaticDirectionalLight& light) {
36+
m_staticDirectionalLights.push_back(light);
37+
}
38+
39+
/***********************************************************************************/
40+
void SceneBase::AddLight(const StaticPointLight& light) {
41+
m_staticPointLights.push_back(light);
42+
}
43+
44+
/***********************************************************************************/
45+
void SceneBase::AddLight(const StaticSpotLight& light) {
46+
m_staticSpotLights.push_back(light);
47+
}
48+
49+
/***********************************************************************************/
50+
void SceneBase::AddModel(const ModelPtr& model) {
51+
m_sceneModels.push_back(model);
52+
}
53+
3454
/***********************************************************************************/
3555
void SceneBase::cullViewFrustum() {
3656
// TODO: optimize projection matrix calculation

MP-APS/SceneBase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class SceneBase {
2121
virtual void Init(const std::string_view sceneName);
2222
virtual void Update(const double delta);
2323

24+
void AddLight(const StaticDirectionalLight& light);
25+
void AddLight(const StaticPointLight& light);
26+
void AddLight(const StaticSpotLight& light);
27+
28+
void AddModel(const ModelPtr& model);
29+
2430
auto GetName() const noexcept { return m_sceneName; }
2531
auto GetCamera() const noexcept { return m_camera; }
2632

@@ -41,3 +47,4 @@ class SceneBase {
4147
std::vector<ModelPtr> m_sceneModels;
4248
std::vector<ModelPtr> m_renderList;
4349
};
50+

0 commit comments

Comments
 (0)