Ship is movable
This commit is contained in:
@@ -85,10 +85,12 @@ void GameWorld::Initialize()
|
|||||||
|
|
||||||
// Player
|
// Player
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
|
SetProperty(ent, "Name", std::string("PlayerShip"));
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
transform->Position = glm::vec3(0.f, 0.f, 0.f);
|
||||||
model = AddComponent<Components::Model>(ent, "Model");
|
model = AddComponent<Components::Model>(ent, "Model");
|
||||||
model->ModelFile = "ship.obj";
|
model->ModelFile = "ship.obj";
|
||||||
|
AddComponent<Components::Input>(ent, "Input");
|
||||||
|
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(ent, "Transform");
|
transform = AddComponent<Components::Transform>(ent, "Transform");
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
#include "PlayerSystem.h"
|
#include "PlayerSystem.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
||||||
|
Systems::PlayerSystem::PlayerSystem( World* world ) : System(world)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Systems::PlayerSystem::Update(double dt)
|
void Systems::PlayerSystem::Update(double dt)
|
||||||
@@ -17,23 +21,25 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
if (input == nullptr)
|
if (input == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
float speed = 10.0f;
|
||||||
|
|
||||||
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
auto name = m_World->GetProperty<std::string>(entity, "Name");
|
||||||
if (name == "Camera") {
|
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_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);
|
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
||||||
|
|
||||||
float speed = 8.0f;
|
|
||||||
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
||||||
speed *= 2.0f;
|
speed *= 4.0f;
|
||||||
}
|
}
|
||||||
if(input->KeyState[GLFW_KEY_LEFT_ALT]) {
|
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;
|
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;
|
transform->Position += Camera_Right * (float)dt * speed;
|
||||||
}
|
}
|
||||||
if(input->KeyState[GLFW_KEY_W]) {
|
if(input->KeyState[GLFW_KEY_W]) {
|
||||||
@@ -48,7 +54,7 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
|
if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
|
||||||
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
|
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
|
// 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 = glm::angleAxis<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
|
||||||
@@ -57,6 +63,45 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ namespace Systems
|
|||||||
class PlayerSystem : public System
|
class PlayerSystem : public System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayerSystem(World* world)
|
PlayerSystem(World* world);
|
||||||
: System(world) { }
|
|
||||||
|
|
||||||
void Update(double dt) override;
|
void Update(double dt) override;
|
||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user