2005-07-03 18:25:48 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "InputProcessor.h"
|
|
|
|
|
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "graphics/Camera.h"
|
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
static float g_ViewZoomSmoothness = 0.02f; // TODO: configurable, like GameView
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
bool InputProcessor::ProcessInput(GameLoopState* state)
|
|
|
|
{
|
|
|
|
if (! g_Game)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CCamera* camera = g_Game->GetView()->GetCamera();
|
|
|
|
|
|
|
|
CVector3D leftwards = camera->m_Orientation.GetLeft();
|
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
CVector3D inwards = camera->m_Orientation.GetIn();
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
// Calculate a vector pointing forwards, parallel to the ground
|
2005-09-15 07:31:49 +02:00
|
|
|
CVector3D forwards = inwards;
|
2005-07-03 18:25:48 +02:00
|
|
|
forwards.Y = 0.0f;
|
|
|
|
if (forwards.GetLength() < 0.001f) // be careful if the camera is looking straight down
|
|
|
|
forwards = CVector3D(1.f, 0.f, 0.f);
|
|
|
|
else
|
|
|
|
forwards.Normalize();
|
|
|
|
|
|
|
|
bool moved = false;
|
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
GameLoopState::Input& input = state->input;
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
if (state->input.scrollSpeed[0] != 0.0f)
|
|
|
|
{
|
2005-09-15 07:31:49 +02:00
|
|
|
camera->m_Orientation.Translate(forwards * (input.scrollSpeed[0] * state->frameLength));
|
2005-07-03 18:25:48 +02:00
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->input.scrollSpeed[1] != 0.0f)
|
|
|
|
{
|
2005-09-15 07:31:49 +02:00
|
|
|
camera->m_Orientation.Translate(forwards * (-input.scrollSpeed[1] * state->frameLength));
|
2005-07-03 18:25:48 +02:00
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->input.scrollSpeed[2] != 0.0f)
|
|
|
|
{
|
2005-09-15 07:31:49 +02:00
|
|
|
camera->m_Orientation.Translate(leftwards * (input.scrollSpeed[2] * state->frameLength));
|
2005-07-03 18:25:48 +02:00
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->input.scrollSpeed[3] != 0.0f)
|
|
|
|
{
|
2005-09-15 07:31:49 +02:00
|
|
|
camera->m_Orientation.Translate(leftwards * (-input.scrollSpeed[3] * state->frameLength));
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->input.zoomDelta != 0.0f)
|
|
|
|
{
|
|
|
|
float zoom_proportion = powf(g_ViewZoomSmoothness, state->frameLength);
|
|
|
|
camera->m_Orientation.Translate(inwards * (input.zoomDelta * (1.0f - zoom_proportion)));
|
|
|
|
input.zoomDelta *= zoom_proportion;
|
|
|
|
|
|
|
|
if (fabsf(input.zoomDelta) < 0.1f)
|
|
|
|
input.zoomDelta = 0.0f;
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
|
2005-11-06 06:05:07 +01:00
|
|
|
if (moved)
|
|
|
|
camera->UpdateFrustum();
|
|
|
|
|
2005-07-03 18:25:48 +02:00
|
|
|
return moved;
|
|
|
|
}
|