Unified all camera inputs

Until now each camera type had separate code for handling camera input, and some new features were missing in some of them.

The camera controls are as follows:
* RMB+mouse and numpad keys - horizontal/vertical rotation
* mouse wheel and +/- keys - zoom (in free camera - move eye up/down)
* CTRL or MMB + horizontal controls - pan left/right
* CTRL or MMB + zoom controls - move lookat up/down (free camera only)
master
krzys-h 2016-05-27 22:38:44 +02:00
parent 261b26c8e9
commit bd72086704
11 changed files with 109 additions and 262 deletions

View File

@ -506,12 +506,6 @@ msgstr ""
msgid "Speed 6.0x\\Sextuple speed"
msgstr ""
msgid "Camera up\\Increase camera angle while visiting message origin"
msgstr ""
msgid "Camera down\\Decrease camera angle while visiting message origin"
msgstr ""
msgid "Pause\\Pause the game without opening menu"
msgstr ""

View File

@ -330,9 +330,6 @@ msgstr "Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erre
msgid "Camera closer\\Moves the camera forward"
msgstr "Kamera näher\\Bewegung der Kamera vorwärts"
msgid "Camera down\\Decrease camera angle while visiting message origin"
msgstr ""
msgid "Camera nearest"
msgstr "Kamera näher"
@ -342,9 +339,6 @@ msgstr "Kamera links"
msgid "Camera to right"
msgstr "Kamera rechts"
msgid "Camera up\\Increase camera angle while visiting message origin"
msgstr ""
msgid "Can not produce not researched object"
msgstr "Das erforschte Objekt kann nicht produziert werden"

View File

@ -321,9 +321,6 @@ msgstr "Défilement dans les bords\\Défilement lorsque la souris touche les bor
msgid "Camera closer\\Moves the camera forward"
msgstr "Caméra plus proche\\Avance la caméra"
msgid "Camera down\\Decrease camera angle while visiting message origin"
msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages"
msgid "Camera nearest"
msgstr "Caméra plus proche"
@ -333,9 +330,6 @@ msgstr "Caméra à gauche"
msgid "Camera to right"
msgstr "Caméra à droite"
msgid "Camera up\\Increase camera angle while visiting message origin"
msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages"
msgid "Can not produce not researched object"
msgstr "Impossible de créer un objet n'ayant pas été recherché"
@ -1815,6 +1809,12 @@ msgstr ""
#~ msgid "COLOBOT"
#~ msgstr "COLOBOT"
#~ msgid "Camera down\\Decrease camera angle while visiting message origin"
#~ msgstr "Caméra plus basse\\Réduit l'angle de caméra lors de la vue de l'origine des messages"
#~ msgid "Camera up\\Increase camera angle while visiting message origin"
#~ msgstr "Caméra plus haute\\Augmente l'angle de caméra lors de la vue de l'origine des messages"
#~ msgid "Can not create this; there are too many objects"
#~ msgstr "Création impossible; il y a trop d'objets"

View File

@ -324,9 +324,6 @@ msgstr "Przewijanie kamery przy krawędzi\\Ekran jest przewijany gdy mysz dotkni
msgid "Camera closer\\Moves the camera forward"
msgstr "Kamera bliżej\\Przybliża kamerę"
msgid "Camera down\\Decrease camera angle while visiting message origin"
msgstr "Kamera w dół\\Opuść kamerę podczas sprawdzania źródła wiadomości"
msgid "Camera nearest"
msgstr "Camera nearest"
@ -336,9 +333,6 @@ msgstr "Camera to left"
msgid "Camera to right"
msgstr "Camera to right"
msgid "Camera up\\Increase camera angle while visiting message origin"
msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości"
msgid "Can not produce not researched object"
msgstr "Nie można wyprodukować nie wynalezionego obiektu"
@ -1811,6 +1805,12 @@ msgstr ""
#~ msgid "Building too close"
#~ msgstr "Budynek za blisko"
#~ msgid "Camera down\\Decrease camera angle while visiting message origin"
#~ msgstr "Kamera w dół\\Opuść kamerę podczas sprawdzania źródła wiadomości"
#~ msgid "Camera up\\Increase camera angle while visiting message origin"
#~ msgstr "Kamera w górę\\Podnieś kamerę podczas sprawdzania źródła wiadomości"
#~ msgid "Can not create this; there are too many objects"
#~ msgstr "Nie można tego utworzyć, za dużo obiektów"

View File

@ -328,9 +328,6 @@ msgstr "Прокрутка\\Прокрутка, когда указатель м
msgid "Camera closer\\Moves the camera forward"
msgstr "Приблизать камеру\\Перемещение камеры вперед"
msgid "Camera down\\Decrease camera angle while visiting message origin"
msgstr ""
msgid "Camera nearest"
msgstr "Приблизить камеру"
@ -340,9 +337,6 @@ msgstr "Камеру влево"
msgid "Camera to right"
msgstr "Камеру вправо"
msgid "Camera up\\Increase camera angle while visiting message origin"
msgstr ""
msgid "Can not produce not researched object"
msgstr ""

View File

@ -30,6 +30,7 @@
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <SDL_system.h>
template<> CInput* CSingleton<CInput>::m_instance = nullptr;
@ -63,13 +64,10 @@ CInput::CInput()
{ INPUT_SLOT_SPEED30, "speed30" },
{ INPUT_SLOT_SPEED40, "speed40" },
{ INPUT_SLOT_SPEED60, "speed60" },
{ INPUT_SLOT_CAMERA_UP, "camup" },
{ INPUT_SLOT_CAMERA_DOWN, "camdown" },
{ INPUT_SLOT_PAUSE, "pause" },
{ INPUT_SLOT_CMDLINE, "cmdline" },
};
m_kmodState = 0;
m_mousePos = Math::Point();
m_mouseButtonsState = 0;
std::fill_n(m_keyPresses, static_cast<std::size_t>(INPUT_SLOT_MAX), false);
@ -80,13 +78,6 @@ CInput::CInput()
void CInput::EventProcess(Event& event)
{
if (event.type == EVENT_KEY_DOWN ||
event.type == EVENT_KEY_UP)
{
// Use the occasion to update kmods
m_kmodState = event.kmodState;
}
// Use the occasion to update mouse button state
if (event.type == EVENT_MOUSE_BUTTON_DOWN)
{
@ -107,7 +98,7 @@ void CInput::EventProcess(Event& event)
data->slot = FindBinding(data->key);
}
event.kmodState = m_kmodState;
event.kmodState = SDL_GetModState();
event.mousePos = m_mousePos;
event.mouseButtonsState = m_mouseButtonsState;
@ -134,8 +125,6 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f;
if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f;
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 1.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = -1.0f;
if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = -1.0f;
if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 1.0f;
if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 1.0f;
@ -152,8 +141,6 @@ void CInput::EventProcess(Event& event)
if (data->slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_CAMERA_UP ) m_cameraKeyMotion.z = 0.0f;
if (data->slot == INPUT_SLOT_CAMERA_DOWN) m_cameraKeyMotion.z = 0.0f;
if (data->key == KEY(KP_4) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP_6) ) m_cameraKeyMotion.x = 0.0f;
if (data->key == KEY(KP_8) ) m_cameraKeyMotion.y = 0.0f;
@ -194,16 +181,6 @@ void CInput::MouseMove(Math::IntPoint pos)
m_mousePos = Gfx::CEngine::GetInstancePointer()->WindowToInterfaceCoords(pos);
}
int CInput::GetKmods() const
{
return m_kmodState;
}
bool CInput::GetKmodState(int kmod) const
{
return (m_kmodState & kmod) != 0;
}
bool CInput::GetKeyState(InputSlot key) const
{
return m_keyPresses[key];
@ -217,7 +194,6 @@ bool CInput::GetMouseButtonState(int index) const
void CInput::ResetKeyStates()
{
GetLogger()->Trace("Reset key states\n");
m_kmodState = 0;
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
@ -272,8 +248,6 @@ void CInput::SetDefaultInputBindings()
m_inputBindings[INPUT_SLOT_SPEED30].primary = KEY(F7);
m_inputBindings[INPUT_SLOT_SPEED40].primary = KEY(F8);
m_inputBindings[INPUT_SLOT_SPEED60].primary = KEY(F9);
m_inputBindings[INPUT_SLOT_CAMERA_UP].primary = KEY(PAGEUP);
m_inputBindings[INPUT_SLOT_CAMERA_DOWN].primary = KEY(PAGEDOWN);
m_inputBindings[INPUT_SLOT_PAUSE].primary = KEY(PAUSE);
m_inputBindings[INPUT_SLOT_PAUSE].secondary = KEY(p);
m_inputBindings[INPUT_SLOT_CMDLINE].primary = KEY(BACKQUOTE);

View File

@ -81,12 +81,6 @@ public:
void MouseMove(Math::IntPoint pos);
//! Returns the current key modifiers
int GetKmods() const;
//! Returns whether the given kmod is active
bool GetKmodState(int kmod) const;
//! Returns whether the key is pressed
bool GetKeyState(InputSlot key) const;
@ -140,8 +134,6 @@ public:
//@}
private:
//! Current state of key modifiers (bitmask of SDLMod)
unsigned int m_kmodState;
//! Current state of keys
bool m_keyPresses[INPUT_SLOT_MAX];

View File

@ -102,8 +102,6 @@ enum InputSlot
INPUT_SLOT_SPEED30,
INPUT_SLOT_SPEED40,
INPUT_SLOT_SPEED60,
INPUT_SLOT_CAMERA_UP,
INPUT_SLOT_CAMERA_DOWN,
INPUT_SLOT_PAUSE,
INPUT_SLOT_CMDLINE,

View File

@ -235,8 +235,6 @@ void InitializeRestext()
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED30] = TR("Speed 3.0x\\Triple speed");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED40] = TR("Speed 4.0x\\Quadruple speed");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_SPEED60] = TR("Speed 6.0x\\Sextuple speed");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAMERA_UP] = TR("Camera up\\Increase camera angle while visiting message origin");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CAMERA_DOWN] = TR("Camera down\\Decrease camera angle while visiting message origin");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_PAUSE] = TR("Pause\\Pause the game without opening menu");
stringsEvent[EVENT_INTERFACE_KEY+INPUT_SLOT_CMDLINE] = TR("Cheat console\\Show cheat console");

View File

@ -102,7 +102,7 @@ CCamera::CCamera()
m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f);
m_directionH = 0.0f;
m_directionV = 0.0f;
m_heightEye = 20.0f;
m_heightEye = 40.0f;
m_heightLookat = 0.0f;
m_speed = 2.0f;
@ -122,8 +122,6 @@ CCamera::CCamera()
m_visitType = CAM_TYPE_NULL;
m_visitDirectionV = 0.0f;
m_editHeight = 40.0f;
m_remotePan = 0.0f;
m_centeringPhase = CAM_PHASE_NULL;
@ -1145,34 +1143,7 @@ bool CCamera::EventMouseMove(const Event &event)
void CCamera::EventMouseWheel(const Event &event)
{
auto dir = event.GetData<MouseWheelEventData>()->y;
if (m_type == CAM_TYPE_BACK)
{
m_backDist -= 8.0f*dir;
if (m_backDist < m_backMin)
m_backDist = m_backMin;
if (m_backDist > 200.0f)
m_backDist = 200.0f;
}
if ( m_type == CAM_TYPE_FIX ||
m_type == CAM_TYPE_PLANE )
{
m_fixDist -= 8.0f*dir;
if (m_fixDist < 10.0f)
m_fixDist = 10.0f;
if (m_fixDist > 200.0f)
m_fixDist = 200.0f;
}
if ( m_type == CAM_TYPE_VISIT )
{
m_visitDist -= 8.0f*dir;
if (m_visitDist < 20.0f)
m_visitDist = 20.0f;
if (m_visitDist > 200.0f)
m_visitDist = 200.0f;
}
m_mouseWheelDelta -= dir;
}
void CCamera::EventMouseButton(const Event &event)
@ -1202,11 +1173,9 @@ bool CCamera::EventFrame(const Event &event)
EffectFrame(event);
OverFrame(event);
if (m_type == CAM_TYPE_FREE)
return EventFrameFree(event);
if (m_type == CAM_TYPE_EDIT)
return EventFrameEdit(event);
if (m_type == CAM_TYPE_FREE ||
m_type == CAM_TYPE_EDIT)
return EventFrameFree(event, m_type != CAM_TYPE_EDIT);
if (m_type == CAM_TYPE_DIALOG)
return EventFrameDialog(event);
@ -1236,57 +1205,36 @@ bool CCamera::EventFrame(const Event &event)
return true;
}
bool CCamera::EventFrameFree(const Event &event)
bool CCamera::EventFrameFree(const Event &event, bool keysAllowed)
{
Math::Vector cameraInput = event.cameraInput;
if (m_cameraObj == nullptr)
{
cameraInput = Math::Clamp(cameraInput + event.motionInput, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f));
}
Math::Vector cameraMove = CalculateCameraMovement(event, keysAllowed);
float factor = m_heightEye * 0.5f + 30.0f;
bool secondary = event.kmodState & KEY_MOD(CTRL) || event.mouseButtonsState & MOUSE_BUTTON_MIDDLE;
m_directionH -= m_mouseDelta.x * 2*Math::PI;
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed);
m_mouseDelta.LoadZero();
// Forward/Backward
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -cameraMove.y * factor * 2);
// Up/Down
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, cameraInput.y * event.rTime * factor * m_speed);
// Left/Right
if ( event.kmodState & KEY_MOD(CTRL) )
// Left/Right (pan or rotate)
if (secondary)
{
if ( cameraInput.x < 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -cameraInput.x * event.rTime * factor * m_speed);
if ( cameraInput.x > 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, cameraInput.x * event.rTime * factor * m_speed);
if (cameraMove.x < 0.0f)
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -cameraMove.x * factor);
if (cameraMove.x > 0.0f)
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, cameraMove.x * factor);
}
else
{
m_directionH -= cameraInput.x * event.rTime * 0.7f * m_speed;
m_directionH -= cameraMove.x;
}
// PageUp/PageDown
if ( m_input->GetKeyState(INPUT_SLOT_AWAY) )
{
if (m_heightEye < 500.0f)
m_heightEye += event.rTime * factor * m_speed;
}
if ( m_input->GetKeyState(INPUT_SLOT_NEAR) )
{
if (m_heightEye > -2.0f)
m_heightEye -= event.rTime * factor * m_speed;
}
// Up/Down (eye or lookat point)
if (secondary)
m_heightLookat -= cameraMove.z;
else
m_heightEye -= cameraMove.z;
if ( m_input->GetKeyState(INPUT_SLOT_CAMERA_UP) )
{
m_heightLookat += event.rTime * factor * m_speed;
}
if ( m_input->GetKeyState(INPUT_SLOT_CAMERA_DOWN) )
{
m_heightLookat -= event.rTime * factor * m_speed;
}
m_heightEye = Math::Clamp(m_heightEye, -2.0f, 500.0f);
m_terrain->AdjustToBounds(m_eyePt, 10.0f);
@ -1314,44 +1262,6 @@ bool CCamera::EventFrameFree(const Event &event)
return true;
}
bool CCamera::EventFrameEdit(const Event &event)
{
float factor = m_editHeight * 0.5f + 30.0f;
m_directionH -= m_mouseDelta.x * 0.7f * 2*Math::PI;
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed);
m_fixDirectionH += m_mouseDelta.x * 2*Math::PI;
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
m_mouseDelta.LoadZero();
m_terrain->AdjustToBounds(m_eyePt, 10.0f);
if (m_terrain->AdjustToFloor(m_eyePt, false))
{
m_eyePt.y += m_editHeight;
Math::Vector pos = m_eyePt;
if (m_terrain->AdjustToFloor(pos, false))
{
pos.y += 2.0f;
if (m_eyePt.y < pos.y)
m_eyePt.y = pos.y;
}
}
Math::Vector lookatPt = Math::LookatPoint( m_eyePt, m_directionH, m_directionV, 50.0f );
if ( m_terrain->AdjustToFloor(lookatPt, true))
lookatPt.y += m_heightLookat;
SetViewTime(m_eyePt, lookatPt, event.rTime);
return true;
}
bool CCamera::EventFrameDialog(const Event &event)
{
return true;
@ -1359,29 +1269,15 @@ bool CCamera::EventFrameDialog(const Event &event)
bool CCamera::EventFrameBack(const Event &event)
{
ObjectType type;
if (m_cameraObj == nullptr)
type = OBJECT_NULL;
else
type = m_cameraObj->GetType();
Math::Vector cameraMove = CalculateCameraMovement(event);
m_addDirectionH += cameraMove.x;
m_addDirectionV += cameraMove.y;
m_backDist += cameraMove.z;
// +/-.
if (m_input->GetKeyState(INPUT_SLOT_NEAR))
{
m_backDist -= event.rTime * 30.0f * m_speed;
if (m_backDist < m_backMin) m_backDist = m_backMin;
}
if (m_input->GetKeyState(INPUT_SLOT_AWAY))
{
m_backDist += event.rTime * 30.0f * m_speed;
if (m_backDist > 200.0f) m_backDist = 200.0f;
}
m_addDirectionH -= m_mouseDelta.x * 2*Math::PI;
m_addDirectionH = Math::NormAngle(m_addDirectionH);
if (m_mouseDelta.Length() > 0)
AbortCentering(); // special stops framing
m_mouseDelta.LoadZero();
m_addDirectionV = Math::NormAngle(m_addDirectionV);
m_backDist = Math::Clamp(m_backDist, m_backMin, 200.0f);
// Increase the special framework
float centeringH = 0.0f;
@ -1423,6 +1319,8 @@ bool CCamera::EventFrameBack(const Event &event)
if (m_cameraObj != nullptr)
{
ObjectType type = m_cameraObj->GetType();
Math::Vector lookatPt = m_cameraObj->GetPosition();
if (type == OBJECT_BASE ) lookatPt.y += 40.0f;
else if (type == OBJECT_HUMAN) lookatPt.y += 1.0f;
@ -1502,30 +1400,16 @@ bool CCamera::EventFrameBack(const Event &event)
bool CCamera::EventFrameFix(const Event &event)
{
// +/-.
if (m_input->GetKeyState(INPUT_SLOT_NEAR))
{
m_fixDist -= event.rTime * 30.0f * m_speed;
if (m_fixDist < 10.0f) m_fixDist = 10.0f;
}
if (m_input->GetKeyState(INPUT_SLOT_AWAY))
{
m_fixDist += event.rTime * 30.0f * m_speed;
if (m_fixDist > 200.0f) m_fixDist = 200.0f;
}
Math::Vector cameraMove = CalculateCameraMovement(event);
m_fixDirectionH += cameraMove.x;
m_fixDirectionV += cameraMove.y;
m_fixDist += cameraMove.z;
m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI;
if (m_mouseDelta.Length() > 0)
AbortCentering(); // special stops framing
m_mouseDelta.LoadZero();
// Left/Right
m_fixDirectionH += event.cameraInput.x * event.rTime * 0.7f * m_speed;
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
m_fixDirectionV = Math::NormAngle(m_fixDirectionV);
// Up/Down
m_fixDirectionV -= event.cameraInput.y * event.rTime * 0.7f * m_speed;
m_fixDirectionV = Math::Min(Math::Max(m_fixDirectionV, -0.5*Math::PI), 0.25*Math::PI);
m_fixDirectionV = Math::Clamp(m_fixDirectionV, -0.5f*Math::PI, 0.25f*Math::PI);
m_fixDist = Math::Clamp(m_fixDist, 10.0f, 200.0f);
if (m_cameraObj != nullptr)
{
@ -1551,8 +1435,9 @@ bool CCamera::EventFrameFix(const Event &event)
bool CCamera::EventFrameExplo(const Event &event)
{
m_directionH -= m_mouseDelta.x * 2*Math::PI;
m_mouseDelta.LoadZero();
Math::Vector cameraMove = CalculateCameraMovement(event);
m_directionH += cameraMove.x;
m_directionH = Math::NormAngle(m_directionH);
m_terrain->AdjustToBounds(m_eyePt, 10.0f);
@ -1609,34 +1494,15 @@ bool CCamera::EventFrameVisit(const Event &event)
{
m_visitTime += event.rTime;
// +/-.
if (m_input->GetKeyState(INPUT_SLOT_NEAR))
{
m_visitDist -= event.rTime * 50.0f * m_speed;
if (m_visitDist < 20.0f) m_visitDist = 20.0f;
}
if (m_input->GetKeyState(INPUT_SLOT_AWAY))
{
m_visitDist += event.rTime * 50.0f * m_speed;
if (m_visitDist > 200.0f) m_visitDist = 200.0f;
}
Math::Vector cameraMove = CalculateCameraMovement(event);
// PageUp/Down.
if (m_input->GetKeyState(INPUT_SLOT_CAMERA_UP))
{
m_visitDirectionV -= event.rTime * 1.0f * m_speed;
if (m_visitDirectionV < -Math::PI * 0.40f) m_visitDirectionV = -Math::PI * 0.40f;
}
if (m_input->GetKeyState(INPUT_SLOT_CAMERA_DOWN))
{
m_visitDirectionV += event.rTime * 1.0f * m_speed;
if (m_visitDirectionV > 0.0f ) m_visitDirectionV = 0.0f;
}
// ZoomIn/ZoomOut
m_visitDist += cameraMove.z;
m_visitDist = Math::Clamp(m_visitDist, 20.0f, 200.0f);
m_visitDist -= m_mouseDelta.y * 100.0f * m_speed;
m_mouseDelta.LoadZero();
if (m_visitDist < 20.0f) m_visitDist = 20.0f;
if (m_visitDist > 200.0f) m_visitDist = 200.0f;
// Up/Down
m_visitDirectionV += cameraMove.y;
m_visitDirectionV = Math::Clamp(m_visitDirectionV, -Math::PI * 0.40f, 0.0f);
float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f);
float angleV = m_visitDirectionV;
@ -1726,4 +1592,38 @@ void CCamera::SetCameraSpeed(float speed)
m_speed = speed;
}
Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed)
{
Math::Vector delta;
delta.x += m_mouseDelta.x * 2*Math::PI;
delta.y -= m_mouseDelta.y * Math::PI;
m_mouseDelta.LoadZero();
delta.z += m_mouseWheelDelta * 8.0f;
m_mouseWheelDelta = 0.0f;
if (keysAllowed)
{
delta.x += event.cameraInput.x * event.rTime * 0.5f * m_speed;
delta.y -= event.cameraInput.y * event.rTime * 0.5f * m_speed;
if (m_cameraObj == nullptr)
{
delta.x += event.motionInput.x * event.rTime * 0.5f * m_speed;
delta.y -= event.motionInput.y * event.rTime * 0.5f * m_speed;
}
if (m_input->GetKeyState(INPUT_SLOT_NEAR))
delta.z -= event.rTime * 20.0f * m_speed;
if (m_input->GetKeyState(INPUT_SLOT_AWAY))
delta.z += event.rTime * 20.0f * m_speed;
}
if (delta.Length() > 0)
AbortCentering(); // special stops framing
return delta;
}
}

View File

@ -223,9 +223,7 @@ protected:
//! Changes the camera according to the time elapsed
bool EventFrame(const Event &event);
//! Moves the point of view
bool EventFrameFree(const Event &event);
//! Moves the point of view
bool EventFrameEdit(const Event &event);
bool EventFrameFree(const Event &event, bool keysAllowed);
//! Moves the point of view
bool EventFrameDialog(const Event &event);
//! Moves the point of view
@ -264,6 +262,13 @@ protected:
//! Advanced overlay effect in the foreground
void OverFrame(const Event &event);
/**
* \brief Calculate camera movement (from user inputs) to apply
* \return Math::Vector where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change)
* \remarks Should not be called more often than once every EVENT_FRAME
**/
Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed = true);
protected:
CEngine* m_engine;
CRobotMain* m_main;
@ -339,15 +344,13 @@ protected:
//! CAM_TYPE_VISIT: direction
float m_visitDirectionV;
//! CAM_TYPE_EDIT: height
float m_editHeight;
float m_remotePan;
//! Last known mouse position, used to calculate change since last frame
Math::Point m_mousePos = Math::Point(0.5f, 0.5f);
Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f);
Math::Point m_mouseDeltaEdge = Math::Point(0.0f, 0.0f);
float m_mouseWheelDelta = 0.0f;
CenteringPhase m_centeringPhase;
float m_centeringAngleH;