1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#include "StdAfx.h"
#include <SDL_keysym.h>
#include "mmgr.h"
#include "OverheadController.h"
#include "ConfigHandler.h"
#include "Game/Camera.h"
#include "Game/CameraHandler.h"
#include "Game/UI/MouseHandler.h"
#include "LogOutput.h"
#include "Map/Ground.h"
#include "GlobalUnsynced.h"
#include <boost/cstdint.hpp>
extern boost::uint8_t *keys;
COverheadController::COverheadController()
: flipped(false),
zscale(0.5f),
height(500),
oldAltHeight(500),
changeAltHeight(true),
maxHeight(10000)
{
scrollSpeed = configHandler->Get("OverheadScrollSpeed",10)*0.1f;
tiltSpeed = configHandler->Get("OverheadTiltSpeed",1.0f);
enabled = !!configHandler->Get("OverheadEnabled",1);
fov = configHandler->Get("OverheadFOV", 45.0f);
}
void COverheadController::KeyMove(float3 move)
{
if (flipped) {
move.x = -move.x;
move.y = -move.y;
}
move*=sqrt(move.z)*200;
float pixelsize= camera->GetTanHalfFov()*2/gu->viewSizeY*height*2;
pos.x+=move.x*pixelsize*2*scrollSpeed;
pos.z-=move.y*pixelsize*2*scrollSpeed;
}
void COverheadController::MouseMove(float3 move)
{
if (flipped) {
move.x = -move.x;
move.y = -move.y;
}
float pixelsize=100*mouseScale* camera->GetTanHalfFov() *2/gu->viewSizeY*height*2;
pos.x+=move.x*pixelsize*(1+keys[SDLK_LSHIFT]*3)*scrollSpeed;
pos.z+=move.y*pixelsize*(1+keys[SDLK_LSHIFT]*3)*scrollSpeed;
}
void COverheadController::ScreenEdgeMove(float3 move)
{
KeyMove(move);
}
void COverheadController::MouseWheelMove(float move)
{
// tilt the camera if LCTRL is pressed
if (keys[SDLK_LCTRL]) {
zscale *= (1.0f + (move * tiltSpeed * mouseScale * (keys[SDLK_LSHIFT] ? 3.0f : 1.0f)));
if (zscale < 0.05f) zscale = 0.05f;
if (zscale > 10) zscale = 10;
} else { // holding down LALT uses 'instant-zoom' from here to the end of the function
// ZOOM IN to mouse cursor instead of mid screen
if (move < 0) {
float3 cpos=pos-dir*height;
float dif=-height * move * mouseScale*0.7f * (keys[SDLK_LSHIFT] ? 3:1);
if ((height - dif) <60.0f) {
dif = height - 60.0f;
}
if (keys[SDLK_LALT]) { // instant-zoom: zoom in to standard view
dif = (height - oldAltHeight) / mouse->dir.y * dir.y;
}
float3 wantedPos = cpos + mouse->dir * dif;
float newHeight = ground->LineGroundCol(wantedPos, wantedPos + dir * 15000);
if (newHeight < 0) {
newHeight = height* (1.0f + move * mouseScale * 0.7f * (keys[SDLK_LSHIFT] ? 3:1));
}
if ((wantedPos.y + (dir.y * newHeight)) < 0) {
newHeight = -wantedPos.y / dir.y;
}
if (newHeight < maxHeight) {
height = newHeight;
pos = wantedPos + dir * height;
}
// ZOOM OUT from mid screen
} else {
if (keys[SDLK_LALT]) { // instant-zoom: zoom out to the max
if(height<maxHeight*0.5f && changeAltHeight){
oldAltHeight=height;
changeAltHeight=false;
}
height=maxHeight;
pos.x=gs->mapx*4;
pos.z=gs->mapy*4.8f; // somewhat longer toward bottom
} else {
height*=1+move * mouseScale*0.7f * (keys[SDLK_LSHIFT] ? 3:1);
}
}
// instant-zoom: turn on the smooth transition and reset the camera tilt
if (keys[SDLK_LALT]) {
zscale = 0.5f;
camHandler->CameraTransition(1.0f);
} else {
changeAltHeight = true;
}
}
}
void COverheadController::Update()
{
}
float3 COverheadController::GetPos()
{
maxHeight = 9.5f * std::max(gs->mapx,gs->mapy); //map not created when constructor run
if (pos.x < 0.01f) { pos.x = 0.01f; }
if (pos.z < 0.01f) { pos.z = 0.01f; }
if (pos.x > ((gs->mapx * SQUARE_SIZE) - 0.01f)) {
pos.x = ((gs->mapx * SQUARE_SIZE) - 0.01f);
}
if (pos.z > ((gs->mapy * SQUARE_SIZE) - 0.01f)) {
pos.z = ((gs->mapy * SQUARE_SIZE) - 0.01f);
}
if (height < 60.0f) {
height = 60.0f;
}
if (height > maxHeight) {
height = maxHeight;
}
pos.y = ground->GetHeight(pos.x,pos.z);
dir = float3(0.0f, -1.0f, flipped ? zscale : -zscale).ANormalize();
float3 cpos = pos - dir * height;
return cpos;
}
float3 COverheadController::GetDir()
{
return dir;
}
float3 COverheadController::SwitchFrom() const
{
return pos;
}
void COverheadController::SwitchTo(bool showText)
{
if(showText)
logOutput.Print("Switching to Overhead (TA) style camera");
}
void COverheadController::GetState(StateMap& sm) const
{
sm["px"] = pos.x;
sm["py"] = pos.y;
sm["pz"] = pos.z;
sm["dx"] = dir.x;
sm["dy"] = dir.y;
sm["dz"] = dir.z;
sm["height"] = height;
sm["zscale"] = zscale;
sm["flipped"] = flipped ? +1.0f : -1.0f;
}
bool COverheadController::SetState(const StateMap& sm)
{
SetStateFloat(sm, "px", pos.x);
SetStateFloat(sm, "py", pos.y);
SetStateFloat(sm, "pz", pos.z);
SetStateFloat(sm, "dx", dir.x);
SetStateFloat(sm, "dy", dir.y);
SetStateFloat(sm, "dz", dir.z);
SetStateFloat(sm, "height", height);
SetStateFloat(sm, "zscale", zscale);
SetStateBool (sm, "flipped", flipped);
return true;
}
|