Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
This commit is contained in:
@@ -15,6 +15,7 @@ struct SoundEmitter : Component
|
||||
float ReferenceDistance;
|
||||
float Pitch;
|
||||
bool Loop;
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ void GameWorld::Initialize()
|
||||
|
||||
AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
//AddSystem("CollisionSystem");
|
||||
AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
AddSystem("PlayerSystem");
|
||||
AddSystem("SoundSystem");
|
||||
@@ -17,19 +17,25 @@ void GameWorld::Initialize()
|
||||
std::shared_ptr<Components::Model> model;
|
||||
std::shared_ptr<Components::PointLight> pointLight;
|
||||
std::shared_ptr<Components::Camera> camera;
|
||||
std::shared_ptr<Components::Bounds> bounds;
|
||||
std::shared_ptr<Components::Collision> collision;
|
||||
EntityID ent;
|
||||
|
||||
// Camera
|
||||
ent = CreateEntity();
|
||||
SetProperty(ent, "Name", std::string("Camera"));
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
AddComponent<Components::Input>(ent, "Input");
|
||||
entcamera = CreateEntity();
|
||||
SetProperty(entcamera, "Name", std::string("Camera"));
|
||||
transform = AddComponent<Components::Transform>(entcamera, "Transform");
|
||||
AddComponent<Components::Input>(entcamera, "Input");
|
||||
transform->Position = glm::vec3(0.f, 10.f, 14.f);
|
||||
camera = AddComponent<Components::Camera>(ent, "Camera");
|
||||
camera = AddComponent<Components::Camera>(entcamera, "Camera");
|
||||
camera->FOV = 45.f;
|
||||
camera->FarClip = 1000.f;
|
||||
camera->NearClip = 0.01f;
|
||||
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
|
||||
collision = AddComponent<Components::Collision>(entcamera, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(entcamera, "Bounds");
|
||||
bounds->VolumeVector = glm::vec3(0.1f,0.1f,0.1f);
|
||||
|
||||
// Fucking lights
|
||||
ent = CreateEntity();
|
||||
@@ -87,20 +93,27 @@ void GameWorld::Initialize()
|
||||
m_Player = CreateEntity();
|
||||
SetProperty(m_Player, "Name", std::string("PlayerShip"));
|
||||
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||
transform->Position = glm::vec3(0.f, 4.f, -5.f);
|
||||
transform->Scale = glm::vec3(1.0f);
|
||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||
model->ModelFile = "Models/ship.obj";
|
||||
AddComponent<Components::Input>(m_Player, "Input");
|
||||
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||
bounds->Origin = glm::vec3(0.f, 0.f, 2.f);
|
||||
bounds->VolumeVector = glm::vec3(3.0f, 0.5f, 2.0f);
|
||||
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3);
|
||||
bounds->VolumeVector = glm::vec3(4.f,0.7f,4);
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "Models/ship.obj";
|
||||
collision = AddComponent<Components::Collision>(player2, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(player2, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
@@ -130,7 +143,7 @@ void GameWorld::RegisterSystems()
|
||||
{
|
||||
m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
#include "GameWorld.h"
|
||||
|
||||
|
||||
void GameWorld::Initialize()
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
//AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
AddSystem("PlayerSystem");
|
||||
AddSystem("SoundSystem");
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
std::shared_ptr<Components::Transform> transform;
|
||||
std::shared_ptr<Components::Model> model;
|
||||
std::shared_ptr<Components::PointLight> pointLight;
|
||||
std::shared_ptr<Components::Camera> camera;
|
||||
std::shared_ptr<Components::Bounds> bounds;
|
||||
std::shared_ptr<Components::Collision> collision;
|
||||
EntityID ent;
|
||||
|
||||
// Camera
|
||||
entcamera = CreateEntity();
|
||||
SetProperty(entcamera, "Name", std::string("Camera"));
|
||||
transform = AddComponent<Components::Transform>(entcamera, "Transform");
|
||||
AddComponent<Components::Input>(entcamera, "Input");
|
||||
transform->Position = glm::vec3(0.f, 2.f, 10.f);
|
||||
camera = AddComponent<Components::Camera>(entcamera, "Camera");
|
||||
camera->FOV = 45.f;
|
||||
camera->FarClip = 1000.f;
|
||||
camera->NearClip = 0.01f;
|
||||
transform->Orientation = glm::angleAxis<float>(glm::radians(25.0f),glm::vec3(1,0,0));
|
||||
collision = AddComponent<Components::Collision>(entcamera, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(entcamera, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(4.f,2.f,2.f);
|
||||
|
||||
// Fucking lights
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||
transform->Position = glm::vec3(10.f, 2.f, 5.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "sphere.obj";
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||
transform->Position = glm::vec3(0.f, 2.f, 5.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Specular = glm::vec3(3.0, 3.0, 3.0);
|
||||
pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "sphere.obj";
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, -4.f, 0.f);
|
||||
transform->Position = glm::vec3(-10.f, 2.f, 5.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "sphere.obj";
|
||||
|
||||
//ground
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "plane.obj";
|
||||
|
||||
// Player
|
||||
<<<<<<< HEAD
|
||||
player1 = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(player1, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(player1, "Model");
|
||||
model->ModelFile = "ship.obj";
|
||||
collision = AddComponent<Components::Collision>(player1, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(player1, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(10.f,10.f,5.f);
|
||||
|
||||
|
||||
player2 = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(player2, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(player2, "Model");
|
||||
=======
|
||||
m_Player = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||
model->ModelFile = "ship.obj";
|
||||
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||
bounds->Origin = glm::vec3(0.f);
|
||||
bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f);
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
|
||||
model->ModelFile = "ship.obj";
|
||||
collision = AddComponent<Components::Collision>(player2, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(player2, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(2.f,2.f,2.f);
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
{
|
||||
World::Update(dt);
|
||||
<<<<<<< HEAD
|
||||
if(GetSystem<Systems::CollisionSystem>("CollisionSystem")->Intersects(player1, entcamera))
|
||||
assert(false);
|
||||
=======
|
||||
|
||||
auto transform = GetComponent<Components::Transform>(m_Player, "Transform");
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>(dt, glm::vec3(0, 0, 1));
|
||||
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
{
|
||||
m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); });
|
||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
||||
m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); });
|
||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
||||
m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); });
|
||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
||||
m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
{
|
||||
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
|
||||
EntityID entcamera, player2;
|
||||
EntityID m_Player;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,142 +30,24 @@
|
||||
class GameWorld : public World
|
||||
{
|
||||
public:
|
||||
GameWorld(std::shared_ptr<Renderer> renderer);
|
||||
void Initialize() override;
|
||||
GameWorld(std::shared_ptr<Renderer> renderer)
|
||||
: m_Renderer(renderer), World() { }
|
||||
|
||||
void Initialize();
|
||||
|
||||
void RegisterSystems() override;
|
||||
void RegisterComponents() override;
|
||||
|
||||
void Update(double dt) override;
|
||||
void Update(double dt) ;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
<<<<<<< HEAD
|
||||
EntityID entcamera, player1, player2;
|
||||
=======
|
||||
|
||||
EntityID m_Player;
|
||||
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
GameWorld::GameWorld(std::shared_ptr<Renderer> renderer)
|
||||
: m_Renderer(renderer), World()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GameWorld::Initialize()
|
||||
{
|
||||
World::Initialize();
|
||||
|
||||
//AddSystem("LevelGenerationSystem");
|
||||
AddSystem("InputSystem");
|
||||
//AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
AddSystem("PlayerSystem");
|
||||
AddSystem("SoundSystem");
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
std::shared_ptr<Components::Transform> transform;
|
||||
std::shared_ptr<Components::Model> model;
|
||||
std::shared_ptr<Components::PointLight> pointLight;
|
||||
std::shared_ptr<Components::Camera> camera;
|
||||
EntityID ent;
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 4.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, -4.f, 0.f);
|
||||
pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
|
||||
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0);
|
||||
pointLight->constantAttenuation = 0.f;
|
||||
pointLight->linearAttenuation = 1.f;
|
||||
pointLight->quadraticAttenuation = 0.f;
|
||||
pointLight->spotExponent = 0.0f;
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(10.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "ship.obj";
|
||||
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "ship.obj";
|
||||
// auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||
// soundEmitter->Gain = 1;
|
||||
// soundEmitter->MaxDistance = FLT_MAX;
|
||||
// soundEmitter->ReferenceDistance = 10;
|
||||
// soundEmitter->Loop = true;
|
||||
// soundEmitter->ReferenceDistance = 0.1;
|
||||
// soundEmitter->Pitch = 1;
|
||||
// GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
|
||||
|
||||
ent = CreateEntity();
|
||||
SetProperty(ent, "Name", std::string("Camera"));
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
AddComponent<Components::Input>(ent, "Input");
|
||||
transform->Position = glm::vec3(0.f, 2.f, 10.f);
|
||||
camera = AddComponent<Components::Camera>(ent, "Camera");
|
||||
camera->FOV = 45.f;
|
||||
camera->FarClip = 1000.f;
|
||||
camera->NearClip = 0.01f;
|
||||
transform->Orientation = glm::angleAxis<float>(glm::radians(25.0f),glm::vec3(1,0,0));
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
{
|
||||
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
||||
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
||||
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
{
|
||||
m_ComponentFactory.Register("Bounds", []() { return new Components::Bounds(); });
|
||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
||||
m_ComponentFactory.Register("Collision", []() { return new Components::Collision(); });
|
||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
||||
m_ComponentFactory.Register("PowerUp", []() { return new Components::PowerUp(); });
|
||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
||||
m_ComponentFactory.Register("Stat", []() { return new Components::Stat(); });
|
||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||
}
|
||||
|
||||
void GameWorld::Update(double dt)
|
||||
{
|
||||
World::Update(dt);
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> origin/master
|
||||
#endif // GameWorld_h__
|
||||
|
||||
@@ -131,10 +131,19 @@ void Renderer::Draw(double dt)
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
m_ShaderProgramDebugAABB.Bind();
|
||||
for (auto aabbModelMatrix : AABBsToRender) {
|
||||
for (auto tuple : AABBsToRender) {
|
||||
glm::mat4 modelMatrix;
|
||||
bool colliding;
|
||||
std::tie(modelMatrix, colliding) = tuple;
|
||||
// Model matrix
|
||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
glm::mat4 MVP = cameraMatrix * aabbModelMatrix;
|
||||
glm::mat4 MVP = cameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
// Color
|
||||
glm::vec4 color(1.f, 1.f, 1.f, 0.f);
|
||||
if (colliding)
|
||||
color = glm::vec4(1.f, 0.f, 0.f, 0.f);
|
||||
glUniform4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "Color"), 1, glm::value_ptr(color));
|
||||
glBindVertexArray(m_DebugAABB);
|
||||
glDrawArrays(GL_LINES, 0, 24);
|
||||
}
|
||||
@@ -318,6 +327,14 @@ void Renderer::AddPointLightToDraw(
|
||||
|
||||
}
|
||||
|
||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding)
|
||||
{
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(origin);
|
||||
model *= glm::scale(volumeVector);
|
||||
AABBsToRender.push_back(std::make_tuple(model, colliding));
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateQuad()
|
||||
{
|
||||
float quadVertices[] = {
|
||||
@@ -409,11 +426,3 @@ GLuint Renderer::CreateAABB()
|
||||
|
||||
return vao;
|
||||
}
|
||||
|
||||
void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector)
|
||||
{
|
||||
glm::mat4 model;
|
||||
model *= glm::translate(origin);
|
||||
model *= glm::scale(volumeVector);
|
||||
AABBsToRender.push_back(model);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
std::vector<float> Light_linearAttenuation;
|
||||
std::vector<float> Light_quadraticAttenuation;
|
||||
std::vector<float> Light_spotExponent;
|
||||
std::vector<glm::mat4> AABBsToRender;
|
||||
std::vector<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||
|
||||
Renderer();
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
float _quadraticAttenuation,
|
||||
float _spotExponent
|
||||
);
|
||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector);
|
||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector, bool colliding);
|
||||
|
||||
void LoadContent();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 430
|
||||
|
||||
uniform vec4 Color;
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
@@ -11,5 +13,5 @@ out vec4 FragmentColor;
|
||||
|
||||
void main() {
|
||||
//FragmentColor = vec4(1.0 - gl_Color.r, 1.0 - gl_Color.g, 1.0 - gl_Color.b, 0.0);
|
||||
FragmentColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
FragmentColor = Color;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
if (parent != 0)
|
||||
/*if (parent != 0)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
@@ -11,6 +11,115 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
transform->Position[0] += parentTransform->Position[0];
|
||||
transform->Position[1] += parentTransform->Position[1];
|
||||
transform->Position[2] += parentTransform->Position[2];
|
||||
}*/
|
||||
|
||||
auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
if (!collisionComponent)
|
||||
return;
|
||||
|
||||
// Clear old collisions
|
||||
collisionComponent->CollidingEntities.clear();
|
||||
|
||||
auto entities = m_World->GetEntities();
|
||||
|
||||
for (auto pair : *entities) {
|
||||
EntityID entity2 = pair.first;
|
||||
EntityID parent2 = pair.second;
|
||||
|
||||
// Check if entity2 is a child of entity
|
||||
/*auto currentParent = parent;
|
||||
bool childOfEntity2 = false;
|
||||
while (currentParent != 0) {
|
||||
if (currentParent == entity2) {
|
||||
childOfEntity2 = true;
|
||||
break;
|
||||
}
|
||||
currentParent = entities[currentParent];
|
||||
}
|
||||
if (childOfEntity2)
|
||||
continue;*/
|
||||
|
||||
// Check if we're the parent to entity2
|
||||
|
||||
//pair.first, pair.second;
|
||||
if(entity == entity2)
|
||||
break;
|
||||
Intersects(entity, entity2);
|
||||
}
|
||||
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
||||
}
|
||||
|
||||
void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
||||
{
|
||||
auto aTransform = m_World->GetComponent<Components::Transform>(aEntity, "Transform");
|
||||
if(aTransform == nullptr)
|
||||
return;
|
||||
auto bTransform = m_World->GetComponent<Components::Transform>(bEntity, "Transform");
|
||||
if(bTransform == nullptr)
|
||||
return;
|
||||
|
||||
auto aCollisionComponent = m_World->GetComponent<Components::Collision>(aEntity, "Collision");
|
||||
if(aCollisionComponent == nullptr)
|
||||
return;
|
||||
auto bCollisionComponent = m_World->GetComponent<Components::Collision>(bEntity, "Collision");
|
||||
if(bCollisionComponent == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
||||
|
||||
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
||||
|
||||
glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale);
|
||||
glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale);
|
||||
|
||||
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
||||
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
||||
glm::vec3 bMax = bPos + bBounds->VolumeVector * bTransform->Scale;
|
||||
glm::vec3 bMin = bPos - bBounds->VolumeVector * bTransform->Scale;
|
||||
|
||||
if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
|
||||
if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
|
||||
if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
|
||||
aCollisionComponent->CollidingEntities.push_back(aEntity);
|
||||
bCollisionComponent->CollidingEntities.push_back(bEntity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr<Components::Bounds> bounds)
|
||||
{
|
||||
float width = abs(bounds->VolumeVector.x);
|
||||
float height = abs(bounds->VolumeVector.y);
|
||||
float depth = abs(bounds->VolumeVector.z);
|
||||
|
||||
GLfloat vertices[] = {
|
||||
bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0,
|
||||
};
|
||||
|
||||
GLuint vbo_vertices;
|
||||
glGenBuffers(1, &vbo_vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
GLushort elements[] = {
|
||||
0, 1, 2, 3,
|
||||
4, 5, 6, 7,
|
||||
0, 4, 1, 5,
|
||||
2, 6, 3, 7
|
||||
};
|
||||
GLuint ibo_elements;
|
||||
glGenBuffers(1, &ibo_elements);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
#include "System.h"
|
||||
#include "logging.h"
|
||||
#include <glew-1.10.0/include/GL/glew.h>
|
||||
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Bounds.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -16,6 +19,8 @@ public:
|
||||
: System(world) { }
|
||||
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void Intersects(EntityID, EntityID);
|
||||
void CreateBoundingBox(std::shared_ptr<Components::Bounds>);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -59,8 +59,16 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
if(collision->CollidingEntities.size() > 0) {
|
||||
// DO STUFF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "PlayerShip")
|
||||
{
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Input.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
||||
|
||||
// Debug draw bounds
|
||||
#ifdef DEBUG
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector);
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Systems
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
#include "Components/SoundEmitter.h"
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
namespace Systems
|
||||
@@ -30,11 +28,11 @@ private:
|
||||
|
||||
//File-info
|
||||
char type[4];
|
||||
DWORD size, chunkSize;
|
||||
unsigned long size, chunkSize;
|
||||
short formatType, channels;
|
||||
DWORD sampleRate, avgBytesPerSec;
|
||||
unsigned long sampleRate, avgBytesPerSec;
|
||||
short bytesPerSample, bitsPerSample;
|
||||
DWORD dataSize;
|
||||
unsigned long dataSize;
|
||||
|
||||
|
||||
std::map<Component*, ALuint> m_Source;
|
||||
|
||||
@@ -103,7 +103,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&size, sizeof(DWORD), 1, fp);
|
||||
fread(&size, sizeof(unsigned long), 1, fp);
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E') {
|
||||
LOG_ERROR("ERROR: Not WAVE-file");
|
||||
@@ -117,11 +117,11 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
}
|
||||
|
||||
//READ THE DATA FROM WAVE-FILE
|
||||
fread(&chunkSize, sizeof(DWORD), 1, fp);
|
||||
fread(&chunkSize, sizeof(unsigned long), 1, fp);
|
||||
fread(&formatType, sizeof(short), 1, fp);
|
||||
fread(&channels, sizeof(short), 1, fp);
|
||||
fread(&sampleRate, sizeof(DWORD), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(DWORD), 1, fp);
|
||||
fread(&sampleRate, sizeof(unsigned long), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(unsigned long), 1, fp);
|
||||
fread(&bytesPerSample, sizeof(short), 1, fp);
|
||||
fread(&bitsPerSample, sizeof(short), 1, fp);
|
||||
|
||||
@@ -132,10 +132,10 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&dataSize, sizeof(DWORD), 1, fp);
|
||||
fread(&dataSize, sizeof(unsigned long), 1, fp);
|
||||
|
||||
unsigned char* buf = new unsigned char[dataSize];
|
||||
fread(buf, sizeof(BYTE), dataSize, fp);
|
||||
fread(buf, sizeof(unsigned char), dataSize, fp);
|
||||
fclose(fp);
|
||||
|
||||
// Create buffer
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
// Recursively update through the scene graph
|
||||
void RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity);
|
||||
|
||||
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
|
||||
|
||||
protected:
|
||||
SystemFactory m_SystemFactory;
|
||||
ComponentFactory m_ComponentFactory;
|
||||
@@ -77,8 +79,7 @@ protected:
|
||||
EntityID m_LastEntityID;
|
||||
std::stack<EntityID> m_RecycledEntityIDs;
|
||||
// A bottom to top tree. A map of child entities to parent entities.
|
||||
std::unordered_map<EntityID, EntityID> m_EntityParents;
|
||||
|
||||
std::unordered_map<EntityID, EntityID> m_EntityParents ;
|
||||
std::unordered_map<EntityID, std::unordered_map<std::string, boost::any>> m_EntityProperties;
|
||||
|
||||
std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
|
||||
|
||||
Reference in New Issue
Block a user