Screen shake working

This commit is contained in:
2015-10-23 14:26:08 +02:00
parent aa0aff9002
commit 9158dd8ef7
7 changed files with 39 additions and 28 deletions
+20 -2
View File
@@ -37,6 +37,7 @@
#include "Rendering/CModel.h"
#include "Rendering/CSprite.h"
#include "Rendering/CPointLight.h"
#include "Rendering/CCamera.h"
#include "Transform/TransformSystem.h"
#include "Sound/SoundSystem.h"
#include "Sound/CCollisionSound.h"
@@ -67,6 +68,7 @@
#include "Game/BrickComponents.h"
#include "Game/ScreenShakeSystem.h"
#include "Game/EScreenShake.h"
#include "Physics/PhysicsSystem.h"
@@ -147,6 +149,7 @@ public:
m_World->ComponentFactory.Register<Components::Sprite>();
m_World->ComponentFactory.Register<Components::Camera>();
m_World->ComponentFactory.Register<Components::RectangleShape>();
m_World->ComponentFactory.Register<Components::Physics>();
m_World->ComponentFactory.Register<Components::Ball>();
@@ -209,6 +212,9 @@ public:
m_World->SystemFactory.Register<Systems::LifeSystem>(
[this]() { return new Systems::LifeSystem(m_World.get(), m_EventBroker); });
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::Template>();
@@ -271,8 +277,6 @@ public:
TEMPAddToRenderQueue();
}
std::unique_ptr<dd::Camera> defaultCamera = nullptr;
// Render scene
//TODO send renderqueue to draw.
m_Renderer->Draw(m_RendererQueue);
@@ -292,6 +296,20 @@ public:
{
if (!m_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())
{
+1
View File
@@ -19,6 +19,7 @@
#include "Rendering/CSprite.h"
#include "Rendering/CModel.h"
#include "Rendering/CPointLight.h"
#include "Rendering/CCamera.h"
#include "Transform/EMove.h"
+3 -3
View File
@@ -37,8 +37,8 @@ public:
void SetFullscreen(bool fullscreen) { m_Fullscreen = fullscreen; }
bool VSYNC() const { return m_VSYNC; }
void SetVSYNC(bool vsync) { m_VSYNC = vsync; }
const dd::Camera* Camera() const { return m_Camera; }
void SetCamera(const dd::Camera* camera)
dd::Camera* Camera() const { return m_Camera; }
void SetCamera(dd::Camera* camera)
{
if (camera == nullptr) {
m_Camera = m_DefaultCamera.get();
@@ -55,7 +55,7 @@ protected:
bool m_Fullscreen = false;
bool m_VSYNC = false;
std::unique_ptr<dd::Camera> m_DefaultCamera = nullptr;
const dd::Camera* m_Camera = nullptr;
dd::Camera* m_Camera = nullptr;
GLFWwindow* m_Window = nullptr;
};
+3 -8
View File
@@ -30,14 +30,9 @@ namespace Components
struct Camera : Component
{
Camera()
: FOV(glm::radians(45.f))
, NearClip(0.1f)
, FarClip(100.f) { }
float FOV;
float NearClip;
float FarClip;
float FOV = glm::radians(45.f);
float NearClip = 0.01f;
float FarClip = 100.f;
};
}
@@ -43,7 +43,6 @@ class Renderer : public BaseRenderer
public:
void Initialize() override;
void Draw(RenderQueueCollection& rq) override;
void PlaceCamera(glm::vec3 position);
private:
int m_GLVersion[2];
@@ -97,12 +96,6 @@ private:
void DrawWater(RenderQueue &objects);
void DrawGUI(RenderQueue& rq);
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;
};
}
+11 -2
View File
@@ -27,6 +27,15 @@ void dd::Systems::LevelSystem::Initialize()
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
{
auto t_Light = m_World->CreateEntity();
@@ -132,8 +141,8 @@ void dd::Systems::LevelSystem::Initialize()
auto wall = m_World->AddComponent<Components::Wall>(BottomWall);
transform->Position = glm::vec3(0.f, -6.f, -10.f);
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(BottomWall);
//sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
std::shared_ptr<Components::RectangleShape> rectangleShape = m_World->AddComponent<Components::RectangleShape>(BottomWall);
rectangleShape->Dimensions = glm::vec2(20.f, 0.5f);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(BottomWall);
+1 -6
View File
@@ -63,7 +63,7 @@ void dd::Renderer::Initialize()
}
// 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));
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera.get();
@@ -391,11 +391,6 @@ void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
DrawWater(objects);
}
void dd::Renderer::PlaceCamera(glm::vec3 position)
{
m_DefaultCamera->SetPosition(position);
}
void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
{
GLuint shaderProgramHandle = program;