# Support '[', ']' keys for camera rotation in scenario editor

This was SVN commit r7460.
This commit is contained in:
Ykkrosh 2010-04-17 11:28:54 +00:00
parent 4570a6af72
commit b6a9e0e9b7
5 changed files with 44 additions and 11 deletions

View File

@ -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
{

View File

@ -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;
};

View File

@ -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");
}

View File

@ -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);

View File

@ -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