diff --git a/Escape-the-Dawn/Shaders/Normals.geo.glsl b/Escape-the-Dawn/Shaders/Normals.geo.glsl index c848a50..0f72a8e 100644 --- a/Escape-the-Dawn/Shaders/Normals.geo.glsl +++ b/Escape-the-Dawn/Shaders/Normals.geo.glsl @@ -23,7 +23,7 @@ void main() { gl_Position = MVP * vec4(Input[i].Position, 1.0); EmitVertex(); - gl_Position = MVP * vec4(Input[i].Position, 1.0) + MVP * vec4(Input[i].Normal, 0.0); + gl_Position = MVP * vec4(Input[i].Position + Input[i].Normal, 1.0); EmitVertex(); EndPrimitive(); diff --git a/Escape-the-Dawn/Systems/InputSystem.cpp b/Escape-the-Dawn/Systems/InputSystem.cpp index 81f8f15..ef7f17d 100644 --- a/Escape-the-Dawn/Systems/InputSystem.cpp +++ b/Escape-the-Dawn/Systems/InputSystem.cpp @@ -21,9 +21,22 @@ void Systems::InputSystem::Update(double dt) glfwGetCursorPos(m_Renderer->GetWindow(), &xpos, &ypos); m_CurrentMouseDeltaX = xpos - m_LastMouseX; m_CurrentMouseDeltaY = ypos - m_LastMouseY; - m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; - m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; - glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); + m_LastMouseX = xpos; + m_LastMouseY = ypos; + + // Lock mouse while holding LMB + if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; + m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; + glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); + } + // Hide/show cursor with LMB + if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); + } + if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) { + glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); + } #ifdef DEBUG // Wireframe diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 1e93148..aeb7ca2 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -19,41 +19,44 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa auto name = m_World->GetProperty(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); - 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 = 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; - } + float speed = 8.0f; + if(input->KeyState[GLFW_KEY_LEFT_SHIFT]) { + speed *= 2.0f; + } + if(input->KeyState[GLFW_KEY_LEFT_ALT]) { + speed /= 2.0f; + } + if(input->KeyState[GLFW_KEY_A]) { + transform->Position -= Camera_Right * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_D]) { + transform->Position += Camera_Right * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_W]) { + transform->Position -= Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_S]) { + transform->Position += Camera_Forward * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_SPACE]) { + transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed; + } + if(input->KeyState[GLFW_KEY_LEFT_CONTROL]) { + transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed; + } - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - //--------------------------------------------------------------------- - transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + //--------------------------------------------------------------------- + transform->Orientation = glm::angleAxis(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation; - transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); - //--------------------------------------------------------------------- - // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS - + transform->Orientation = transform->Orientation * glm::angleAxis(input->dX/300.f,glm::vec3(0,1,0)); + //--------------------------------------------------------------------- + // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS + } } }