Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/GameWorld.cpp Escape-the-Dawn/GameWorld.h
This commit is contained in:
@@ -15,6 +15,7 @@ struct SoundEmitter : Component
|
||||
float ReferenceDistance;
|
||||
float Pitch;
|
||||
bool Loop;
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -166,6 +166,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Fragment2.glsl" />
|
||||
<None Include="Shaders\AABB.frag.glsl" />
|
||||
<None Include="Shaders\Fragment.glsl" />
|
||||
<None Include="Shaders\Normals.frag.glsl" />
|
||||
<None Include="Shaders\Normals.geo.glsl" />
|
||||
|
||||
@@ -176,6 +176,9 @@
|
||||
<None Include="Shaders\VisualizeDepth.vert.glsl">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="Shaders\AABB.frag.glsl">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Systems">
|
||||
|
||||
@@ -35,8 +35,7 @@ void GameWorld::Initialize()
|
||||
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);
|
||||
bounds->VolumeVector = glm::vec3(0.1f,0.1f,0.1f);
|
||||
|
||||
// Fucking lights
|
||||
ent = CreateEntity();
|
||||
@@ -86,21 +85,22 @@ void GameWorld::Initialize()
|
||||
//ground
|
||||
ent = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, -4.f, 0.f);
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(ent, "Model");
|
||||
model->ModelFile = "plane.obj";
|
||||
|
||||
// Player
|
||||
player1 = CreateEntity();
|
||||
transform = AddComponent<Components::Transform>(player1, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||
model = AddComponent<Components::Model>(player1, "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";
|
||||
collision = AddComponent<Components::Collision>(player1, "Collision");
|
||||
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
||||
collision->Phantom = false;
|
||||
bounds = AddComponent<Components::Bounds>(player1, "Bounds");
|
||||
bounds->Origin = transform->Position;
|
||||
bounds->VolumeVector = glm::vec3(10.f,10.f,5.f);
|
||||
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);
|
||||
bounds->VolumeVector = glm::vec3(1.f,0.7f,1.f);
|
||||
|
||||
|
||||
player2 = CreateEntity();
|
||||
@@ -118,8 +118,11 @@ void GameWorld::Initialize()
|
||||
void GameWorld::Update(double dt)
|
||||
{
|
||||
World::Update(dt);
|
||||
if(GetSystem<Systems::CollisionSystem>("CollisionSystem")->Intersects(player1, entcamera))
|
||||
if(GetSystem<Systems::CollisionSystem>("CollisionSystem")->Intersects(m_Player, entcamera))
|
||||
assert(false);
|
||||
|
||||
auto transform = GetComponent<Components::Transform>(m_Player, "Transform");
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>(dt, glm::vec3(0, 0, 1));
|
||||
}
|
||||
|
||||
void GameWorld::RegisterComponents()
|
||||
|
||||
@@ -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,8 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
EntityID entcamera, player1, player2;
|
||||
EntityID entcamera, player2;
|
||||
EntityID m_Player;
|
||||
};
|
||||
|
||||
#endif // GameWorld_h__
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -218,7 +218,9 @@ void OBJ::ParseMaterial()
|
||||
// Texture file
|
||||
// TODO:
|
||||
if (prefix == "map_Ka" || prefix == "map_Kd") {
|
||||
ss >> currentMaterial->TextureFile;
|
||||
std::string textureFile;
|
||||
ss >> textureFile;
|
||||
currentMaterial->TextureFile = (m_MaterialPath.branch_path() / textureFile).string();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ Renderer::Renderer()
|
||||
m_DrawWireframe = false;
|
||||
|
||||
m_SunPosition = glm::vec3(0, 10, 10);
|
||||
m_SunTarget = glm::vec3(0);
|
||||
m_SunTarget = glm::vec3(0, 0, 0);
|
||||
m_SunProjection = glm::ortho<float>(-20, 20, -20, 20, -10, 20);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,12 @@ void Renderer::LoadContent()
|
||||
m_ShaderProgramShadowsDrawDepth.Compile();
|
||||
m_ShaderProgramShadowsDrawDepth.Link();
|
||||
|
||||
m_ShaderProgramDebugAABB.AddShader(standardVS);
|
||||
m_ShaderProgramDebugAABB.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/AABB.frag.glsl")));
|
||||
m_ShaderProgramDebugAABB.Compile();
|
||||
m_ShaderProgramDebugAABB.Link();
|
||||
|
||||
m_DebugAABB = CreateAABB();
|
||||
m_ScreenQuad = CreateQuad();
|
||||
CreateShadowMap(2048*2);
|
||||
}
|
||||
@@ -116,9 +122,25 @@ void Renderer::CreateShadowMap(int resolution)
|
||||
}
|
||||
void Renderer::Draw(double dt)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
DrawShadowMap();
|
||||
DrawScene();
|
||||
|
||||
#ifdef DEBUG
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
|
||||
m_ShaderProgramDebugAABB.Bind();
|
||||
for (auto aabbModelMatrix : AABBsToRender) {
|
||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||
glm::mat4 MVP = cameraMatrix * aabbModelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramDebugAABB.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glBindVertexArray(m_DebugAABB);
|
||||
glDrawArrays(GL_LINES, 0, 24);
|
||||
}
|
||||
AABBsToRender.clear();
|
||||
#endif
|
||||
|
||||
DrawDebugShadowMap();
|
||||
|
||||
ModelsToRender.clear();
|
||||
@@ -336,4 +358,63 @@ GLuint Renderer::CreateQuad()
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
return vao;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint Renderer::CreateAABB()
|
||||
{
|
||||
float vertices[] = {
|
||||
// Bottom
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
|
||||
// Top
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
|
||||
// Connectors
|
||||
-1.0f, -1.0f, 1.0f, // 0
|
||||
-1.0f, 1.0f, 1.0f, // 4
|
||||
1.0f, -1.0f, 1.0f, // 1
|
||||
1.0f, 1.0f, 1.0f, // 5
|
||||
1.0f, -1.0f, -1.0f, // 2
|
||||
1.0f, 1.0f, -1.0f, // 6
|
||||
-1.0f, -1.0f, -1.0f, // 3
|
||||
-1.0f, 1.0f, -1.0f, // 7
|
||||
};
|
||||
|
||||
GLuint vbo, vao;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
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,6 +46,7 @@ public:
|
||||
std::vector<float> Light_linearAttenuation;
|
||||
std::vector<float> Light_quadraticAttenuation;
|
||||
std::vector<float> Light_spotExponent;
|
||||
std::vector<glm::mat4> AABBsToRender;
|
||||
|
||||
Renderer();
|
||||
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
float _quadraticAttenuation,
|
||||
float _spotExponent
|
||||
);
|
||||
void AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector);
|
||||
|
||||
void LoadContent();
|
||||
|
||||
@@ -87,6 +89,7 @@ private:
|
||||
glm::vec3 m_SunTarget;
|
||||
glm::mat4 m_SunProjection;
|
||||
|
||||
GLuint m_DebugAABB;
|
||||
GLuint m_ScreenQuad;
|
||||
GLuint m_ShadowFrameBuffer;
|
||||
GLuint m_ShadowDepthTexture;
|
||||
@@ -97,6 +100,7 @@ private:
|
||||
ShaderProgram m_ShaderProgramNormals;
|
||||
ShaderProgram m_ShaderProgramShadows;
|
||||
ShaderProgram m_ShaderProgramShadowsDrawDepth;
|
||||
ShaderProgram m_ShaderProgramDebugAABB;
|
||||
|
||||
void DrawScene();
|
||||
void DrawModels(ShaderProgram &shader);
|
||||
@@ -104,6 +108,7 @@ private:
|
||||
void CreateShadowMap(int resolution);
|
||||
GLuint CreateQuad();
|
||||
void DrawDebugShadowMap();
|
||||
GLuint CreateAABB();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#version 430
|
||||
|
||||
in VertexData {
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec3 ShadowCoord;
|
||||
} Input;
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -15,42 +15,42 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
||||
}
|
||||
|
||||
bool Systems::CollisionSystem::Intersects(EntityID entity1, EntityID entity2)
|
||||
bool Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
||||
{
|
||||
auto collisionComponent1 = m_World->GetComponent<Components::Collision>(entity1, "Collision");
|
||||
if(collisionComponent1 == nullptr)
|
||||
auto aTransform = m_World->GetComponent<Components::Transform>(aEntity, "Transform");
|
||||
if(aTransform == nullptr)
|
||||
return false;
|
||||
auto collisionComponent2 = m_World->GetComponent<Components::Collision>(entity2, "Collision");
|
||||
if(collisionComponent2 == nullptr)
|
||||
auto bTransform = m_World->GetComponent<Components::Transform>(bEntity, "Transform");
|
||||
if(bTransform == nullptr)
|
||||
return false;
|
||||
collisionComponent1->CollidingEntities.clear();
|
||||
collisionComponent2->CollidingEntities.clear();
|
||||
|
||||
auto aCollisionComponent = m_World->GetComponent<Components::Collision>(aEntity, "Collision");
|
||||
if(aCollisionComponent == nullptr)
|
||||
return false;
|
||||
auto bCollisionComponent = m_World->GetComponent<Components::Collision>(bEntity, "Collision");
|
||||
if(bCollisionComponent == nullptr)
|
||||
return false;
|
||||
aCollisionComponent->CollidingEntities.clear();
|
||||
bCollisionComponent->CollidingEntities.clear();
|
||||
|
||||
auto bounds1 = m_World->GetComponent<Components::Bounds>(entity1, "Bounds");
|
||||
|
||||
auto bounds2 = m_World->GetComponent<Components::Bounds>(entity2, "Bounds");
|
||||
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
||||
|
||||
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
||||
|
||||
glm::vec3 max1 = glm::vec3(bounds1->Origin.x + bounds1->VolumeVector.x, bounds1->Origin.y + bounds1->VolumeVector.y, bounds1->Origin.z + bounds1->VolumeVector.z);
|
||||
glm::vec3 min1 = glm::vec3(bounds1->Origin.x - bounds1->VolumeVector.x, bounds1->Origin.y - bounds1->VolumeVector.y, bounds1->Origin.z - bounds1->VolumeVector.z);
|
||||
glm::vec3 max2 = glm::vec3(bounds2->Origin.x + bounds2->VolumeVector.x, bounds2->Origin.y + bounds2->VolumeVector.y, bounds2->Origin.z + bounds2->VolumeVector.z);
|
||||
glm::vec3 min2 = glm::vec3(bounds2->Origin.x - bounds2->VolumeVector.x, bounds2->Origin.y - bounds2->VolumeVector.y, bounds2->Origin.z - bounds2->VolumeVector.z);
|
||||
|
||||
|
||||
|
||||
for(int z = min1.z; z < max1.z; z++)
|
||||
if (z > min2.z && z < max2.z)
|
||||
for (int y = min1.y; y < max1.y; y++)
|
||||
if(y > min2.y && y < max2.y)
|
||||
for (int x = min1.x; x < max1.x; x++)
|
||||
if(x > min2.x && x < max2.x)
|
||||
{
|
||||
//vi har en kollision!!! kanske :(
|
||||
collisionComponent1->CollidingEntities.push_back(entity2);
|
||||
collisionComponent2->CollidingEntities.push_back(entity1);
|
||||
return true;
|
||||
}
|
||||
glm::vec3 aMax = aTransform->Position + aBounds->Origin + aBounds->VolumeVector;
|
||||
glm::vec3 aMin = aTransform->Position + aBounds->Origin - aBounds->VolumeVector;
|
||||
glm::vec3 bMax = bTransform->Position + bBounds->Origin + bBounds->VolumeVector;
|
||||
glm::vec3 bMin = bTransform->Position + bBounds->Origin - bBounds->VolumeVector;
|
||||
|
||||
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 true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,19 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
||||
auto model = m_CachedModels[modelComponent->ModelFile];
|
||||
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
||||
}
|
||||
|
||||
// Debug draw bounds
|
||||
#ifdef DEBUG
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + bounds->Origin;
|
||||
m_Renderer->AddAABBToDraw(origin, bounds->VolumeVector);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
if (pointLightComponent != nullptr)
|
||||
{
|
||||
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
transformComponent->Position,
|
||||
pointLightComponent->Specular,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Components/Model.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Systems
|
||||
|
||||
+12
-15
@@ -1,17 +1,14 @@
|
||||
# Blender v2.69 (sub 0) OBJ File: 'obstaclesandstuff.blend'
|
||||
# www.blender.org
|
||||
mtllib plane.mtl
|
||||
o Plane_Plane.001
|
||||
v 102.461288 0.778257 97.553291
|
||||
v -97.538712 0.778257 97.553291
|
||||
v 102.461288 0.778257 -102.446709
|
||||
v -97.538712 0.778257 -102.446709
|
||||
vt 0.000100 0.000100
|
||||
vt 0.999900 0.000100
|
||||
vt 0.000100 0.999900
|
||||
vt 0.999900 0.999900
|
||||
o Plane
|
||||
v -1000 0 1000
|
||||
v 1000 0 1000
|
||||
v 1000 0 -1000
|
||||
v -1000 0 -1000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
usemtl Material.004
|
||||
s off
|
||||
f 2/1/1 1/2/1 4/3/1
|
||||
f 1/2/1 3/4/1 4/3/1
|
||||
vt 0 0
|
||||
vt 1 0
|
||||
vt 1 1
|
||||
vt 0 1
|
||||
usemtl Material.001
|
||||
f 1/1/1 3/3/1 4/4/1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
|
||||
Reference in New Issue
Block a user