Skip to content

Commit

Permalink
add left/right center rotation with Q/E. #40
Browse files Browse the repository at this point in the history
  • Loading branch information
lanice committed Dec 21, 2013
1 parent e419a01 commit d08fc23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <GLFW/glfw3.h>

#include <glm/gtc/matrix_transform.hpp>
// #include <glm/gtc/quaternion.hpp>


static const double c_distanceEyeCenterDefault = 5.;
Expand Down Expand Up @@ -37,6 +38,9 @@ void Navigation::update()
{
if (glfwGetWindowAttrib(&m_window, GLFW_FOCUSED))
{
if (glfwGetKey(&m_window, GLFW_KEY_SPACE) == GLFW_PRESS)
setTransformation(glm::vec3(0, 2, 2), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));

if (glfwGetKey(&m_window, GLFW_KEY_W) == GLFW_PRESS)
move(glm::vec3(0, 0, -1));
if (glfwGetKey(&m_window, GLFW_KEY_A) == GLFW_PRESS)
Expand All @@ -45,24 +49,33 @@ void Navigation::update()
move(glm::vec3(0, 0, 1));
if (glfwGetKey(&m_window, GLFW_KEY_D) == GLFW_PRESS)
move(glm::vec3(1, 0, 0));

if (glfwGetKey(&m_window, GLFW_KEY_Q) == GLFW_PRESS)
rotate(-1.);
if (glfwGetKey(&m_window, GLFW_KEY_E) == GLFW_PRESS)
rotate(1.);
}
}

void Navigation::apply()
{
glm::vec3 eye = m_center + m_rotation * glm::vec3(0, m_distanceEyeCenter, 0);
glm::vec3 up = /*m_rotation * */glm::vec3(0, 1, 0);

m_camera->setEye(eye);
m_camera->setCenter(m_center);
m_camera->setUp(up);
m_camera->setUp(glm::vec3(0, 1, 0));
}

void Navigation::move(const glm::vec3 & direction)
{
m_center += glm::vec3(direction.x, 0, direction.z);
}

void Navigation::rotate(const float & angle)
{
m_rotation = glm::angleAxis(angle, glm::vec3(0, 1, 0)) * m_rotation;
}

const glowutils::Camera * Navigation::camera() const
{
return m_camera;
Expand Down
2 changes: 2 additions & 0 deletions src/navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Navigation

void update();
void apply();

void move(const glm::vec3 & direction);
void rotate(const float & degree);

const glowutils::Camera * camera() const;

Expand Down

0 comments on commit d08fc23

Please sign in to comment.