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

Conflicts:
	Escape-the-Dawn/GameWorld.cpp
	Escape-the-Dawn/Systems/PlayerSystem.cpp
This commit is contained in:
ViktorLjung
2014-03-13 02:05:47 +01:00
8 changed files with 64 additions and 168 deletions
+4
View File
@@ -9,9 +9,13 @@ namespace Components
struct Transform : Component
{
Transform()
: Scale(glm::vec3(1.f)) { }
glm::vec3 Position;
glm::quat Orientation;
glm::vec3 Velocity;
glm::vec3 Scale;
};
}
+3 -4
View File
@@ -85,12 +85,14 @@ void GameWorld::Initialize()
// Player
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->Scale = glm::vec3(2.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);
bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f);
ent = CreateEntity();
@@ -103,9 +105,6 @@ void GameWorld::Initialize()
void GameWorld::Update(double dt)
{
World::Update(dt);
auto transform = GetComponent<Components::Transform>(m_Player, "Transform");
transform->Orientation = transform->Orientation * glm::angleAxis<float>(dt, glm::vec3(0, 0, 1));
}
void GameWorld::RegisterComponents()
-146
View File
@@ -1,146 +0,0 @@
#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;
EntityID ent;
// Camera
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));
// 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 = "Models/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 = "Models/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 = "Models/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 = "Models/plane.obj";
// Player
<<<<<<< HEAD
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 = "Models/ship.obj";
=======
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);
>>>>>>> 21b2e3bdc15ac8b21f027a7f531574f46187ae80
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";
}
void GameWorld::Update(double dt)
{
World::Update(dt);
auto transform = GetComponent<Components::Transform>(m_Player, "Transform");
transform->Orientation = transform->Orientation * glm::angleAxis<float>(dt, glm::vec3(0, 0, 1));
}
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); });
}
+3 -4
View File
@@ -285,12 +285,11 @@ void Renderer::AddTextToDraw()
//Add to draw shit vector
}
void Renderer::AddModelToDraw(std::shared_ptr<Model> _model, glm::vec3 _position, glm::quat _orientation)
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
{
glm::mat4 RotationMatrix = glm::toMat4(_orientation);
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), _position) * RotationMatrix ;
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
// You can now use ModelMatrix to build the MVP matrix
ModelsToRender.push_back(new ModelData(_model, ModelMatrix));
ModelsToRender.push_back(new ModelData(model, ModelMatrix));
}
void Renderer::AddPointLightToDraw(
+1 -1
View File
@@ -54,7 +54,7 @@ public:
void Draw(double dt);
void DrawText();
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation);
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
void AddTextToDraw();
void AddPointLightToDraw(
glm::vec3 _position,
+49 -9
View File
@@ -1,11 +1,12 @@
#include "PlayerSystem.h"
#include "World.h"
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
{
}
void Systems::PlayerSystem::Update(double dt)
{
}
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -17,23 +18,25 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
if (input == nullptr)
return;
float speed = 10.0f;
auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera") {
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
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 = 15.0f;
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
speed *= 2.0f;
speed *= 4.0f;
}
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
speed /= 2.0f;
speed /= 4.0f;
}
if(input->KeyState[GLFW_KEY_A]) {
if(input->KeyState[GLFW_KEY_A] || input->KeyState[GLFW_KEY_LEFT]) {
transform->Position -= Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_D]) {
if(input->KeyState[GLFW_KEY_D] || input->KeyState[GLFW_KEY_RIGHT]) {
transform->Position += Camera_Right * (float)dt * speed;
}
if(input->KeyState[GLFW_KEY_W]) {
@@ -48,7 +51,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
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;
@@ -57,6 +60,43 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
}
name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "PlayerShip")
{
glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0));
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
float TurnSpeed = 2.0f;
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
LOG_DEBUG("Euler: %f", Euler.z);
if(input->KeyState[GLFW_KEY_LEFT]) {
transform->Position -= Ship_Right * (float)dt * speed;
if(Euler.z < 25.f)
{
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,1));
}
}
else if(input->KeyState[GLFW_KEY_RIGHT]) {
transform->Position += Ship_Right * (float)dt * speed;
if(Euler.z > -25.f)
{
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt * TurnSpeed,glm::vec3(0,0,-1));
}
}
else
{
if(Euler.z < 0.5f && Euler.z > -0.5f)
transform->Orientation = glm::angleAxis<float>(0,glm::vec3(0,0,1));
else if(Euler.z < 0.f)
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,1));
else if(Euler.z > 0.f)
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,-1));
}
}
}
+1 -2
View File
@@ -14,8 +14,7 @@ namespace Systems
class PlayerSystem : public System
{
public:
PlayerSystem(World* world)
: System(world) { }
PlayerSystem(World* world);
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+3 -2
View File
@@ -25,7 +25,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
}
auto model = m_CachedModels[modelComponent->ModelFile];
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale);
}
// Debug draw bounds
@@ -33,7 +33,8 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
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);
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
m_Renderer->AddAABBToDraw(origin, volumeVector);
}
#endif