Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

Conflicts:
	Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
	Escape-the-Dawn/GameWorld.cpp
This commit is contained in:
Adam
2014-03-14 01:53:22 +01:00
37 changed files with 529 additions and 244 deletions
+18
View File
@@ -78,3 +78,21 @@ void Camera::UpdateViewMatrix()
{ {
m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position); m_ViewMatrix = glm::translate(glm::toMat4(m_Orientation), -m_Position);
} }
void Camera::FOV(float val)
{
m_FOV = val;
UpdateProjectionMatrix();
}
void Camera::NearClip(float val)
{
m_NearClip = val;
UpdateProjectionMatrix();
}
void Camera::FarClip(float val)
{
m_FarClip = val;
UpdateProjectionMatrix();
}
+4 -11
View File
@@ -1,13 +1,7 @@
#ifndef Camera_h__ #ifndef Camera_h__
#define Camera_h__ #define Camera_h__
#define GLM_FORCE_RADIANS #include "GLM.h"
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
class Camera class Camera
{ {
@@ -38,13 +32,13 @@ public:
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; } void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
float FOV() const { return m_FOV; } float FOV() const { return m_FOV; }
void FOV(float val) { m_FOV = val; } void FOV(float val);
float NearClip() const { return m_NearClip; } float NearClip() const { return m_NearClip; }
void NearClip(float val) { m_NearClip = val; } void NearClip(float val);
float FarClip() const { return m_FarClip; } float FarClip() const { return m_FarClip; }
void FarClip(float val) { m_FarClip = val; } void FarClip(float val);
private: private:
void UpdateProjectionMatrix(); void UpdateProjectionMatrix();
@@ -54,7 +48,6 @@ private:
float m_AspectRatio; float m_AspectRatio;
float m_NearClip; float m_NearClip;
float m_FarClip; float m_FarClip;
glm::vec3 m_Position; glm::vec3 m_Position;
glm::quat m_Orientation; glm::quat m_Orientation;
+2
View File
@@ -1,6 +1,8 @@
#ifndef Component_h__ #ifndef Component_h__
#define Component_h__ #define Component_h__
#include "GLM.h"
#include "Factory.h" #include "Factory.h"
#include "Entity.h" #include "Entity.h"
-1
View File
@@ -2,7 +2,6 @@
#define Components_Bounds_h__ #define Components_Bounds_h__
#include "Component.h" #include "Component.h"
#include <glm/common.hpp>
namespace Components namespace Components
{ {
+2
View File
@@ -8,6 +8,8 @@ namespace Components
struct Camera : Component struct Camera : Component
{ {
Camera() : FOV(glm::radians(45.f)), NearClip(0.1f), FarClip(100.f) { }
float FOV; float FOV;
float NearClip; float NearClip;
float FarClip; float FarClip;
+3 -1
View File
@@ -11,8 +11,10 @@ namespace Components
struct Model : Component struct Model : Component
{ {
const char* ModelFile; Model() : Visible(true) { }
std::string ModelFile;
Color Color; Color Color;
bool Visible;
}; };
} }
-1
View File
@@ -2,7 +2,6 @@
#define Components_Transform_h__ #define Components_Transform_h__
#include "Component.h" #include "Component.h"
#include <glm/gtc/quaternion.hpp>
namespace Components namespace Components
{ {
+3
View File
@@ -112,6 +112,7 @@
<ClCompile Include="ShaderProgram.cpp" /> <ClCompile Include="ShaderProgram.cpp" />
<ClCompile Include="Skybox.cpp" /> <ClCompile Include="Skybox.cpp" />
<ClCompile Include="Systems\CollisionSystem.cpp" /> <ClCompile Include="Systems\CollisionSystem.cpp" />
<ClCompile Include="Systems\TransformSystem.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="TextFrame.cpp" /> <ClCompile Include="TextFrame.cpp" />
<ClCompile Include="World.cpp" /> <ClCompile Include="World.cpp" />
@@ -146,6 +147,7 @@
<ClInclude Include="Frame.h" /> <ClInclude Include="Frame.h" />
<ClInclude Include="GameFrame.h" /> <ClInclude Include="GameFrame.h" />
<ClInclude Include="GameWorld.h" /> <ClInclude Include="GameWorld.h" />
<ClInclude Include="GLM.h" />
<ClInclude Include="GUIManager.h" /> <ClInclude Include="GUIManager.h" />
<ClInclude Include="logging.h" /> <ClInclude Include="logging.h" />
<ClInclude Include="glerror.h" /> <ClInclude Include="glerror.h" />
@@ -165,6 +167,7 @@
<ClInclude Include="Systems\PlayerSystem.h" /> <ClInclude Include="Systems\PlayerSystem.h" />
<ClInclude Include="Systems\RenderSystem.h" /> <ClInclude Include="Systems\RenderSystem.h" />
<ClInclude Include="Systems\SoundSystem.h" /> <ClInclude Include="Systems\SoundSystem.h" />
<ClInclude Include="Systems\TransformSystem.h" />
<ClInclude Include="Texture.h" /> <ClInclude Include="Texture.h" />
<ClInclude Include="TextFrame.h" /> <ClInclude Include="TextFrame.h" />
<ClInclude Include="World.h" /> <ClInclude Include="World.h" />
@@ -49,6 +49,9 @@
<ClCompile Include="GameWorld.cpp" /> <ClCompile Include="GameWorld.cpp" />
<ClCompile Include="Skybox.cpp" /> <ClCompile Include="Skybox.cpp" />
<ClCompile Include="CubemapTexture.cpp" /> <ClCompile Include="CubemapTexture.cpp" />
<ClCompile Include="Systems\TransformSystem.cpp">
<Filter>Systems</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Component.h" /> <ClInclude Include="Component.h" />
@@ -152,6 +155,10 @@
<ClInclude Include="OpenGL.h" /> <ClInclude Include="OpenGL.h" />
<ClInclude Include="Skybox.h" /> <ClInclude Include="Skybox.h" />
<ClInclude Include="CubemapTexture.h" /> <ClInclude Include="CubemapTexture.h" />
<ClInclude Include="Systems\TransformSystem.h">
<Filter>Systems</Filter>
</ClInclude>
<ClInclude Include="GLM.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Shaders\Fragment.glsl"> <None Include="Shaders\Fragment.glsl">
+77 -14
View File
@@ -3,51 +3,74 @@
GUI::Frame::Frame() GUI::Frame::Frame()
{ {
rectangle = new Rectangle(); rectangle = new Rectangle();
texture = nullptr;
} }
int GUI::Frame::GetWidth() int GUI::Frame::GetWidth()
{ {
return rectangle; return rectangle->Width();
} }
int GUI::Frame::GetHeight() int GUI::Frame::GetHeight()
{ {
return rectangle.Height(); return rectangle->Height();
} }
int GUI::Frame::GetX() int GUI::Frame::GetX()
{ {
return rectangle; return rectangle->X();
} }
int GUI::Frame::GetY() int GUI::Frame::GetY()
{ {
return rectangle.Y(); return rectangle->Y();
} }
void GUI::Frame::SetWidth(int wid) int GUI::Frame::GetRight()
{ {
rectangle.width(wid); return rectangle->Right();
} }
void GUI::Frame::SetHeight(int hei) int GUI::Frame::GetLeft()
{ {
rectangle.height(hei); return rectangle->Left();
} }
void GUI::Frame::SetX(int xcord) int GUI::Frame::GetBottom()
{ {
rectangle.X(xcord) return rectangle->Bottom();
} }
void GUI::Frame::SetY(int ycord) int GUI::Frame::GetTop()
{ {
rectangle.Y(ycord) return rectangle->Right();
} }
void GUI::Frame::SetWidth(int _width)
{
rectangle->Width(_width);
}
void GUI::Frame::SetHeight(int _height)
{
rectangle->Height(_height);
}
void GUI::Frame::SetX(int _x)
{
rectangle->X(_x);
}
void GUI::Frame::SetY(int _y)
{
rectangle->Y(_y);
}
Rectangle GUI::Frame::AbsouluteRectangle() Rectangle GUI::Frame::AbsouluteRectangle()
{ {
} }
bool GUI::Frame::Visible() bool GUI::Frame::Visible()
@@ -85,8 +108,48 @@ void GUI::Frame::Update(double dt)
} }
void AddChild(GUI::Frame childFrame)
{
childFrame.Parent = this;
if (!Children.Contains(childFrame))
Children.Add(childFrame);
}
/// <summary>
/// Remove a child frame from the frame.
/// </summary>
/// <param name="childFrame">The child frame to remove.</param>
void RemoveChild(GUI::Frame childFrame)
{
if (Children.Contains(childFrame))
Children.Remove(childFrame);
}
/// <summary>
/// Destroys the frame and all its children.
/// </summary>
void Destroy()
{
if (Parent != null)
Parent.RemoveChild(this);
Manager.Remove(this);
}
void GUI::Frame::SetTexture(std::string fileName)
{
//texture == någonTextureIDunno;
}
void GUI::Frame::Draw() void GUI::Frame::Draw()
{ {
if (Visible)
{
if (texture != nullptr)
{
//Drawshit
}
}
} }
*/ */
+14 -9
View File
@@ -1,4 +1,4 @@
/*#ifndef Frame_h__ #ifndef Frame_h__
#define Frame_h__ #define Frame_h__
#include <map> #include <map>
@@ -7,7 +7,7 @@
#include "GUIManager.h" #include "GUIManager.h"
#include "Texture.h" #include "Texture.h"
#include "Color.h" #include "Color.h"
//#include "Camera.h" #include "Camera.h"
namespace GUI namespace GUI
{ {
@@ -22,14 +22,19 @@ public:
int GetHeight(); int GetHeight();
int GetX(); int GetX();
int GetY(); int GetY();
void SetWidth(int wid); int GetRight();
void SetHeight(int hei); int GetLeft();
void SetX( int xcord); int GetBottom();
void SetY(int ycord); int GetTop();
void SetWidth(int _width);
void SetHeight(int _height);
void SetX( int _x);
void SetY(int _y);
void SetTexture(std::string fileName);
Rectangle *rectangle; Rectangle *rectangle;
Rectangle AbsouluteRectangle(); Rectangle AbsouluteRectangle();
Texture texture; Texture* texture;
Color color; Color* color;
bool _Visible; bool _Visible;
bool Visible(); bool Visible();
int layer; int layer;
@@ -48,4 +53,4 @@ protected:
}; };
} }
#endif*/ #endif
+9
View File
@@ -0,0 +1,9 @@
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/common.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>
+2 -2
View File
@@ -2,7 +2,7 @@
int GUI::GUIManager::Add(Frame frame) int GUI::GUIManager::Add(Frame frame)
{ {
//Frame.Add(frame); Frame.Add(frame);
//return CreateUID(); return CreateUID();
} }
*/ */
+2 -3
View File
@@ -1,4 +1,4 @@
/*#ifndef GUIManager_h__ #ifndef GUIManager_h__
#define GUIManager_h__ #define GUIManager_h__
#include "Frame.h" #include "Frame.h"
@@ -18,9 +18,8 @@ private:
static int uidIndex; static int uidIndex;
}; };
} }
#endif */ #endif
+53 -35
View File
@@ -5,14 +5,6 @@ void GameWorld::Initialize()
{ {
World::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::Transform> transform;
std::shared_ptr<Components::Model> model; std::shared_ptr<Components::Model> model;
std::shared_ptr<Components::PointLight> pointLight; std::shared_ptr<Components::PointLight> pointLight;
@@ -22,11 +14,8 @@ void GameWorld::Initialize()
std::shared_ptr<Components::SoundEmitter> soundEmitter; std::shared_ptr<Components::SoundEmitter> soundEmitter;
EntityID ent; EntityID ent;
// Fucking lights // Fucking lights
ent = CreateEntity(); /*ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
transform->Position = glm::vec3(0.f, 7.f, 0.f); transform->Position = glm::vec3(0.f, 7.f, 0.f);
pointLight = AddComponent<Components::PointLight>(ent, "PointLight"); pointLight = AddComponent<Components::PointLight>(ent, "PointLight");
@@ -61,7 +50,7 @@ void GameWorld::Initialize()
pointLight->quadraticAttenuation = 0.f; pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f; pointLight->spotExponent = 0.0f;
model = AddComponent<Components::Model>(ent, "Model"); model = AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "Models/sphere.obj"; model->ModelFile = "Models/sphere.obj";*/
//ground //ground
ent = CreateEntity(); ent = CreateEntity();
@@ -77,7 +66,7 @@ void GameWorld::Initialize()
AddComponent<Components::Input>(entcamera, "Input"); AddComponent<Components::Input>(entcamera, "Input");
transform->Position = glm::vec3(0.f, 10.f, 14.f); transform->Position = glm::vec3(0.f, 10.f, 14.f);
camera = AddComponent<Components::Camera>(entcamera, "Camera"); camera = AddComponent<Components::Camera>(entcamera, "Camera");
camera->FOV = 45.f; camera->FOV = glm::radians(45.f);
camera->FarClip = 1000.f; camera->FarClip = 1000.f;
camera->NearClip = 0.01f; camera->NearClip = 0.01f;
transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0)); transform->Orientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
@@ -92,13 +81,6 @@ void GameWorld::Initialize()
transform->Scale = glm::vec3(1.0f); transform->Scale = glm::vec3(1.0f);
model = AddComponent<Components::Model>(m_Player, "Model"); model = AddComponent<Components::Model>(m_Player, "Model");
model->ModelFile = "Models/ship.obj"; model->ModelFile = "Models/ship.obj";
pointLight = AddComponent<Components::PointLight>(m_Player, "PointLight");
pointLight->Specular = glm::vec3(1.0, 1.0, 1.0);
pointLight->Diffuse = glm::vec3(0.4, 0.4, 1.0);
pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.f;
pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f;
AddComponent<Components::Input>(m_Player, "Input"); AddComponent<Components::Input>(m_Player, "Input");
collision = AddComponent<Components::Collision>(m_Player, "Collision"); collision = AddComponent<Components::Collision>(m_Player, "Collision");
collision->Phantom = false; collision->Phantom = false;
@@ -106,20 +88,43 @@ void GameWorld::Initialize()
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds"); bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
bounds->Origin = glm::vec3(0, 0, 2.f); bounds->Origin = glm::vec3(0, 0, 2.f);
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1); bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
soundEmitter = AddComponent<Components::SoundEmitter>(m_Player, "SoundEmitter"); // Player light
soundEmitter->Loop = true; auto playerLight = CreateEntity(m_Player);
//soundEmitter->MaxDistance = 10; transform = AddComponent<Components::Transform>(playerLight, "Transform");
soundEmitter->ReferenceDistance = 10; transform->Position = glm::vec3(1.5f, 0.25f, 2.5f);
soundEmitter->Gain = 1; pointLight = AddComponent<Components::PointLight>(playerLight, "PointLight");
soundEmitter->Pitch = 1; pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
soundEmitter->Path = "Sounds/hallelujah.wav"; pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
//GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter); pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 0.9f;
pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f;
bounds = AddComponent<Components::Bounds>(playerLight, "Bounds");
bounds->VolumeVector = glm::vec3(0.5f);
playerLight = CreateEntity(m_Player);
transform = AddComponent<Components::Transform>(playerLight, "Transform");
transform->Position = glm::vec3(-1.5f, 0.25f, 2.5f);
pointLight = AddComponent<Components::PointLight>(playerLight, "PointLight");
pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 0.9f;
pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f;
bounds = AddComponent<Components::Bounds>(playerLight, "Bounds");
bounds->VolumeVector = glm::vec3(0.5f);
playerLight = CreateEntity(m_Player);
transform = AddComponent<Components::Transform>(playerLight, "Transform");
transform->Position = glm::vec3(0.0f, 2.0f, 2.5f);
pointLight = AddComponent<Components::PointLight>(playerLight, "PointLight");
pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f);
pointLight->constantAttenuation = 0.f;
pointLight->linearAttenuation = 1.0f;
pointLight->quadraticAttenuation = 0.f;
pointLight->spotExponent = 0.0f;
bounds = AddComponent<Components::Bounds>(playerLight, "Bounds");
bounds->VolumeVector = glm::vec3(0.5f);
/*ent = CreateEntity(); /*ent = CreateEntity();
transform = AddComponent<Components::Transform>(ent, "Transform"); transform = AddComponent<Components::Transform>(ent, "Transform");
@@ -164,5 +169,18 @@ void GameWorld::RegisterSystems()
//m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); //m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this); });
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); }); m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
}
void GameWorld::AddSystems()
{
AddSystem("TransformSystem");
AddSystem("LevelGenerationSystem");
AddSystem("InputSystem");
AddSystem("CollisionSystem");
//AddSystem("ParticleSystem");
AddSystem("PlayerSystem");
AddSystem("SoundSystem");
AddSystem("RenderSystem");
} }
+3 -1
View File
@@ -4,6 +4,7 @@
#include "World.h" #include "World.h"
#include "Renderer.h" #include "Renderer.h"
#include "Systems/TransformSystem.h"
#include "Systems/CollisionSystem.h" #include "Systems/CollisionSystem.h"
#include "Systems/InputSystem.h" #include "Systems/InputSystem.h"
#include "Systems/LevelGenerationSystem.h" #include "Systems/LevelGenerationSystem.h"
@@ -36,9 +37,10 @@ public:
void Initialize(); void Initialize();
void RegisterSystems() override; void RegisterSystems() override;
void AddSystems() override;
void RegisterComponents() override; void RegisterComponents() override;
void Update(double dt) ; void Update(double dt);
private: private:
std::shared_ptr<Renderer> m_Renderer; std::shared_ptr<Renderer> m_Renderer;
+1 -4
View File
@@ -9,10 +9,7 @@
#include <memory> #include <memory>
#include "OpenGL.h" #include "OpenGL.h"
#include <glm/glm.hpp> #include "GLM.h"
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <cstdlib> #include <cstdlib>
#include <stack> #include <stack>
+1 -1
View File
@@ -9,4 +9,4 @@ Ks 0.500000 0.500000 0.500000
Ni 1.000000 Ni 1.000000
d 1.000000 d 1.000000
illum 2 illum 2
map_Kd ObstacleTexture.png map_Kd planetexture.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

+1 -2
View File
@@ -1,5 +1,4 @@
#include <GL/glew.h> #include <GL/glew.h>
#define GLFW_INCLUDE_GLU #define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glext.h> #include <glext.h>
#define GLM_FORCE_RADIANS
+8
View File
@@ -22,6 +22,14 @@ public:
int Y() const { return y; } int Y() const { return y; }
void Y(int val) { y = val; } void Y(int val) { y = val; }
int Left() const { return x; }
int Right() const { return x+width; }
int Top() const { return y; }
int Bottom() const { return y+height; }
}; };
Rectangle::Rectangle() Rectangle::Rectangle()
+24 -19
View File
@@ -14,7 +14,7 @@ Renderer::Renderer()
#endif #endif
m_ShadowMapRes = 2048*2; m_ShadowMapRes = 2048*2;
m_SunPosition = glm::vec3(0, 0.3f, 10); m_SunPosition = glm::vec3(0, 1.5f, 10);
m_SunTarget = glm::vec3(0, 0, 0); m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800); m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
Lights = 0; Lights = 0;
@@ -237,7 +237,11 @@ void Renderer::DrawScene()
{ {
Model* model; Model* model;
glm::mat4 modelMatrix; glm::mat4 modelMatrix;
std::tie(model, modelMatrix) = tuple; bool visible;
std::tie(model, modelMatrix, visible) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix; MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix; depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -288,7 +292,8 @@ void Renderer::DrawShadowMap()
{ {
Model* model; Model* model;
glm::mat4 modelMatrix; glm::mat4 modelMatrix;
std::tie(model, modelMatrix) = tuple; bool visible;
std::tie(model, modelMatrix, visible) = tuple;
MVP = depthCamera * modelMatrix; MVP = depthCamera * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -317,26 +322,26 @@ void Renderer::DrawDebugShadowMap()
void Renderer::DrawModels(ShaderProgram &shader) void Renderer::DrawModels(ShaderProgram &shader)
{ {
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix(); /*glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
for (auto tuple : ModelsToRender) for (auto tuple : ModelsToRender)
{ {
Model* model; Model* model;
glm::mat4 modelMatrix; glm::mat4 modelMatrix;
std::tie(model, modelMatrix) = tuple; std::tie(model, modelMatrix) = tuple;
MVP = cameraMatrix * modelMatrix; MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glBindVertexArray(model->VAO); glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups) { for (auto texGroup : model->TextureGroups) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture); glBindTexture(GL_TEXTURE_2D, texGroup.Texture->texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
} }
}*/
} }
void Renderer::DrawText() void Renderer::DrawText()
@@ -349,11 +354,11 @@ void Renderer::AddTextToDraw()
//Add to draw shit vector //Add to draw shit vector
} }
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale) void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible)
{ {
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
// You can now use ModelMatrix to build the MVP matrix // You can now use ModelMatrix to build the MVP matrix
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix)); ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix, visible));
} }
void Renderer::AddPointLightToDraw( void Renderer::AddPointLightToDraw(
+3 -8
View File
@@ -8,12 +8,7 @@
#include <vector> #include <vector>
#include "OpenGL.h" #include "OpenGL.h"
#include <glm/glm.hpp> #include "GLM.h"
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include "glerror.h" #include "glerror.h"
#include "Camera.h" #include "Camera.h"
@@ -31,7 +26,7 @@ public:
int HEIGHT, WIDTH; int HEIGHT, WIDTH;
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender; std::list<std::tuple<Model*, glm::mat4, bool>> ModelsToRender;
int Lights; int Lights;
std::vector<float> Light_position; std::vector<float> Light_position;
std::vector<float> Light_specular; std::vector<float> Light_specular;
@@ -48,7 +43,7 @@ public:
void Draw(double dt); void Draw(double dt);
void DrawText(); void DrawText();
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale); void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale, bool visible);
void AddTextToDraw(); void AddTextToDraw();
void AddPointLightToDraw( void AddPointLightToDraw(
glm::vec3 _position, glm::vec3 _position,
+2 -2
View File
@@ -23,7 +23,7 @@ in VertexData {
vec3 ShadowCoord; vec3 ShadowCoord;
} Input; } Input;
vec3 scene_ambient = vec3(0.3); vec3 scene_ambient = vec3(0.98, 0.95, 0.7);
out vec4 fragmentColor; out vec4 fragmentColor;
@@ -54,7 +54,7 @@ void main() {
float bias = 0.0005; float bias = 0.0005;
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy); vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) { if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) {
visibility = 0.5; visibility = 0.3;
} }
} }
+2
View File
@@ -13,6 +13,8 @@ public:
System(World* world) : m_World(world) { } System(World* world) : m_World(world) { }
virtual ~System() { } virtual ~System() { }
virtual void Initialize() { }
// Called once per system every tick // Called once per system every tick
virtual void Update(double dt) { } virtual void Update(double dt) { }
// Called once for every entity in the world every tick // Called once for every entity in the world every tick
+2 -2
View File
@@ -85,8 +85,8 @@ void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
if (aMin.x <= bMax.x && bMin.x <= aMax.x) { if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
if (aMin.y <= bMax.y && bMin.y <= aMax.y) { if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
if (aMin.z <= bMax.z && bMin.z <= aMax.z) { if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
aCollisionComponent->CollidingEntities.push_back(aEntity); aCollisionComponent->CollidingEntities.push_back(bEntity);
bCollisionComponent->CollidingEntities.push_back(bEntity); bCollisionComponent->CollidingEntities.push_back(aEntity);
return; return;
} }
} }
@@ -8,6 +8,7 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
velocity = 0; velocity = 0;
startx = 0; startx = 0;
startyz = glm::vec2(0, -1000); startyz = glm::vec2(0, -1000);
spawnFrequency = 0.1f;
} }
void Systems::LevelGenerationSystem::SpawnObstacle() void Systems::LevelGenerationSystem::SpawnObstacle()
@@ -17,18 +18,17 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
EntityID ent; EntityID ent;
ent = m_World->CreateEntity(); ent = m_World->CreateEntity();
obstacles.push_back(ent);
m_World->SetProperty(ent, "Name", std::string("Obstacle")); auto transform = m_World->AddComponent<Components::Transform>(ent, "Transform");
transform = m_World->AddComponent<Components::Transform>(ent, "Transform"); auto bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds");
bounds = m_World->AddComponent<Components::Bounds>(ent, "Bounds"); auto collision = m_World->AddComponent<Components::Collision>(ent, "Collision");
collision = m_World->AddComponent<Components::Collision>(ent, "Collision"); auto model = m_World->AddComponent<Components::Model>(ent, "Model");
model = m_World->AddComponent<Components::Model>(ent, "Model");
auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter"); auto sound = m_World->AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
positionRandom = -500 + startx + (rand() % 1000); positionRandom = -500 + startx + (rand() % 1000);
transform->Position = glm::vec3(positionRandom, startyz); transform->Position = glm::vec3(positionRandom, startyz);
//transform->Velocity = glm::vec3(0.f, 10.f, 100.f); transform->Velocity = glm::vec3(0.f, 10.f, 0);
sound->Loop = true; sound->Loop = true;
sound->Gain = 1.f; sound->Gain = 1.f;
@@ -37,7 +37,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
{ {
float scale = (float)(rand() % 1000) / 250; m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 250;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(9, 12, 7); bounds->VolumeVector = glm::vec3(9, 12, 7);
bounds->Origin = glm::vec3(1,11,-1); bounds->Origin = glm::vec3(1,11,-1);
@@ -45,7 +46,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D else if(typeRandom >= 2 && typeRandom < 5) // Single Mountain :D
{ {
float scale = (float)(rand() % 1000) / 200; m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.0f + (float)(rand() % 1000) / 200;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f); bounds->VolumeVector = glm::vec3(3.5f, 7.5f, 3.5f);
bounds->Origin = glm::vec3(0,7.5f,0); bounds->Origin = glm::vec3(0,7.5f,0);
@@ -53,7 +55,8 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
else if(typeRandom >= 5 && typeRandom < 8) else if(typeRandom >= 5 && typeRandom < 8)
{ {
float scale = (float)(rand() % 1000) / 100; m_World->SetProperty(ent, "Name", std::string("Obstacle"));
float scale = 1.f + (float)(rand() % 1000) / 100;
transform->Scale = glm::vec3(scale); transform->Scale = glm::vec3(scale);
bounds->VolumeVector = glm::vec3(1, 1, 1); bounds->VolumeVector = glm::vec3(1, 1, 1);
bounds->Origin = glm::vec3(0,1,0); bounds->Origin = glm::vec3(0,1,0);
@@ -61,20 +64,20 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
} }
if(typeRandom >= 8 && typeRandom < 10) if(typeRandom >= 8 && typeRandom < 10)
{ {
float scale = (float)(rand() % 1000) / 100; m_World->SetProperty(ent, "Name", std::string("PowerUp"));
bounds->VolumeVector = glm::vec3(4, 4, 4); bounds->VolumeVector = glm::vec3(4, 4, 4);
bounds->Origin = glm::vec3(0,4,0); bounds->Origin = glm::vec3(0,4,0);
powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp"); auto powerUp = m_World->AddComponent<Components::PowerUp>(ent, "PowerUp");
powerUp->Speed = 10.f; powerUp->Speed = 200.f;
model->ModelFile = "Models/powerup.obj"; model->ModelFile = "Models/powerup.obj";
} }
// Put it below ground level // Put it below ground level
//transform->Position.y -= bounds->VolumeVector.y * 2.f; transform->Position.y -= bounds->VolumeVector.y * 2.f;
} }
@@ -82,47 +85,47 @@ void Systems::LevelGenerationSystem::Update( double dt )
{ {
elapsedtime += dt; elapsedtime += dt;
spawnFrequency = 10/velocity;
if(elapsedtime > 0.1){ if(elapsedtime > spawnFrequency){
SpawnObstacle(); SpawnObstacle();
elapsedtime = 0; elapsedtime = 0;
} }
std::list<EntityID> removethis;
for(auto ent : obstacles)
{
auto transform = m_World->GetComponent<Components::Transform>(ent, "Transform");
transform->Velocity.z = velocity;
transform->Position += transform->Velocity * (float)dt;
// Stop raising obstacles when they reach ground level
if (transform->Velocity.y > 0 && transform->Position.y >= 0) {
transform->Position.y = 0;
transform->Velocity.y = 0;
}
if(transform->Position.z > 800)
{
removethis.push_back(ent);
}
}
for(auto ent : removethis)
{
m_World->RemoveEntity(ent);
obstacles.remove(ent);
}
removethis.clear();
} }
void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) void Systems::LevelGenerationSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{ {
if( m_World->GetProperty<std::string>(entity, "Name") == "Obstacle" || m_World->GetProperty<std::string>(entity, "Name") == "PowerUp")
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
transform->Velocity.z = velocity;
transform->Position += transform->Velocity * (float)dt;
// Stop raising obstacles when they reach ground level
if (transform->Velocity.y > 0 && transform->Position.y >= 0)
{
transform->Position.y = 0;
transform->Velocity.y = 0;
}
auto model = m_World->GetComponent<Components::Model>(entity, "Model");
if (transform->Position.z > 10 && model->Visible)
{
model->Visible = false;
}
if(transform->Position.z > 800) {
m_World->RemoveEntity(entity);
}
}
if( m_World->GetProperty<std::string>(entity, "Name") == "Player") if( m_World->GetProperty<std::string>(entity, "Name") == "Player")
{ {
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform"); auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
startyz = glm::vec2(0, transformComponent->Position.z - 1000); startyz = glm::vec2(0, transformComponent->Position.z - 1000);
startx = transformComponent->Position.x; startx = transformComponent->Position.x;
velocity = transformComponent->Velocity.z; velocity = transformComponent->Velocity.z;
@@ -31,18 +31,9 @@ namespace Systems
int positionRandom; int positionRandom;
glm::vec2 startyz; glm::vec2 startyz;
float startx; float startx;
double elapsedtime; double elapsedtime;
std::list<EntityID> obstacles;
float velocity; float velocity;
float spawnFrequency;
std::shared_ptr<Components::Transform> transform;
std::shared_ptr<Components::Bounds> bounds;
std::shared_ptr<Components::Collision> collision;
std::shared_ptr<Components::Model> model;
std::shared_ptr<Components::PointLight> pointLight;
std::shared_ptr<Components::PowerUp> powerUp;
}; };
} }
+108 -46
View File
@@ -10,11 +10,14 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
m_CameraOrientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0)); m_CameraOrientation = glm::angleAxis<float>(glm::radians(15.0f),glm::vec3(1,0,0));
freecamEnabled = false; freecamEnabled = false;
m_poweruptimeleft = 0;
m_basespeed = 100.f;
m_maxspeed = 100.f;
} }
void Systems::PlayerSystem::Update(double dt) void Systems::PlayerSystem::Update(double dt)
{ {
m_poweruptimeleft -= (float)dt;
} }
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -26,48 +29,74 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
if (input == nullptr) if (input == nullptr)
return; return;
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto name = m_World->GetProperty<std::string>(entity, "Name"); auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera" && freecamEnabled) { if(collision != nullptr)
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation); {
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation); for(auto ent : collision->CollidingEntities)
{
float speed = m_PlayerSpeed; if(m_World->GetProperty<std::string>(ent, "Name") == "Obstacle")
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { {
speed *= 4.0f; m_World->RemoveEntity(entity);
} }
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
speed /= 4.0f;
}
if(input->KeyState[GLFW_KEY_A]) {
transform->Position -= Camera_Right * (float)dt * speed;
}
else if(input->KeyState[GLFW_KEY_D]) {
transform->Position += Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_W]) {
transform->Position -= Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_S]) {
transform->Position += Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_SPACE]) {
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
}
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
transform->Orientation = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
} }
} }
if (name == "Camera") {
if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) {
if(freecamEnabled)
freecamEnabled = false;
else
freecamEnabled = true;
}
if(freecamEnabled)
{
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
float speed = m_PlayerSpeed;
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
speed *= 4.0f;
}
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
speed /= 4.0f;
}
if(input->KeyState[GLFW_KEY_A]) {
transform->Position -= Camera_Right * (float)dt * speed;
}
else if(input->KeyState[GLFW_KEY_D]) {
transform->Position += Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_W]) {
transform->Position -= Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_S]) {
transform->Position += Camera_Forward * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_SPACE]) {
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
}
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
//---------------------------------------------------------------------
transform->Orientation = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
}
}
if (name == "Player") if (name == "Player")
{ {
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds"); auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
@@ -79,7 +108,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0)); glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
float TurnSpeed = 1.0f; float TurnSpeed = 1.0f;
glm::vec3 Euler = glm::eulerAngles(transform->Orientation); glm::vec3 Euler = glm::degrees(glm::eulerAngles(transform->Orientation));
if(input->KeyState[GLFW_KEY_LEFT]) { if(input->KeyState[GLFW_KEY_LEFT]) {
transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z); transform->Position -= Ship_Right * (float)dt * (m_PlayerSpeed + Euler.z);
@@ -115,6 +144,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
} }
else else
{ {
transform->Position -= Ship_Right * (float)dt * Euler.z;
if(Euler.z < 1.5f && Euler.z > -1.5f) if(Euler.z < 1.5f && Euler.z > -1.5f)
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1)); transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
else if(Euler.z < 0.f) else if(Euler.z < 0.f)
@@ -130,23 +160,55 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
} }
if(input->KeyState[GLFW_KEY_F4] && !input->LastKeyState[GLFW_KEY_F4]) {
if(freecamEnabled)
freecamEnabled = false; //powerup
else auto cameraEntity = m_World->GetProperty<EntityID>(entity, "Camera");
freecamEnabled = true; auto cameracamera = m_World->GetComponent<Components::Camera>(cameraEntity, "Camera");
cameracamera->FOV = glm::radians(20.f + transform->Velocity.z/3 );
auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
for(auto ent : collisionComponent->CollidingEntities)
{
std::string name = m_World->GetProperty<std::string>(ent, "Name");
if(name == "PowerUp")
{
auto powerupComp = m_World->GetComponent<Components::PowerUp>(ent, "PowerUp");
m_maxspeed = powerupComp->Speed;
m_poweruptimeleft = 5.f;
m_World->RemoveEntity(ent);
}
}
if(m_poweruptimeleft <= 0)
{
m_maxspeed = m_basespeed;
}
if(transform->Velocity.z < m_maxspeed)
{
transform->Velocity.z += 100.f*dt;
if(transform->Velocity.z >= m_maxspeed)
transform->Velocity.z = m_maxspeed;
}
else if(transform->Velocity.z > m_maxspeed)
{
transform->Velocity.z -= 50.f*dt;
if(transform->Velocity.z <= m_maxspeed)
transform->Velocity.z = m_maxspeed;
} }
// Update camera // Update camera
if(! freecamEnabled) if(! freecamEnabled)
{ {
auto cameraEntity = m_World->GetProperty<EntityID>(entity, "Camera");
auto cameraTransform = m_World->GetComponent<Components::Transform>(cameraEntity, "Transform"); auto cameraTransform = m_World->GetComponent<Components::Transform>(cameraEntity, "Transform");
if (cameraTransform) { if (cameraTransform) {
cameraTransform->Position = transform->Position + m_CameraOffset; cameraTransform->Position = transform->Position + m_CameraOffset;
cameraTransform->Orientation = m_CameraOrientation; cameraTransform->Orientation = m_CameraOrientation;
} }
} }
} }
} }
+7
View File
@@ -9,6 +9,8 @@
#include "Components/Collision.h" #include "Components/Collision.h"
#include "Components/Camera.h" #include "Components/Camera.h"
#include "Components/Bounds.h" #include "Components/Bounds.h"
#include "Components/PowerUp.h"
#include "logging.h" #include "logging.h"
@@ -32,6 +34,11 @@ namespace Systems
glm::quat m_CameraOrientation; glm::quat m_CameraOrientation;
bool freecamEnabled; bool freecamEnabled;
float m_basespeed;
float m_maxspeed;
float m_poweruptimeleft;
}; };
} }
+13 -3
View File
@@ -25,7 +25,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
} }
auto model = m_CachedModels[modelComponent->ModelFile]; auto model = m_CachedModels[modelComponent->ModelFile];
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale); glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity);
m_Renderer->AddModelToDraw(model, position, orientation, transformComponent->Scale, modelComponent->Visible);
} }
// Debug draw bounds // Debug draw bounds
@@ -33,7 +35,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision"); auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds"); auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
if (bounds != nullptr) { if (bounds != nullptr) {
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin); glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector; glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0)); m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
} }
@@ -42,8 +44,9 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight"); auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
if (pointLightComponent != nullptr) if (pointLightComponent != nullptr)
{ {
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
m_Renderer->AddPointLightToDraw( m_Renderer->AddPointLightToDraw(
transformComponent->Position, position,
pointLightComponent->Specular, pointLightComponent->Specular,
pointLightComponent->Diffuse, pointLightComponent->Diffuse,
pointLightComponent->constantAttenuation, pointLightComponent->constantAttenuation,
@@ -51,6 +54,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
pointLightComponent->quadraticAttenuation, pointLightComponent->quadraticAttenuation,
pointLightComponent->spotExponent); pointLightComponent->spotExponent);
} }
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera"); auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
if (cameraComponent != nullptr) if (cameraComponent != nullptr)
{ {
@@ -63,6 +67,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
} }
} }
void Systems::RenderSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>("TransformSystem");
}
+4 -1
View File
@@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include "System.h" #include "System.h"
#include "Systems/TransformSystem.h"
#include "Model.h" #include "Model.h"
#include "Texture.h" #include "Texture.h"
#include "Components/Model.h" #include "Components/Model.h"
@@ -22,6 +23,8 @@ namespace Systems
RenderSystem(World* world, std::shared_ptr<Renderer> renderer) RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
: System(world), m_Renderer(renderer){ } : System(world), m_Renderer(renderer){ }
void Initialize() override;
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels; std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override; void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
@@ -29,7 +32,7 @@ namespace Systems
private: private:
std::shared_ptr<Renderer> m_Renderer; std::shared_ptr<Renderer> m_Renderer;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
}; };
-1
View File
@@ -7,7 +7,6 @@
#include <AL/al.h> #include <AL/al.h>
#include <AL/alc.h> #include <AL/alc.h>
#include <vector> #include <vector>
#include <glm/gtx/quaternion.hpp>
namespace Systems namespace Systems
{ {
@@ -0,0 +1,47 @@
#include "TransformSystem.h"
#include "World.h"
//void Systems::TransformSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
//{
// if (parent == 0)
// return;
//
// auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
// auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
//
// transform->Position = parentTransform->Position + transform->RelativePosition;
//}
glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
{
glm::vec3 absPosition;
glm::quat accumulativeOrientation;
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
//absPosition += transform->Position;
entity = m_World->GetEntityParent(entity);
auto transform2 = m_World->GetComponent<Components::Transform>(entity, "Transform");
if (entity != 0)
absPosition += transform2->Orientation * transform->Position;
else
absPosition += transform->Position;
} while (entity != 0);
return absPosition * accumulativeOrientation;
}
glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
{
glm::quat absOrientation;
do
{
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
absOrientation *= transform->Orientation;
entity = m_World->GetEntityParent(entity);
} while (entity != 0);
return absOrientation;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef TransformSystem_h__
#define TransformSystem_h__
#include "System.h"
#include "Components/Transform.h"
namespace Systems
{
class TransformSystem : public System
{
public:
TransformSystem(World* world)
: System(world) { }
//void Update(double dt) override;
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
glm::vec3 AbsolutePosition(EntityID entity);
glm::quat AbsoluteOrientation(EntityID entity);
};
}
#endif // TransformSystem_h__
+29 -24
View File
@@ -36,6 +36,8 @@ void World::Update(double dt)
system->Update(dt); system->Update(dt);
RecursiveUpdate(system, dt, 0); RecursiveUpdate(system, dt, 0);
} }
ProcessEntityRemovals();
} }
//std::vector<EntityID> GetEntityChildren(EntityID entity); //std::vector<EntityID> GetEntityChildren(EntityID entity);
@@ -60,21 +62,29 @@ bool World::ValidEntity(EntityID entity)
void World::RemoveEntity(EntityID entity) void World::RemoveEntity(EntityID entity)
{ {
m_EntityParents.erase(entity); m_EntitiesToRemove.push_back(entity);
// Remove components }
for (auto pair : m_EntityComponents[entity]) {
auto type = pair.first;
auto component = pair.second;
// Trigger events
for (auto pair : m_Systems) {
auto system = pair.second;
system->OnComponentRemoved(type, component.get());
}
m_ComponentsOfType[type].remove(component);
}
m_EntityComponents.erase(entity);
RecycleEntityID(entity); void World::ProcessEntityRemovals()
{
for (auto entity : m_EntitiesToRemove) {
m_EntityParents.erase(entity);
// Remove components
for (auto pair : m_EntityComponents[entity]) {
auto type = pair.first;
auto component = pair.second;
// Trigger events
for (auto pair : m_Systems) {
auto system = pair.second;
system->OnComponentRemoved(type, component.get());
}
m_ComponentsOfType[type].remove(component);
}
m_EntityComponents.erase(entity);
RecycleEntityID(entity);
}
m_EntitiesToRemove.clear();
} }
EntityID World::CreateEntity(EntityID parent /*= 0*/) EntityID World::CreateEntity(EntityID parent /*= 0*/)
@@ -97,19 +107,14 @@ World::World()
void World::Initialize() void World::Initialize()
{ {
RegisterSystems(); RegisterSystems();
AddSystems();
for (auto system : m_Systems) {
system.second->Initialize();
}
RegisterComponents(); RegisterComponents();
} }
void World::RegisterSystems()
{
}
void World::RegisterComponents()
{
}
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType) std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
{ {
return AddComponent<Component>(entity, componentType); return AddComponent<Component>(entity, componentType);
+8 -2
View File
@@ -25,8 +25,10 @@ public:
virtual void Initialize(); virtual void Initialize();
virtual void RegisterComponents(); virtual void RegisterSystems() = 0;
virtual void RegisterSystems(); virtual void AddSystems() = 0;
virtual void RegisterComponents() = 0;
void AddSystem(std::string systemType); void AddSystem(std::string systemType);
template <class T> template <class T>
@@ -85,9 +87,13 @@ protected:
std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType; std::unordered_map<std::string, std::list<std::shared_ptr<Component>>> m_ComponentsOfType;
std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents; std::unordered_map<EntityID, std::map<std::string, std::shared_ptr<Component>>> m_EntityComponents;
std::list<EntityID> m_EntitiesToRemove;
void ProcessEntityRemovals();
EntityID GenerateEntityID(); EntityID GenerateEntityID();
void RecycleEntityID(EntityID id); void RecycleEntityID(EntityID id);
}; };
template <class T> template <class T>