Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add camera rotation hotkey #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions Library/src/core/GraphicalSimulationApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,12 @@ void GraphicalSimulationApp::WindowEvent(SDL_Event* event)
void GraphicalSimulationApp::KeyDown(SDL_Event *event)
{
GLfloat moveStep = 0.1f;
GLfloat rotateStep = 1.f;
if(event->key.keysym.mod & KMOD_SHIFT)
{
moveStep = 1.f;
rotateStep = 10.f;
}

switch (event->key.keysym.sym)
{
Expand Down Expand Up @@ -414,22 +418,45 @@ void GraphicalSimulationApp::KeyDown(SDL_Event *event)
}
break;

case SDLK_q: //Up
case SDLK_r: //Up
{
OpenGLTrackball* trackball = getSimulationManager()->getTrackball();
if(trackball->isEnabled())
trackball->MoveCenter(glm::vec3(0.f, 0.f, -moveStep));
}
break;

case SDLK_z: //Down
case SDLK_f: //Down
{
OpenGLTrackball* trackball = getSimulationManager()->getTrackball();
if(trackball->isEnabled())
trackball->MoveCenter(glm::vec3(0.f, 0.f, moveStep));
}
break;

case SDLK_q: //Rotate left
{
OpenGLTrackball* trackball = getSimulationManager()->getTrackball();
if(trackball->isEnabled())
{
glm::quat rotation = glm::angleAxis(glm::radians(-rotateStep), glm::vec3(0.0f, 0.0f, 1.0f));
trackball->Rotate(rotation);
}
}
break;

case SDLK_e: // Rotate right.
{
OpenGLTrackball* trackball = getSimulationManager()->getTrackball();

if(trackball->isEnabled())
{
glm::quat rotation = glm::angleAxis(glm::radians(rotateStep),glm::vec3(0.0f, 0.0f, 1.0f));
trackball->Rotate(rotation);
}
}
break;

default:
break;
}
Expand Down Expand Up @@ -971,17 +998,19 @@ void GraphicalSimulationApp::DoHUD()
//Keymap
if(displayKeymap)
{
offset = getWindowHeight()-246.f;
offset = getWindowHeight()-278.f;
GLfloat left = getWindowWidth()-130.f;
gui->DoPanel(left - 10.f, offset, 130.f, 206.f); offset += 10.f;
gui->DoPanel(left - 10.f, offset, 130.f, 238.f); offset += 10.f;
gui->DoLabel(left, offset, "[H] show/hide GUI"); offset += 16.f;
gui->DoLabel(left, offset, "[C] show/hide console"); offset += 16.f;
gui->DoLabel(left, offset, "[W] move forward"); offset += 16.f;
gui->DoLabel(left, offset, "[S] move backward"); offset += 16.f;
gui->DoLabel(left, offset, "[A] move left"); offset += 16.f;
gui->DoLabel(left, offset, "[D] move right"); offset += 16.f;
gui->DoLabel(left, offset, "[Q] move up"); offset += 16.f;
gui->DoLabel(left, offset, "[Z] move down"); offset += 16.f;
gui->DoLabel(left, offset, "[R] move up"); offset += 16.f;
gui->DoLabel(left, offset, "[F] move down"); offset += 16.f;
gui->DoLabel(left, offset, "[Q] Rotate left"); offset += 16.f;
gui->DoLabel(left, offset, "[E] Rotate right"); offset += 16.f;
gui->DoLabel(left, offset, "[Shift] move fast"); offset += 16.f;
gui->DoLabel(left, offset, "[Mouse right] rotate"); offset += 16.f;
gui->DoLabel(left, offset, "[Mouse middle] move"); offset += 16.f;
Expand Down
3 changes: 2 additions & 1 deletion Library/src/graphics/OpenGLTrackball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ glm::mat4 OpenGLTrackball::GetViewMatrix() const

void OpenGLTrackball::Rotate(glm::quat rot)
{
rotation = glm::rotation(up, glm::vec3(0,0,1.f)) * rot;
rotation = rotation * rot;
UpdateTransform();
}

void OpenGLTrackball::MoveCenter(glm::vec3 step)
Expand Down