From b6a9e0e9b776f922005abc9124624cf1e7573555 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 17 Apr 2010 11:28:54 +0000 Subject: [PATCH] # Support '[', ']' keys for camera rotation in scenario editor This was SVN commit r7460. --- .../AtlasUI/ScenarioEditor/ScenarioEditor.cpp | 14 +++++--- source/tools/atlas/GameInterface/GameLoop.h | 2 +- .../Handlers/CameraCtrlHandlers.cpp | 2 +- .../atlas/GameInterface/InputProcessor.cpp | 33 +++++++++++++++++-- source/tools/atlas/GameInterface/Messages.h | 4 +-- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index 720ad7e3b2..83ac09eca5 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2010 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -84,6 +84,8 @@ private: case WXK_RIGHT: dir = eScrollConstantDir::RIGHT; break; case WXK_UP: dir = eScrollConstantDir::FORWARDS; break; case WXK_DOWN: dir = eScrollConstantDir::BACKWARDS; break; + case ']': dir = eScrollConstantDir::CLOCKWISE; break; + case '[': dir = eScrollConstantDir::ANTICLOCKWISE; break; case WXK_SHIFT: case WXK_CONTROL: dir = -1; break; default: return false; } @@ -92,10 +94,12 @@ private: if (dir == -1) // changed modifier keys - update all currently-scrolling directions { - if (wxGetKeyState(WXK_LEFT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::LEFT, speed)); - if (wxGetKeyState(WXK_RIGHT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::RIGHT, speed)); - if (wxGetKeyState(WXK_UP)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::FORWARDS, speed)); - if (wxGetKeyState(WXK_DOWN)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::BACKWARDS, speed)); + if (wxGetKeyState(WXK_LEFT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::LEFT, speed)); + if (wxGetKeyState(WXK_RIGHT)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::RIGHT, speed)); + if (wxGetKeyState(WXK_UP)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::FORWARDS, speed)); + if (wxGetKeyState(WXK_DOWN)) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::BACKWARDS, speed)); + if (wxGetKeyState((wxKeyCode)']')) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::CLOCKWISE, speed)); + if (wxGetKeyState((wxKeyCode)'[')) POST_MESSAGE(ScrollConstant, (eRenderView::GAME, eScrollConstantDir::ANTICLOCKWISE, speed)); } else { diff --git a/source/tools/atlas/GameInterface/GameLoop.h b/source/tools/atlas/GameInterface/GameLoop.h index 17d5e036a4..039b333d6e 100644 --- a/source/tools/atlas/GameInterface/GameLoop.h +++ b/source/tools/atlas/GameInterface/GameLoop.h @@ -36,7 +36,7 @@ struct GameLoopState struct Input { - float scrollSpeed[4]; // [fwd, bwd, left, right]. 0.0f for disabled. + float scrollSpeed[6]; // [fwd, bwd, left, right, cw-rotation, ccw-rotation]. 0.0f for disabled. float zoomDelta; } input; }; diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp index 77aee09d48..5eee7d7d8f 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -38,7 +38,7 @@ MESSAGEHANDLER(ScrollConstant) if (g_Game->GetView()->GetCinema()->IsPlaying()) return; - if (msg->dir < 0 || msg->dir > 3) + if (msg->dir < 0 || msg->dir > 5) { debug_warn(L"ScrollConstant: invalid direction"); } diff --git a/source/tools/atlas/GameInterface/InputProcessor.cpp b/source/tools/atlas/GameInterface/InputProcessor.cpp index ce034f9bc2..488fdc5c9c 100644 --- a/source/tools/atlas/GameInterface/InputProcessor.cpp +++ b/source/tools/atlas/GameInterface/InputProcessor.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2010 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,8 +22,25 @@ #include "ps/Game.h" #include "graphics/Camera.h" #include "graphics/GameView.h" +#include "maths/Quaternion.h" -static float g_ViewZoomSmoothness = 0.02f; // TODO: configurable, like GameView +static float g_ViewZoomSmoothness = 0.02f; +static float g_ViewRotateScale = 0.02f; + +static void Rotate(CCamera& camera, float speed) +{ + CVector3D upwards(0.0f, 1.0f, 0.0f); + CVector3D origin = camera.m_Orientation.GetTranslation(); + CVector3D pivot = camera.GetFocus(); + CVector3D delta = origin - pivot; + + CQuaternion r; + r.FromAxisAngle(upwards, speed); + delta = r.Rotate(delta); + camera.m_Orientation.Translate(-origin); + camera.m_Orientation.Rotate(r); + camera.m_Orientation.Translate(pivot + delta); +} bool InputProcessor::ProcessInput(GameLoopState* state) { @@ -72,6 +89,18 @@ bool InputProcessor::ProcessInput(GameLoopState* state) moved = true; } + if (state->input.scrollSpeed[4] != 0.0f) + { + Rotate(*camera, input.scrollSpeed[4] * state->frameLength * g_ViewRotateScale); + moved = true; + } + + if (state->input.scrollSpeed[5] != 0.0f) + { + Rotate(*camera, -input.scrollSpeed[5] * state->frameLength * g_ViewRotateScale); + moved = true; + } + if (state->input.zoomDelta != 0.0f) { float zoom_proportion = powf(g_ViewZoomSmoothness, state->frameLength); diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 5d1a2533a0..49133e6f30 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -248,8 +248,8 @@ QUERY(Exit,,); // no inputs nor outputs ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -struct eScrollConstantDir { enum { FORWARDS, BACKWARDS, LEFT, RIGHT }; }; -MESSAGE(ScrollConstant, +struct eScrollConstantDir { enum { FORWARDS, BACKWARDS, LEFT, RIGHT, CLOCKWISE, ANTICLOCKWISE }; }; +MESSAGE(ScrollConstant, // set a constant scrolling(/rotation) rate ((int, view)) // eRenderView ((int, dir)) // eScrollConstantDir ((float, speed)) // set speed 0.0f to stop scrolling