Screen shake working
This commit is contained in:
+20
-2
@@ -37,6 +37,7 @@
|
|||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "Rendering/CPointLight.h"
|
#include "Rendering/CPointLight.h"
|
||||||
|
#include "Rendering/CCamera.h"
|
||||||
#include "Transform/TransformSystem.h"
|
#include "Transform/TransformSystem.h"
|
||||||
#include "Sound/SoundSystem.h"
|
#include "Sound/SoundSystem.h"
|
||||||
#include "Sound/CCollisionSound.h"
|
#include "Sound/CCollisionSound.h"
|
||||||
@@ -67,6 +68,7 @@
|
|||||||
|
|
||||||
#include "Game/BrickComponents.h"
|
#include "Game/BrickComponents.h"
|
||||||
|
|
||||||
|
#include "Game/ScreenShakeSystem.h"
|
||||||
#include "Game/EScreenShake.h"
|
#include "Game/EScreenShake.h"
|
||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
@@ -147,6 +149,7 @@ public:
|
|||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||||
|
|
||||||
|
m_World->ComponentFactory.Register<Components::Camera>();
|
||||||
m_World->ComponentFactory.Register<Components::RectangleShape>();
|
m_World->ComponentFactory.Register<Components::RectangleShape>();
|
||||||
m_World->ComponentFactory.Register<Components::Physics>();
|
m_World->ComponentFactory.Register<Components::Physics>();
|
||||||
m_World->ComponentFactory.Register<Components::Ball>();
|
m_World->ComponentFactory.Register<Components::Ball>();
|
||||||
@@ -209,6 +212,9 @@ public:
|
|||||||
m_World->SystemFactory.Register<Systems::LifeSystem>(
|
m_World->SystemFactory.Register<Systems::LifeSystem>(
|
||||||
[this]() { return new Systems::LifeSystem(m_World.get(), m_EventBroker); });
|
[this]() { return new Systems::LifeSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::LifeSystem>();
|
m_World->AddSystem<Systems::LifeSystem>();
|
||||||
|
m_World->SystemFactory.Register<Systems::ScreenShakeSystem>(
|
||||||
|
[this]() { return new Systems::ScreenShakeSystem(m_World.get(), m_EventBroker); });
|
||||||
|
m_World->AddSystem<Systems::ScreenShakeSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
@@ -271,8 +277,6 @@ public:
|
|||||||
TEMPAddToRenderQueue();
|
TEMPAddToRenderQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<dd::Camera> defaultCamera = nullptr;
|
|
||||||
|
|
||||||
// Render scene
|
// Render scene
|
||||||
//TODO send renderqueue to draw.
|
//TODO send renderqueue to draw.
|
||||||
m_Renderer->Draw(m_RendererQueue);
|
m_Renderer->Draw(m_RendererQueue);
|
||||||
@@ -292,6 +296,20 @@ public:
|
|||||||
{
|
{
|
||||||
if (!m_TransformSystem)
|
if (!m_TransformSystem)
|
||||||
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||||
|
|
||||||
|
// HACK: How do we handle multiple cameras? Maybe view and projection matrices in render queue...
|
||||||
|
auto cameras = m_World->GetComponentsOfType<Components::Camera>();
|
||||||
|
if (cameras != nullptr) {
|
||||||
|
for (auto& component : *cameras) {
|
||||||
|
auto camera = static_cast<Components::Camera*>(component.get());
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(camera->Entity);
|
||||||
|
m_Renderer->Camera()->SetPosition(transform->Position);
|
||||||
|
m_Renderer->Camera()->SetOrientation(transform->Orientation);
|
||||||
|
m_Renderer->Camera()->SetFOV(camera->FOV);
|
||||||
|
m_Renderer->Camera()->SetNearClip(camera->NearClip);
|
||||||
|
m_Renderer->Camera()->SetFarClip(camera->FarClip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &pair : *m_World->GetEntities())
|
for (auto &pair : *m_World->GetEntities())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Rendering/CPointLight.h"
|
#include "Rendering/CPointLight.h"
|
||||||
|
#include "Rendering/CCamera.h"
|
||||||
|
|
||||||
#include "Transform/EMove.h"
|
#include "Transform/EMove.h"
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ public:
|
|||||||
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
|
||||||
bool VSYNC() const { return m_VSYNC; }
|
bool VSYNC() const { return m_VSYNC; }
|
||||||
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
|
||||||
const dd::Camera* Camera() const { return m_Camera; }
|
dd::Camera* Camera() const { return m_Camera; }
|
||||||
void SetCamera(const dd::Camera* camera)
|
void SetCamera(dd::Camera* camera)
|
||||||
{
|
{
|
||||||
if (camera == nullptr) {
|
if (camera == nullptr) {
|
||||||
m_Camera = m_DefaultCamera.get();
|
m_Camera = m_DefaultCamera.get();
|
||||||
@@ -55,7 +55,7 @@ protected:
|
|||||||
bool m_Fullscreen = false;
|
bool m_Fullscreen = false;
|
||||||
bool m_VSYNC = false;
|
bool m_VSYNC = false;
|
||||||
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
|
||||||
const dd::Camera* m_Camera = nullptr;
|
dd::Camera* m_Camera = nullptr;
|
||||||
GLFWwindow* m_Window = nullptr;
|
GLFWwindow* m_Window = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,9 @@ namespace Components
|
|||||||
|
|
||||||
struct Camera : Component
|
struct Camera : Component
|
||||||
{
|
{
|
||||||
Camera()
|
float FOV = glm::radians(45.f);
|
||||||
: FOV(glm::radians(45.f))
|
float NearClip = 0.01f;
|
||||||
, NearClip(0.1f)
|
float FarClip = 100.f;
|
||||||
, FarClip(100.f) { }
|
|
||||||
|
|
||||||
float FOV;
|
|
||||||
float NearClip;
|
|
||||||
float FarClip;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class Renderer : public BaseRenderer
|
|||||||
public:
|
public:
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
void Draw(RenderQueueCollection& rq) override;
|
void Draw(RenderQueueCollection& rq) override;
|
||||||
void PlaceCamera(glm::vec3 position);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_GLVersion[2];
|
int m_GLVersion[2];
|
||||||
@@ -97,12 +96,6 @@ private:
|
|||||||
void DrawWater(RenderQueue &objects);
|
void DrawWater(RenderQueue &objects);
|
||||||
void DrawGUI(RenderQueue& rq);
|
void DrawGUI(RenderQueue& rq);
|
||||||
void DebugKeys();
|
void DebugKeys();
|
||||||
|
|
||||||
dd::EventRelay<Renderer, dd::Events::ScreenShake> m_EScreenShake;
|
|
||||||
bool OnScreenShake(dd::Events::ScreenShake &event);
|
|
||||||
bool m_ScreenShake = false;
|
|
||||||
float m_ShakeIntensity = 0;
|
|
||||||
float m_ShakeTimer = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ void dd::Systems::LevelSystem::Initialize()
|
|||||||
|
|
||||||
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<bool>("Cheat.GodMode", false);
|
m_GodMode = ResourceManager::Load<ConfigFile>("Config.ini")->GetValue<bool>("Cheat.GodMode", false);
|
||||||
|
|
||||||
|
// Camera
|
||||||
|
{
|
||||||
|
auto ent = m_World->CreateEntity();
|
||||||
|
auto transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
|
auto camera = m_World->AddComponent<Components::Camera>(ent);
|
||||||
|
camera->FOV = glm::radians(58.31f);
|
||||||
|
m_World->CommitEntity(ent);
|
||||||
|
}
|
||||||
|
|
||||||
//PointLightTest
|
//PointLightTest
|
||||||
{
|
{
|
||||||
auto t_Light = m_World->CreateEntity();
|
auto t_Light = m_World->CreateEntity();
|
||||||
@@ -132,8 +141,8 @@ void dd::Systems::LevelSystem::Initialize()
|
|||||||
auto wall = m_World->AddComponent<Components::Wall>(BottomWall);
|
auto wall = m_World->AddComponent<Components::Wall>(BottomWall);
|
||||||
transform->Position = glm::vec3(0.f, -6.f, -10.f);
|
transform->Position = glm::vec3(0.f, -6.f, -10.f);
|
||||||
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
|
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(BottomWall);
|
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(BottomWall);
|
||||||
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
|
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void dd::Renderer::Initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create default camera
|
// Create default camera
|
||||||
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, 45.f, 0.01f, 5000.f));
|
m_DefaultCamera = std::unique_ptr<dd::Camera>(new dd::Camera((float)m_Resolution.Width / m_Resolution.Height, glm::radians(45.f), 0.01f, 5000.f));
|
||||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 0));
|
||||||
if (m_Camera == nullptr) {
|
if (m_Camera == nullptr) {
|
||||||
m_Camera = m_DefaultCamera.get();
|
m_Camera = m_DefaultCamera.get();
|
||||||
@@ -391,11 +391,6 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
|||||||
DrawWater(objects);
|
DrawWater(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Renderer::PlaceCamera(glm::vec3 position)
|
|
||||||
{
|
|
||||||
m_DefaultCamera->SetPosition(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||||
{
|
{
|
||||||
GLuint shaderProgramHandle = program;
|
GLuint shaderProgramHandle = program;
|
||||||
|
|||||||
Reference in New Issue
Block a user