WIP Camera Control

This commit is contained in:
Tobias Dahl
2014-03-10 01:51:00 +01:00
parent da62ed5ac6
commit cb16ecb5d6
5 changed files with 93 additions and 6 deletions
+52
View File
@@ -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));
}
}
+30
View File
@@ -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__
-1
View File
@@ -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)