WIP Camera Control
This commit is contained in:
@@ -56,7 +56,7 @@ void GameWorld::Initialize()
|
||||
AddSystem("InputSystem");
|
||||
//AddSystem("CollisionSystem");
|
||||
//AddSystem("ParticleSystem");
|
||||
//AddSystem("PlayerSystem");
|
||||
AddSystem("PlayerSystem");
|
||||
//AddSystem("SoundSystem");
|
||||
AddSystem("RenderSystem");
|
||||
|
||||
@@ -72,14 +72,15 @@ void GameWorld::Initialize()
|
||||
model->ModelFile = "ship.obj";
|
||||
|
||||
ent = CreateEntity();
|
||||
SetProperty(ent, "Name", "Camera");
|
||||
SetProperty(ent, "Name", std::string("Camera"));
|
||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||
transform->Position = glm::vec3(0.f, 0.f, 10.f);
|
||||
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()
|
||||
@@ -88,7 +89,7 @@ void GameWorld::RegisterSystems()
|
||||
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("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); });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "PlayerSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
|
||||
|
||||
void Systems::PlayerSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (transform == nullptr)
|
||||
return;
|
||||
auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
if (input == nullptr)
|
||||
return;
|
||||
|
||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "Camera") {
|
||||
|
||||
glm::vec3 Camera_Right = glm::rotate(transform->Orientation, glm::vec3(1, 0, 0));
|
||||
glm::vec3 Camera_Forward = glm::rotate(transform->Orientation, glm::vec3(0, 0, 1));
|
||||
|
||||
|
||||
float speed = 4.0f;
|
||||
if(input->KeyState[GLFW_KEY_LEFT_SHIFT] == GLFW_PRESS)
|
||||
{
|
||||
speed = 1.0f;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_A] == GLFW_PRESS)
|
||||
{
|
||||
transform->Position -= Camera_Right * (float)dt*2.f * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_D] == GLFW_PRESS)
|
||||
{
|
||||
transform->Position += Camera_Right * (float)dt*2.f * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_W] == GLFW_PRESS)
|
||||
{
|
||||
transform->Position -= Camera_Forward * (float)dt*2.f * speed;
|
||||
}
|
||||
if(input->KeyState[GLFW_KEY_S] == GLFW_PRESS)
|
||||
{
|
||||
transform->Position += Camera_Forward * (float)dt*2.f * speed;
|
||||
}
|
||||
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>(-(input->dX/300.f),glm::vec3(0,1,0));
|
||||
transform->Orientation = transform->Orientation * glm::angleAxis<float>(-(input->dY/300.f),glm::vec3(1,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef PlayerSystem_h__
|
||||
#define PlayerSystem_h__
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "System.h"
|
||||
#include "Renderer.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Input.h"
|
||||
#include "logging.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class PlayerSystem : public System
|
||||
{
|
||||
public:
|
||||
PlayerSystem(World* world)
|
||||
: System(world) { }
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // InputSystem_h__
|
||||
|
||||
@@ -28,7 +28,6 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
if(soundEmitter == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName)
|
||||
|
||||
@@ -42,6 +42,11 @@ public:
|
||||
template <class T>
|
||||
T GetProperty(EntityID entity, std::string property)
|
||||
{
|
||||
if(m_EntityProperties.find(entity) == m_EntityProperties.end())
|
||||
return T();
|
||||
if(m_EntityProperties[entity].find(property) == m_EntityProperties[entity].end())
|
||||
return T();
|
||||
|
||||
return boost::any_cast<T>(m_EntityProperties[entity][property]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user