Right click camera; minor CCamera cleanups

dev-time-step
krzys-h 2016-02-14 15:51:18 +01:00
parent d9ccd6edf3
commit 47d39e5b22
13 changed files with 87 additions and 177 deletions

View File

@ -636,16 +636,6 @@ struct MouseButtonEventData : public EventData
MouseButton button = MOUSE_BUTTON_LEFT;
};
/**
* \enum WheelDirection
* \brief Direction of mouse wheel movement
*/
enum WheelDirection
{
WHEEL_UP,
WHEEL_DOWN
};
/**
* \struct MouseWheelEventData
* \brief Additional data for mouse wheel event.

View File

@ -98,11 +98,6 @@ CCamera::CCamera()
m_normLookat = Math::Vector(0.0f, 0.0f, 0.0f);
m_focus = 1.0f;
m_rightDown = false;
m_rightPosInit = Math::Point(0.5f, 0.5f);
m_rightPosCenter = Math::Point(0.5f, 0.5f);
m_rightPosMove = Math::Point(0.5f, 0.5f);
m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f);
m_directionH = 0.0f;
m_directionV = 0.0f;
@ -130,12 +125,6 @@ CCamera::CCamera()
m_remotePan = 0.0f;
m_mouseDirH = 0.0f;
m_mouseDirV = 0.0f;
m_mouseMarging = 0.01f;
m_motorTurn = 0.0f;
m_centeringPhase = CAM_PHASE_NULL;
m_centeringAngleH = 0.0f;
m_centeringAngleV = 0.0f;
@ -222,13 +211,6 @@ bool CCamera::GetCameraInvertY()
return m_cameraInvertY;
}
float CCamera::GetMotorTurn()
{
if (m_type == CAM_TYPE_BACK)
return m_motorTurn;
return 0.0f;
}
void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay)
{
m_initDelay = delay;
@ -1076,6 +1058,11 @@ bool CCamera::EventProcess(const Event &event)
EventFrame(event);
break;
case EVENT_MOUSE_BUTTON_DOWN:
case EVENT_MOUSE_BUTTON_UP:
EventMouseButton(event);
break;
case EVENT_MOUSE_MOVE:
EventMouseMove(event);
break;
@ -1092,7 +1079,10 @@ bool CCamera::EventProcess(const Event &event)
bool CCamera::EventMouseMove(const Event &event)
{
m_mouseDelta += (event.mousePos - m_mousePos);
m_mousePos = event.mousePos;
if (m_mouseRightDown)
m_engine->SetMouseType(ENG_MOUSE_MOVE);
return true;
}
@ -1129,6 +1119,24 @@ void CCamera::EventMouseWheel(const Event &event)
}
}
void CCamera::EventMouseButton(const Event &event)
{
if (event.GetData<MouseButtonEventData>()->button == MOUSE_BUTTON_RIGHT)
{
if (event.type == EVENT_MOUSE_BUTTON_DOWN)
{
m_mouseRightDown = true;
m_mouseDelta.LoadZero();
m_engine->SetMouseType(ENG_MOUSE_MOVE);
}
else
{
m_mouseRightDown = false;
m_engine->SetMouseType(ENG_MOUSE_NORM);
}
}
}
bool CCamera::EventFrame(const Event &event)
{
EffectFrame(event);
@ -1168,69 +1176,6 @@ bool CCamera::EventFrame(const Event &event)
return true;
}
EngineMouseType CCamera::GetMouseDef(Math::Point pos)
{
EngineMouseType type = ENG_MOUSE_NORM;
m_mousePos = pos;
if (m_type == CAM_TYPE_INFO)
return type;
if (m_rightDown) // the right button pressed?
{
m_rightPosMove.x = pos.x - m_rightPosCenter.x;
m_rightPosMove.y = pos.y - m_rightPosCenter.y;
type = ENG_MOUSE_MOVE;
}
else
{
if (!m_cameraScroll)
return type;
m_mouseDirH = 0.0f;
m_mouseDirV = 0.0f;
if (pos.x < m_mouseMarging)
m_mouseDirH = pos.x / m_mouseMarging - 1.0f;
if (pos.x > 1.0f - m_mouseMarging)
m_mouseDirH = 1.0f - (1.0f - pos.x) / m_mouseMarging;
if (pos.y < m_mouseMarging)
m_mouseDirV = pos.y / m_mouseMarging - 1.0f;
if (pos.y > 1.0f-m_mouseMarging)
m_mouseDirV = 1.0f - (1.0f - pos.y) / m_mouseMarging;
if ( m_type == CAM_TYPE_FREE ||
m_type == CAM_TYPE_EDIT ||
m_type == CAM_TYPE_BACK ||
m_type == CAM_TYPE_FIX ||
m_type == CAM_TYPE_PLANE ||
m_type == CAM_TYPE_EXPLO )
{
if (m_mouseDirH > 0.0f)
type = ENG_MOUSE_SCROLLR;
if (m_mouseDirH < 0.0f)
type = ENG_MOUSE_SCROLLL;
}
if ( m_type == CAM_TYPE_FREE ||
m_type == CAM_TYPE_EDIT )
{
if (m_mouseDirV > 0.0f)
type = ENG_MOUSE_SCROLLU;
if (m_mouseDirV < 0.0f)
type = ENG_MOUSE_SCROLLD;
}
if (m_cameraInvertX)
m_mouseDirH = -m_mouseDirH;
}
return type;
}
bool CCamera::EventFrameFree(const Event &event)
{
Math::Vector cameraInput = event.cameraInput;
@ -1241,10 +1186,12 @@ bool CCamera::EventFrameFree(const Event &event)
float factor = m_heightEye * 0.5f + 30.0f;
if ( m_mouseDirH != 0.0f )
m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed;
if ( m_mouseDirV != 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed);
if ( m_mouseRightDown )
{
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();
}
// Up/Down
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, cameraInput.y * event.rTime * factor * m_speed);
@ -1314,17 +1261,13 @@ bool CCamera::EventFrameEdit(const Event &event)
{
float factor = m_editHeight * 0.5f + 30.0f;
if (m_mouseDirH != 0.0f)
m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed;
if (m_mouseDirV != 0.0f)
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed);
if (m_cameraScroll)
if (m_mouseRightDown)
{
// Left/Right.
m_fixDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed;
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
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();
}
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
m_terrain->AdjustToBounds(m_eyePt, 10.0f);
@ -1377,25 +1320,13 @@ bool CCamera::EventFrameBack(const Event &event)
if (m_backDist > 200.0f) m_backDist = 200.0f;
}
m_motorTurn = 0.0f;
if (m_rightDown)
if (m_mouseRightDown)
{
m_addDirectionH = m_rightPosMove.x * 6.0f;
m_addDirectionV = -m_rightPosMove.y * 2.0f;
}
else
{
if (m_cameraScroll)
{
// Left/Right
m_addDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed;
m_addDirectionH = Math::NormAngle(m_addDirectionH);
}
}
if ((m_mouseDirH != 0) || (m_mouseDirV != 0))
m_addDirectionH -= m_mouseDelta.x * 2*Math::PI;
m_addDirectionH = Math::NormAngle(m_addDirectionH);
m_mouseDelta.LoadZero();
AbortCentering(); // special stops framing
}
// Increase the special framework
float centeringH = 0.0f;
@ -1528,21 +1459,21 @@ bool CCamera::EventFrameFix(const Event &event)
if (m_fixDist > 200.0f) m_fixDist = 200.0f;
}
// Left/Right
if (m_cameraScroll)
if (m_mouseRightDown)
{
m_fixDirectionH += m_mouseDirH * event.rTime * 1.0f * m_speed;
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI;
m_mouseDelta.LoadZero();
AbortCentering(); // special stops framing
}
// Left/Right
m_fixDirectionH += event.cameraInput.x * event.rTime * 0.7f * m_speed;
m_fixDirectionH = Math::NormAngle(m_fixDirectionH);
// 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);
if ((m_mouseDirH != 0) || (m_mouseDirV != 0))
AbortCentering(); // special stops framing
if (m_cameraObj != nullptr)
{
Math::Vector lookatPt = m_cameraObj->GetPosition();
@ -1567,8 +1498,11 @@ bool CCamera::EventFrameFix(const Event &event)
bool CCamera::EventFrameExplo(const Event &event)
{
if (m_mouseDirH != 0.0f)
m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed;
if (m_mouseRightDown)
{
m_directionH -= m_mouseDelta.x * 2*Math::PI;
m_mouseDelta.LoadZero();
}
m_terrain->AdjustToBounds(m_eyePt, 10.0f);
@ -1649,9 +1583,10 @@ bool CCamera::EventFrameVisit(const Event &event)
if (m_visitDirectionV > 0.0f ) m_visitDirectionV = 0.0f;
}
if (m_cameraScroll)
if (m_mouseRightDown)
{
m_visitDist -= m_mouseDirV * event.rTime * 30.0f * m_speed;
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;
}
@ -1744,5 +1679,4 @@ void CCamera::SetCameraSpeed(float speed)
m_speed = speed;
}
}

View File

@ -211,18 +211,15 @@ public:
void SetCameraInvertY(bool invert);
bool GetCameraInvertY();
//! Returns an additional force to turn
float GetMotorTurn();
//! Returns the default sprite to use for the mouse
EngineMouseType GetMouseDef(Math::Point pos);
void SetCameraSpeed(float speed);
protected:
//! Changes the camera according to the mouse moved
bool EventMouseMove(const Event &event);
//! Mouse wheel operation
void EventMouseWheel(const Event& event);
void EventMouseWheel(const Event &event);
//! Mouse button handling
void EventMouseButton(const Event &event);
//! Changes the camera according to the time elapsed
bool EventFrame(const Event &event);
//! Moves the point of view
@ -301,11 +298,6 @@ protected:
float m_focus;
bool m_rightDown;
Math::Point m_rightPosInit;
Math::Point m_rightPosCenter;
Math::Point m_rightPosMove;
//! CAM_TYPE_FREE: eye
Math::Vector m_eyePt;
//! CAM_TYPE_FREE: horizontal direction
@ -352,12 +344,9 @@ protected:
float m_remotePan;
Math::Point m_mousePos;
float m_mouseDirH;
float m_mouseDirV;
float m_mouseMarging;
float m_motorTurn;
bool m_mouseRightDown = false;
Math::Point m_mousePos = Math::Point(0.5f, 0.5f);
Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f);
CenteringPhase m_centeringPhase;
float m_centeringAngleH;
@ -396,7 +385,6 @@ protected:
bool m_cameraInvertX;
//! Y inversion in the edges?
bool m_cameraInvertY;
};

View File

@ -687,7 +687,6 @@ bool CRobotMain::ProcessEvent(Event &event)
m_displayText->EventProcess(event);
RemoteCamera(m_cameraPan, m_cameraZoom, event.rTime);
m_interface->EventProcess(event);
if (m_displayInfo != nullptr) // current edition?
m_displayInfo->EventProcess(event);

View File

@ -2103,7 +2103,6 @@ bool COldObject::EventProcess(const Event &event)
axeZ = -1.0f; // tomb
}
axeX += m_camera->GetMotorTurn(); // additional power according to camera
if ( axeX > 1.0f ) axeX = 1.0f;
if ( axeX < -1.0f ) axeX = -1.0f;

View File

@ -314,7 +314,7 @@ bool CControl::EventProcess(const Event &event)
GlintFrame(event);
}
if ( event.type == EVENT_MOUSE_MOVE )
if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP )
{
m_glintMouse = event.mousePos;

View File

@ -266,7 +266,7 @@ bool CEdit::EventProcess(const Event &event)
m_timeBlink += event.rTime;
}
if ( event.type == EVENT_MOUSE_MOVE )
if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP )
{
if ( Detect(event.mousePos) &&
event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )

View File

@ -54,7 +54,6 @@ CInterface::CInterface()
{
m_event = CApplication::GetInstancePointer()->GetEventQueue();
m_engine = Gfx::CEngine::GetInstancePointer();
m_camera = nullptr;
}
// Object's destructor.
@ -300,12 +299,9 @@ CControl* CInterface::SearchControl(EventType eventMsg)
bool CInterface::EventProcess(const Event &event)
{
if (event.type == EVENT_MOUSE_MOVE)
if (event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP)
{
if (m_camera == nullptr)
m_camera = CRobotMain::GetInstancePointer()->GetCamera();
m_engine->SetMouseType(m_camera->GetMouseDef(event.mousePos));
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
}
for (auto& control : boost::adaptors::reverse(m_controls))

View File

@ -29,7 +29,6 @@
namespace Gfx
{
class CCamera;
class CEngine;
} // namespace Gfx
@ -101,7 +100,6 @@ protected:
CEventQueue* m_event;
Gfx::CEngine* m_engine;
Gfx::CCamera* m_camera;
std::array<std::unique_ptr<CControl>, MAXCONTROL> m_controls;
};

View File

@ -293,15 +293,18 @@ bool CList::EventProcess(const Event &event)
CControl::EventProcess(event);
if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos))
if (event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP)
{
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
for (int i = 0; i < m_displayLine; i++)
if (Detect(event.mousePos))
{
if (i + m_firstLine >= m_totalLine)
break;
if (m_buttons[i] != nullptr)
m_buttons[i]->EventProcess(event);
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
for (int i = 0; i < m_displayLine; i++)
{
if (i + m_firstLine >= m_totalLine)
break;
if (m_buttons[i] != nullptr)
m_buttons[i]->EventProcess(event);
}
}
}

View File

@ -203,12 +203,15 @@ bool CMap::EventProcess(const Event &event)
if ( event.type == EVENT_FRAME )
m_time += event.rTime;
if ( event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos) )
if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP )
{
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
bool inMap = false;
if (DetectObject(event.mousePos, inMap) != nullptr)
m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND);
if (Detect(event.mousePos))
{
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
bool inMap = false;
if (DetectObject(event.mousePos, inMap) != nullptr)
m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND);
}
}
if (event.type == EVENT_MOUSE_BUTTON_DOWN &&

View File

@ -64,7 +64,7 @@ bool CTarget::EventProcess(const Event &event)
CControl::EventProcess(event);
if ( event.type == EVENT_MOUSE_MOVE )
if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP )
{
m_main->SetFriendAim(false);

View File

@ -662,7 +662,7 @@ int CWindow::BorderDetect(Math::Point pos)
bool CWindow::EventProcess(const Event &event)
{
if ( event.type == EVENT_MOUSE_MOVE )
if ( event.type == EVENT_MOUSE_MOVE || event.type == EVENT_MOUSE_BUTTON_DOWN || event.type == EVENT_MOUSE_BUTTON_UP )
{
if ( m_bCapture )
{