Merge remote-tracking branch 'origin/master' into Physics
Conflicts: include/Core/Engine.h src/game/Physics/PhysicsSystem.cpp
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 722 KiB |
|
After Width: | Height: | Size: 773 KiB |
|
After Width: | Height: | Size: 433 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
@@ -30,16 +30,22 @@
|
|||||||
//TODO: Remove includes that are only here for the temporary draw solution.
|
//TODO: Remove includes that are only here for the temporary draw solution.
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include "CTransform.h"
|
#include "CTransform.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
#include "Rendering/CModel.h"
|
#include "Rendering/CModel.h"
|
||||||
#include "Rendering/CSprite.h"
|
#include "Rendering/CSprite.h"
|
||||||
#include "CTemplate.h"
|
#include "CTemplate.h"
|
||||||
|
#include "Rendering/CPointLight.h"
|
||||||
#include "Transform/TransformSystem.h"
|
#include "Transform/TransformSystem.h"
|
||||||
|
#include "Game/LevelSystem.h"
|
||||||
|
#include "Game/PadSystem.h"
|
||||||
|
#include "Game/CBall.h"
|
||||||
|
#include "Game/CBrick.h"
|
||||||
|
#include "Game/CPad.h"
|
||||||
|
|
||||||
#include "Physics/PhysicsSystem.h"
|
#include "Physics/PhysicsSystem.h"
|
||||||
#include "Physics/CPhysics.h"
|
#include "Physics/CPhysics.h"
|
||||||
|
|
||||||
|
|
||||||
#include "Physics/CBoxShape.h"
|
#include "Physics/CBoxShape.h"
|
||||||
|
#include "Physics/ESetImpulse.h"
|
||||||
|
|
||||||
namespace dd
|
namespace dd
|
||||||
{
|
{
|
||||||
@@ -67,40 +73,123 @@ public:
|
|||||||
// m_World->ComponentFactory.Register<Components::Model>();
|
// m_World->ComponentFactory.Register<Components::Model>();
|
||||||
// m_World->ComponentFactory.Register<Components::Template>();
|
// m_World->ComponentFactory.Register<Components::Template>();
|
||||||
|
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||||
|
|
||||||
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::Brick>();
|
||||||
|
m_World->ComponentFactory.Register<Components::Pad>();
|
||||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||||
|
|
||||||
|
m_World->SystemFactory.Register<Systems::LevelSystem>([this]() { return new Systems::LevelSystem(m_World.get(), m_EventBroker); });
|
||||||
|
m_World->AddSystem<Systems::LevelSystem>();
|
||||||
|
m_World->SystemFactory.Register<Systems::PadSystem>([this]() { return new Systems::PadSystem(m_World.get(), m_EventBroker); });
|
||||||
|
m_World->AddSystem<Systems::PadSystem>();
|
||||||
|
|
||||||
m_World->ComponentFactory.Register<Components::Model>();
|
m_World->ComponentFactory.Register<Components::Model>();
|
||||||
m_World->ComponentFactory.Register<Components::Template>();
|
m_World->ComponentFactory.Register<Components::Template>();
|
||||||
|
m_World->ComponentFactory.Register<Components::PointLight>();
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Remove tobias light-test code.
|
||||||
|
{
|
||||||
|
auto t_BrickWall = m_World->CreateEntity();
|
||||||
|
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
|
||||||
|
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||||
|
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
|
||||||
|
//TODO: Rename SpriteFile to DiffuseTexture or similar.
|
||||||
|
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
|
||||||
|
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
|
||||||
|
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
||||||
|
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Ball.png";
|
||||||
|
|
||||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||||
|
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||||
|
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
|
|
||||||
|
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||||
|
plight->Radius = 2.f;
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
|
Events::SetImpulse e;
|
||||||
|
e.Entity = ent;
|
||||||
|
e.Impulse = glm::vec2(0.f, -7.f);
|
||||||
|
e.Point = glm::vec2(0.5f, 0.f);
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto topWall = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
||||||
|
transform->Position = glm::vec3(0.f, 5.f, -10.f);
|
||||||
|
transform->Scale = glm::vec3(15.f, 0.5f, 1.f);
|
||||||
|
|
||||||
{
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||||
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(topWall);
|
||||||
|
|
||||||
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||||
|
physics->Static = true;
|
||||||
|
|
||||||
|
m_World->CommitEntity(topWall);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto leftWall = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(leftWall);
|
||||||
|
transform->Position = glm::vec3(-9.f, 1.f, -10.f);
|
||||||
|
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
||||||
|
|
||||||
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(leftWall);
|
||||||
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(leftWall);
|
||||||
|
|
||||||
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
|
||||||
|
physics->Static = true;
|
||||||
|
|
||||||
|
m_World->CommitEntity(leftWall);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto rightWall = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(rightWall);
|
||||||
|
transform->Position = glm::vec3(9.f, 1.f, -10.f);
|
||||||
|
transform->Scale = glm::vec3(0.5f, 10.f, 1.f);
|
||||||
|
|
||||||
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(rightWall);
|
||||||
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
|
|
||||||
|
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(rightWall);
|
||||||
|
|
||||||
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
|
||||||
|
physics->Static = true;
|
||||||
|
|
||||||
|
m_World->CommitEntity(rightWall);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.f, -2.f, -10.f);
|
transform->Position = glm::vec3(0.f, -3.f, -10.f);
|
||||||
transform->Scale = glm::vec3(8.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(8.f, 0.5f, 1.f);
|
||||||
transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1));
|
transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1));
|
||||||
|
|
||||||
@@ -113,28 +202,22 @@ public:
|
|||||||
physics->Static = true;
|
physics->Static = true;
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
m_World->SetProperty(ent, "Name", "Pad");
|
||||||
transform->Position = glm::vec3(-2.f, -1.f, -10.f);
|
auto ctransform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Scale = glm::vec3(0.5f, 8.5f, 1.f);
|
ctransform->Position = glm::vec3(0.f, -5.f, -10.f);
|
||||||
//transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1));
|
ctransform->Scale = glm::vec3(3.2, 0.8, 0.);
|
||||||
|
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
auto csprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
|
auto pad = m_World->AddComponent<Components::Pad>(ent);
|
||||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
csprite->SpriteFile = "Textures/Pad.png";
|
||||||
|
|
||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
|
||||||
physics->Static = true;
|
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +236,19 @@ public:
|
|||||||
|
|
||||||
m_World->Update(dt);
|
m_World->Update(dt);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
|
||||||
|
// ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//TODO Fill up the renderQueue with models (Temp fix)
|
||||||
|
// TEMPAddToRenderQueue();
|
||||||
|
|
||||||
|
// Render scene
|
||||||
|
//TODO send renderqueue to draw.
|
||||||
|
// m_Renderer->Draw(m_RendererQueue);
|
||||||
|
|
||||||
if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
|
if (glfwGetKey(m_Renderer->Window(), GLFW_KEY_R)) {
|
||||||
ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
ResourceManager::Reload("Shaders/Deferred/3/Fragment.glsl");
|
||||||
}
|
}
|
||||||
@@ -171,6 +267,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||||
|
std::shared_ptr<Systems::LevelSystem> m_LevelSystem;
|
||||||
|
|
||||||
//TODO: Get this out of engine.h
|
//TODO: Get this out of engine.h
|
||||||
void TEMPAddToRenderQueue()
|
void TEMPAddToRenderQueue()
|
||||||
@@ -209,19 +306,43 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Add LightLoadShit
|
||||||
|
|
||||||
|
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||||
|
if (pointLightComponent)
|
||||||
|
{
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
EnqueuePointLight(absoluteTransform.Position,
|
||||||
|
pointLightComponent->Diffuse,
|
||||||
|
pointLightComponent->Specular,
|
||||||
|
pointLightComponent->Radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
if (spriteComponent)
|
if (spriteComponent)
|
||||||
{
|
{
|
||||||
auto textureAsset = ResourceManager::Load<Texture>(spriteComponent->SpriteFile);
|
|
||||||
if (textureAsset)
|
std::string normal = spriteComponent->NormalTexture;
|
||||||
{
|
std::string spec = spriteComponent->SpecularTexture;
|
||||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
|
||||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
|
if (normal.empty()) {
|
||||||
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
|
normal = "Textures/Core/NeutralNormalMap.png";
|
||||||
* glm::toMat4(orientation2D)
|
|
||||||
* glm::scale(absoluteTransform.Scale);
|
|
||||||
EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color);
|
|
||||||
}
|
}
|
||||||
|
if (spec.empty()) {
|
||||||
|
spec = "Textures/Core/NeutralSpecularMap.png";
|
||||||
|
}
|
||||||
|
auto texturediff = ResourceManager::Load<Texture>(spriteComponent->SpriteFile);
|
||||||
|
auto texturenorm = ResourceManager::Load<Texture>(normal);
|
||||||
|
auto texturespec = ResourceManager::Load<Texture>(spec);
|
||||||
|
|
||||||
|
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
|
||||||
|
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
|
||||||
|
* glm::toMat4(orientation2D)
|
||||||
|
* glm::scale(absoluteTransform.Scale);
|
||||||
|
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,15 +371,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Get this out of engine.h
|
// TODO: Get this out of engine.h
|
||||||
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color)
|
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color)
|
||||||
{
|
{
|
||||||
SpriteJob job;
|
SpriteJob job;
|
||||||
job.TextureID = texture->ResourceID;
|
job.TextureID = texture->ResourceID;
|
||||||
job.Texture = *texture;
|
job.DiffuseTexture = *texture;
|
||||||
|
job.NormalTexture = *normalTexture;
|
||||||
|
job.SpecularTexture = *specularTexture;
|
||||||
job.ModelMatrix = modelMatrix;
|
job.ModelMatrix = modelMatrix;
|
||||||
job.Color = color;
|
job.Color = color;
|
||||||
|
|
||||||
m_RendererQueue.Forward.Add(job);
|
m_RendererQueue.Deferred.Add(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
|
||||||
|
{
|
||||||
|
PointLightJob job;
|
||||||
|
job.Position = position;
|
||||||
|
job.DiffuseColor = diffuseColor;
|
||||||
|
job.SpecularColor = specularColor;
|
||||||
|
job.Radius = radius;
|
||||||
|
|
||||||
|
m_RendererQueue.Lights.Add(job);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -34,54 +34,23 @@ class InputController
|
|||||||
public:
|
public:
|
||||||
InputController(std::shared_ptr<dd::EventBroker> eventBroker)
|
InputController(std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
: EventBroker(eventBroker)
|
: EventBroker(eventBroker)
|
||||||
, InGame(true)
|
|
||||||
{ Initialize(); }
|
{ Initialize(); }
|
||||||
|
|
||||||
virtual void Initialize()
|
virtual void Initialize()
|
||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::_OnCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::_OnMouseMove);
|
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &InputController::OnGameStart);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &InputController::OnGameOver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool OnCommand(const Events::InputCommand &event) { return false; }
|
virtual bool OnCommand(const Events::InputCommand &event) { return false; }
|
||||||
virtual bool OnMouseMove(const Events::MouseMove &event) { return false; }
|
virtual bool OnMouseMove(const Events::MouseMove &event) { return false; }
|
||||||
virtual bool OnGameStart(const Events::GameStart &event)
|
|
||||||
{
|
|
||||||
InGame = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
virtual bool OnGameOver(const Events::GameOver &event)
|
|
||||||
{
|
|
||||||
InGame = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<dd::EventBroker> EventBroker;
|
std::shared_ptr<dd::EventBroker> EventBroker;
|
||||||
bool InGame;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventRelay<EventContext, Events::InputCommand> m_EInputCommand;
|
EventRelay<EventContext, Events::InputCommand> m_EInputCommand;
|
||||||
EventRelay<EventContext, Events::MouseMove> m_EMouseMove;
|
EventRelay<EventContext, Events::MouseMove> m_EMouseMove;
|
||||||
EventRelay<EventContext, Events::GameStart> m_EGameStart;
|
|
||||||
EventRelay<EventContext, Events::GameOver> m_EGameOver;
|
|
||||||
|
|
||||||
virtual bool _OnCommand(const Events::InputCommand &event)
|
|
||||||
{
|
|
||||||
if (InGame || event.Value == 0)
|
|
||||||
return OnCommand(event);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
virtual bool _OnMouseMove(const Events::MouseMove &event)
|
|
||||||
{
|
|
||||||
if (InGame)
|
|
||||||
return OnMouseMove(event);
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,9 @@ struct SpriteJob : RenderJob
|
|||||||
unsigned int TextureID;
|
unsigned int TextureID;
|
||||||
|
|
||||||
glm::mat4 ModelMatrix;
|
glm::mat4 ModelMatrix;
|
||||||
GLuint Texture;
|
GLuint DiffuseTexture;
|
||||||
|
GLuint NormalTexture;
|
||||||
|
GLuint SpecularTexture;
|
||||||
glm::vec4 Color;
|
glm::vec4 Color;
|
||||||
|
|
||||||
void CalculateHash() override
|
void CalculateHash() override
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ private:
|
|||||||
|
|
||||||
GLuint m_ScreenQuad = 0;
|
GLuint m_ScreenQuad = 0;
|
||||||
Model* m_UnitSphere = nullptr;
|
Model* m_UnitSphere = nullptr;
|
||||||
|
Model* m_UnitQuad = nullptr;
|
||||||
|
|
||||||
GLuint m_rbDepthBuffer = 0;
|
GLuint m_rbDepthBuffer = 0;
|
||||||
GLuint m_fbDeferred1 = 0;
|
GLuint m_fbDeferred1 = 0;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-10.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CBALL_H
|
||||||
|
#define DAYDREAM_CBALL_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Ball : Component
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CBALL_H
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-09.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CBRICK_H
|
||||||
|
#define DAYDREAM_CBRICK_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Brick : Component
|
||||||
|
{
|
||||||
|
int Points = 10;
|
||||||
|
int Hits = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CBRICK_H
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-10.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_CPAD_H
|
||||||
|
#define DAYDREAM_CPAD_H
|
||||||
|
|
||||||
|
#include "Core/Component.h"
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Pad : Component
|
||||||
|
{
|
||||||
|
int Lives;
|
||||||
|
int Points;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_CPAD_H
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-09.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_ESTAGECLEARED_H
|
||||||
|
#define DAYDREAM_ESTAGECLEARED_H
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
struct StageCleared : Event
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_ESTAGECLEARED_H
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-09.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_LEVELSYSTEM_H
|
||||||
|
#define DAYDREAM_LEVELSYSTEM_H
|
||||||
|
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/CTransform.h"
|
||||||
|
#include "Rendering/CSprite.h"
|
||||||
|
#include "Game/CBrick.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/World.h"
|
||||||
|
#include "Game/CBall.h"
|
||||||
|
#include "Game/EStageCleared.h"
|
||||||
|
#include "Physics/CBoxShape.h"
|
||||||
|
#include "Physics/CPhysics.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <intrin.h>
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
// Me trying things out.
|
||||||
|
class Level
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int levelRows;
|
||||||
|
int levelLines;
|
||||||
|
int levelSpaceBetweenBricks;
|
||||||
|
int levelSpaceToEdge;
|
||||||
|
int bricks[];
|
||||||
|
};
|
||||||
|
|
||||||
|
class LevelSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LevelSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
|
||||||
|
void CreateBasicLevel(int, int, glm::vec2, int);
|
||||||
|
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
|
||||||
|
void LoadLevel(char[20]);
|
||||||
|
void CreateBrick(int, int, glm::vec2, int, int);
|
||||||
|
void ProcessCollision();
|
||||||
|
|
||||||
|
void OnEntityRemoved(EntityID entity);
|
||||||
|
|
||||||
|
void EndLevel();
|
||||||
|
|
||||||
|
void Update(double dt);
|
||||||
|
|
||||||
|
private:
|
||||||
|
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||||
|
|
||||||
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
|
|
||||||
|
bool m_Initialized = false;
|
||||||
|
|
||||||
|
int numberOfBricks;
|
||||||
|
int tRows = 7;
|
||||||
|
int tLines = 8;
|
||||||
|
glm::vec2 tSpaceBetweenBricks = glm::vec2(2, 0.5);
|
||||||
|
int tSpaceToEdge = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DAYDREAM_LEVELSYSTEM_H
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-10.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DAYDREAM_PADSYSTEM_H
|
||||||
|
#define DAYDREAM_PADSYSTEM_H
|
||||||
|
|
||||||
|
#include "Core/InputController.h"
|
||||||
|
#include "Core/System.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
#include "Core/EKeyUp.h"
|
||||||
|
#include "Input/EBindKey.h"
|
||||||
|
#include "Physics/EContact.h"
|
||||||
|
#include "Core/CTransform.h"
|
||||||
|
#include "Physics/CBoxShape.h"
|
||||||
|
#include "Physics/CPhysics.h"
|
||||||
|
#include "Rendering/CSprite.h"
|
||||||
|
#include "Game/CBall.h"
|
||||||
|
#include "Core/Component.h"
|
||||||
|
#include "Physics/ESetImpulse.h"
|
||||||
|
#include "Physics/CCircleShape.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class PadSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PadSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: System(world, eventBroker)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Initialize() override;
|
||||||
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
||||||
|
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
||||||
|
|
||||||
|
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||||
|
bool OnKeyUp(const dd::Events::KeyUp &event);
|
||||||
|
|
||||||
|
|
||||||
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PadSteeringInputController;
|
||||||
|
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
|
||||||
|
|
||||||
|
EntityID ent = 0;
|
||||||
|
Components::Transform* transform;
|
||||||
|
glm::vec3 acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||||
|
bool left = false, right = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PadSystem::PadSteeringInputController : InputController<PadSystem>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PadSteeringInputController(std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
|
: InputController(eventBroker)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
virtual bool OnCommand(const Events::InputCommand &event);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DAYDREAM_PADSYSTEM_H
|
||||||
@@ -7,11 +7,11 @@ namespace dd
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Physics: public Component
|
struct Physics: public Component
|
||||||
{
|
{
|
||||||
//idk if anything should be here :)
|
//idk if anything should be here :)
|
||||||
bool Static = true;
|
bool Static = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ private:
|
|||||||
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()];
|
||||||
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()];
|
||||||
|
|
||||||
std::cout << e.Entity1 << " " << e.Entity2 << std::endl;
|
|
||||||
|
|
||||||
m_PhysicsSystem->EventBroker->Publish(e);
|
m_PhysicsSystem->EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
void EndContact(b2Contact* contact)
|
void EndContact(b2Contact* contact)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ struct Sprite : Component
|
|||||||
Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { }
|
Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { }
|
||||||
|
|
||||||
std::string SpriteFile;
|
std::string SpriteFile;
|
||||||
|
std::string NormalTexture;
|
||||||
|
std::string SpecularTexture;
|
||||||
glm::vec4 Color;
|
glm::vec4 Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
TransformSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
TransformSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||||
: System(world, eventBroker)
|
: System(world, eventBroker)
|
||||||
{ }
|
{ }
|
||||||
//void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
|
|
||||||
Components::Transform AbsoluteTransform(EntityID entity);
|
Components::Transform AbsoluteTransform(EntityID entity);
|
||||||
glm::vec3 AbsolutePosition(EntityID entity);
|
glm::vec3 AbsolutePosition(EntityID entity);
|
||||||
|
|||||||
@@ -77,12 +77,20 @@ void dd::Camera::SetOrientation(glm::quat val)
|
|||||||
|
|
||||||
void dd::Camera::UpdateProjectionMatrix()
|
void dd::Camera::UpdateProjectionMatrix()
|
||||||
{
|
{
|
||||||
m_ProjectionMatrix = glm::perspective(
|
m_ProjectionMatrix = glm::ortho(
|
||||||
m_FOV,
|
-16.f,
|
||||||
m_AspectRatio,
|
16.f,
|
||||||
|
-9.f,
|
||||||
|
9.f,
|
||||||
m_NearClip,
|
m_NearClip,
|
||||||
m_FarClip
|
m_FarClip
|
||||||
);
|
);
|
||||||
|
// m_ProjectionMatrix = glm::perspective(
|
||||||
|
// m_FOV,
|
||||||
|
// m_AspectRatio,
|
||||||
|
// m_NearClip,
|
||||||
|
// m_FarClip
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Camera::UpdateViewMatrix()
|
void dd::Camera::UpdateViewMatrix()
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ void dd::Renderer::LoadShaders()
|
|||||||
void dd::Renderer::CreateBuffers()
|
void dd::Renderer::CreateBuffers()
|
||||||
{
|
{
|
||||||
m_ScreenQuad = CreateQuad();
|
m_ScreenQuad = CreateQuad();
|
||||||
|
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||||
|
|
||||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
||||||
@@ -264,7 +265,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
|||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_spDeferred3->Bind();
|
m_spDeferred3->Bind();
|
||||||
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.3f)));
|
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
@@ -306,6 +307,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
|
|
||||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
|
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
|
||||||
|
|
||||||
|
//TODO: Make sure that a normal/specular is loaded in.
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
|
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
|
||||||
if (modelJob->NormalTexture != 0) {
|
if (modelJob->NormalTexture != 0) {
|
||||||
@@ -328,17 +330,21 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
|||||||
if (spriteJob)
|
if (spriteJob)
|
||||||
{
|
{
|
||||||
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
|
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
|
||||||
modelMatrix = modelMatrix * glm::scale(glm::vec3(0.5f));
|
|
||||||
MVP = PV * modelMatrix;
|
MVP = PV * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
|
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, spriteJob->NormalTexture);
|
||||||
|
glActiveTexture(GL_TEXTURE2);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, spriteJob->SpecularTexture);
|
||||||
|
|
||||||
glBindVertexArray(m_ScreenQuad);
|
glBindVertexArray(m_UnitQuad->VAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_UnitQuad->ElementBuffer);
|
||||||
|
glDrawElementsBaseVertex(GL_TRIANGLES, m_UnitQuad->m_Indices.size(), GL_UNSIGNED_INT, 0, 0);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void main()
|
|||||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||||
}
|
}
|
||||||
|
|
||||||
gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
gl_Position = MVP * vec4(Position, 1.0);
|
||||||
|
|
||||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ void main()
|
|||||||
|
|
||||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
||||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
||||||
frag_Diffuse = DiffuseTexel;
|
frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
|
||||||
|
//frag_Diffuse = DiffuseTexel;
|
||||||
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
||||||
}
|
}
|
||||||
@@ -84,6 +84,6 @@ void main()
|
|||||||
|
|
||||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||||
|
|
||||||
//FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||||
FragmentColor = diffuseTexel;
|
//FragmentColor = diffuseTexel;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ dd::Texture::Texture(std::string path)
|
|||||||
std::unique_ptr<Image> image = std::make_unique<PNG>(path);
|
std::unique_ptr<Image> image = std::make_unique<PNG>(path);
|
||||||
|
|
||||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||||
image = std::make_unique<PNG>("Textures/ErrorTexture.png");
|
image = std::make_unique<PNG>("Textures/Core/ErrorTexture.png");
|
||||||
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
if (image->Width == 0 && image->Height == 0 || image->Format == Image::ImageFormat::Unknown) {
|
||||||
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-09.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Game/LevelSystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::Initialize()
|
||||||
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::Update(double dt) {
|
||||||
|
if (!m_Initialized) {
|
||||||
|
CreateBasicLevel(tRows, tLines, tSpaceBetweenBricks, tSpaceToEdge);
|
||||||
|
m_Initialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, int spaceToEdge)
|
||||||
|
{
|
||||||
|
int num = 0;
|
||||||
|
numberOfBricks = rows * lines;
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
num++;
|
||||||
|
for (int j = 0; j < lines; j++)
|
||||||
|
{
|
||||||
|
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
|
||||||
|
}
|
||||||
|
if (num == 7)
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBetweenBricks, int spaceToEdge, int num)
|
||||||
|
{
|
||||||
|
auto brick = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
|
||||||
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
|
||||||
|
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
|
||||||
|
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
|
||||||
|
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
|
||||||
|
std::string fileName = "Textures/Bricks/";
|
||||||
|
fileName.append(std::to_string(num));
|
||||||
|
fileName.append(".png");
|
||||||
|
sprite->SpriteFile = fileName;
|
||||||
|
float x = spaceToEdge + line * spacesBetweenBricks.x;
|
||||||
|
float y = spaceToEdge + row * spacesBetweenBricks.y;
|
||||||
|
transform->Scale = glm::vec3(1.6, 0.4, 0.);
|
||||||
|
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
||||||
|
//sprite->Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||||
|
m_World->CommitEntity(brick);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::ProcessCollision()
|
||||||
|
{
|
||||||
|
// Like, go into brick component and check what it does upon collision. Maybe not done here?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
||||||
|
{
|
||||||
|
auto brick = m_World->GetComponent<Components::Brick>(entity);
|
||||||
|
if (brick != NULL)
|
||||||
|
{
|
||||||
|
numberOfBricks--;
|
||||||
|
if (numberOfBricks < 1)
|
||||||
|
{
|
||||||
|
EndLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
/*event.Entity1 - Vi vet inte vilken som.
|
||||||
|
event.Entity2 - */
|
||||||
|
EntityID entityBrick = event.Entity1;
|
||||||
|
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
||||||
|
if (brick == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EntityID entityBall = event.Entity2;
|
||||||
|
//EntityID entity1 = event.Entity1;
|
||||||
|
//EntityID entity2 = event.Entity2;
|
||||||
|
|
||||||
|
//auto brick = m_World->GetComponent<Components::Brick>(entity1);
|
||||||
|
//auto ball = m_World->GetComponent<Components::Ball>(entity2);
|
||||||
|
//std::cout << brick << std::endl;
|
||||||
|
//std::cout << ball << std::endl;
|
||||||
|
/*if (brick != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Entity1 is a brick!" << std::endl;
|
||||||
|
entityBrick = entity1;
|
||||||
|
if (ball != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Entity2 is a ball!" << std::endl;
|
||||||
|
entityBall = entity2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
brick = m_World->GetComponent<Components::Brick>(entity2);
|
||||||
|
if (brick != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Entity2 is a brick!" << std::endl;
|
||||||
|
entityBrick = entity2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ball = m_World->GetComponent<Components::Ball>(entity1);
|
||||||
|
if (ball != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Entity1 is a ball!" << std::endl;
|
||||||
|
entityBall = entity1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityBrick != NULL && entityBall != NULL)
|
||||||
|
{*/
|
||||||
|
//std::cout << "We're destroying!" << std::endl;
|
||||||
|
m_World->RemoveEntity(entityBrick);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
//}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::LevelSystem::EndLevel()
|
||||||
|
{
|
||||||
|
Events::StageCleared e;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
//
|
||||||
|
// Created by Adniklastrator on 2015-09-10.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "PrecompiledHeader.h"
|
||||||
|
#include "Game/PadSystem.h"
|
||||||
|
#include "Core/World.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <Game/CPad.h>
|
||||||
|
|
||||||
|
|
||||||
|
void dd::Systems::PadSystem::Initialize()
|
||||||
|
{
|
||||||
|
Events::BindKey r;
|
||||||
|
r.KeyCode = GLFW_KEY_RIGHT;
|
||||||
|
r.Command = "right";
|
||||||
|
EventBroker->Publish(r);
|
||||||
|
|
||||||
|
Events::BindKey l;
|
||||||
|
l.KeyCode = GLFW_KEY_LEFT;
|
||||||
|
l.Command = "left";
|
||||||
|
EventBroker->Publish(l);
|
||||||
|
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dd::Systems::PadSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
if (ent == 0) {
|
||||||
|
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
|
||||||
|
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
|
||||||
|
ent = it->first;
|
||||||
|
transform = m_World->GetComponent<Components::Transform>(ent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transform->Velocity.x < -400.f)
|
||||||
|
{
|
||||||
|
transform->Velocity.x = -400.f;
|
||||||
|
}
|
||||||
|
else if (transform->Velocity.x > 400.f)
|
||||||
|
{
|
||||||
|
transform->Velocity.x = 400.f;
|
||||||
|
}
|
||||||
|
transform->Position += transform->Velocity * (float)dt;
|
||||||
|
transform->Velocity += acceleration * (float)dt;
|
||||||
|
transform->Velocity -= transform->Velocity * (0.9f * (float)dt);
|
||||||
|
|
||||||
|
if (left)
|
||||||
|
{
|
||||||
|
acceleration.x = -20.f;
|
||||||
|
}
|
||||||
|
else if (right)
|
||||||
|
{
|
||||||
|
acceleration.x = 20.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
acceleration.x = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||||
|
{
|
||||||
|
int val = event.KeyCode;
|
||||||
|
if (val == 265)
|
||||||
|
{
|
||||||
|
//std::cout << "Up!" << std::endl;
|
||||||
|
}
|
||||||
|
else if (val == 264)
|
||||||
|
{
|
||||||
|
//std::cout << "Down!" << std::endl;
|
||||||
|
}
|
||||||
|
else if (val == 263)
|
||||||
|
{
|
||||||
|
//std::cout << "Left!" << std::endl;
|
||||||
|
//acceleration.x = -0.01f;
|
||||||
|
left = true;
|
||||||
|
}
|
||||||
|
else if (val = 262)
|
||||||
|
{
|
||||||
|
//std::cout << "Right!" << std::endl;
|
||||||
|
//acceleration.x = 0.01f;
|
||||||
|
right = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
||||||
|
{
|
||||||
|
int val = event.KeyCode;
|
||||||
|
if (val == 265)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (val == 264)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (val == 263)
|
||||||
|
{
|
||||||
|
left = false;
|
||||||
|
}
|
||||||
|
else if (val = 262)
|
||||||
|
{
|
||||||
|
right = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||||
|
{
|
||||||
|
EntityID entityBall = event.Entity2;
|
||||||
|
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
||||||
|
if (ball == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
EntityID entityPad = event.Entity1;
|
||||||
|
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
|
||||||
|
if (pad == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||||
|
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
|
||||||
|
|
||||||
|
float movementMultiplier = 2.f;
|
||||||
|
|
||||||
|
float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||||
|
float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
|
||||||
|
|
||||||
|
std::cout << movementX << " " << movementY << std::endl;
|
||||||
|
|
||||||
|
//Temporary solution. Add a new ball and delete the old one.
|
||||||
|
auto ent = m_World->CreateEntity();
|
||||||
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
|
transform->Position = glm::vec3(transformBall->Position.x, transformBall->Position.y + 0.1f, -10.f);
|
||||||
|
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
|
sprite->SpriteFile = "Textures/Ball.png";
|
||||||
|
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||||
|
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
|
||||||
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
|
physics->Static = false;
|
||||||
|
|
||||||
|
m_World->RemoveEntity(entityBall);
|
||||||
|
m_World->CommitEntity(ent);
|
||||||
|
|
||||||
|
Events::SetImpulse e;
|
||||||
|
e.Entity = ent;
|
||||||
|
e.Impulse = glm::vec2(movementX, movementY);
|
||||||
|
e.Point = glm::vec2(event.ContactPoint);
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
|
{
|
||||||
|
std::string command = event.Command;
|
||||||
|
|
||||||
|
std::cout << "Command!" << std::endl;
|
||||||
|
|
||||||
|
if (command == "right")
|
||||||
|
{
|
||||||
|
std::cout << "Right!" << std::endl;
|
||||||
|
}
|
||||||
|
else if (command == "left")
|
||||||
|
{
|
||||||
|
std::cout << "Left!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ void dd::Systems::PhysicsSystem::Initialize()
|
|||||||
{
|
{
|
||||||
m_ContactListener = new ContactListener(this);
|
m_ContactListener = new ContactListener(this);
|
||||||
|
|
||||||
m_Gravity = b2Vec2(0.f, -9.82f);
|
m_Gravity = b2Vec2(0.f, 0.f);
|
||||||
m_PhysicsWorld = new b2World(m_Gravity);
|
m_PhysicsWorld = new b2World(m_Gravity);
|
||||||
|
|
||||||
m_TimeStep = 1.f/60.f;
|
m_TimeStep = 1.f/60.f;
|
||||||
@@ -188,7 +188,7 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
|||||||
b2FixtureDef fixtureDef;
|
b2FixtureDef fixtureDef;
|
||||||
fixtureDef.shape = pShape;
|
fixtureDef.shape = pShape;
|
||||||
fixtureDef.density = 1.f;
|
fixtureDef.density = 1.f;
|
||||||
fixtureDef.restitution = 0.0f;
|
fixtureDef.restitution = 1.0f;
|
||||||
fixtureDef.friction = 0.3f;
|
fixtureDef.friction = 0.3f;
|
||||||
body->CreateFixture(&fixtureDef);
|
body->CreateFixture(&fixtureDef);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,12 @@
|
|||||||
#include "Transform/TransformSystem.h"
|
#include "Transform/TransformSystem.h"
|
||||||
#include "Core/World.h"
|
#include "Core/World.h"
|
||||||
|
|
||||||
|
void dd::Systems::TransformSystem::Update(double dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 dd::Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
glm::vec3 dd::Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||||
{
|
{
|
||||||
glm::vec3 absPosition;
|
glm::vec3 absPosition;
|
||||||
|
|||||||