I Can't Believe It's Not Shadows!®

This commit is contained in:
2014-03-13 16:29:34 +01:00
parent a711ea7db8
commit 4905c17ebf
11 changed files with 81 additions and 41 deletions
+17 -7
View File
@@ -3,7 +3,8 @@
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
{
speed = 20;
m_PlayerSpeed = 20;
m_PlayerOriginalBounds = glm::vec3(0);
}
void Systems::PlayerSystem::Update(double dt)
@@ -21,10 +22,10 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
auto name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "Camera") {
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;
}
@@ -64,12 +65,15 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
// DO STUFF
}
}
name = m_World->GetProperty<std::string>(entity, "Name");
if (name == "PlayerShip")
{
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
if (bounds && m_PlayerOriginalBounds == glm::vec3(0)) {
m_PlayerOriginalBounds = bounds->VolumeVector;
}
glm::vec3 Ship_Right = glm::vec3(glm::vec4(1, 0, 0, 0));
glm::vec3 Ship_Forward = glm::vec3(glm::vec4(0, 0, 1, 0));
@@ -77,7 +81,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
glm::vec3 Euler = glm::eulerAngles(transform->Orientation);
if(input->KeyState[GLFW_KEY_LEFT]) {
transform->Position -= Ship_Right * (float)dt * speed;
transform->Position -= Ship_Right * (float)dt * m_PlayerSpeed;
if(Euler.z < 10.f)
{
@@ -93,7 +97,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
}
}
else if(input->KeyState[GLFW_KEY_RIGHT]) {
transform->Position += Ship_Right * (float)dt * speed;
transform->Position += Ship_Right * (float)dt * m_PlayerSpeed;
if(Euler.z > -10.f)
{
@@ -117,6 +121,12 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
else if(Euler.z > 0.f)
transform->Orientation = transform->Orientation * glm::angleAxis<float>((float)dt,glm::vec3(0,0,-1));
}
// Update player bounds based on rotation
if (bounds) {
Euler = glm::eulerAngles(transform->Orientation);
bounds->VolumeVector.x = m_PlayerOriginalBounds.x * glm::cos(glm::radians(Euler.z));
}
}
}