Click-to-camera!

This commit is contained in:
2014-03-11 16:11:12 +01:00
parent f027773af8
commit 43ab2473ec
3 changed files with 52 additions and 36 deletions
+1 -1
View File
@@ -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();
+16 -3
View File
@@ -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
+35 -32
View File
@@ -19,41 +19,44 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
auto name = m_World->GetProperty<std::string>(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<float>(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<float>(input->dY/300.f,glm::vec3(1,0,0)) * transform->Orientation;
transform->Orientation = transform->Orientation * glm::angleAxis<float>(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<float>(input->dX/300.f,glm::vec3(0,1,0));
//---------------------------------------------------------------------
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
}
}
}