Skip to content

Commit

Permalink
further improve zooming in spring cam
Browse files Browse the repository at this point in the history
  • Loading branch information
jK committed Dec 8, 2014
1 parent fb2f27f commit 49484f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
1 change: 0 additions & 1 deletion rts/Game/Camera/FreeController.cpp
Expand Up @@ -444,7 +444,6 @@ bool CFreeController::SetState(const StateMap& sm)
rot.x += (fastmath::HALFPI);
rot.x = fastmath::PI - rot.x;
rot.y -= fastmath::PI;
LOG("rot.x %f", rot.x);
camera->SetRot(rot);

SetStateFloat(sm, "vx", prevVel.x);
Expand Down
37 changes: 28 additions & 9 deletions rts/Game/Camera/SpringController.cpp
Expand Up @@ -106,16 +106,22 @@ void CSpringController::MouseWheelMove(float move)
dist = oldDist;
zoomBack = false;
camHandler->CameraTransition(0.5f);
} else {
float newDist = CGround::LineGroundCol(curPos, curPos + mouse->dir * 15000, false);
if (newDist > 0.0f) {
pos = curPos + mouse->dir * newDist;
}
camera->SetPos(GetPos());
camera->Update();
float3 winPos = camera->CalcWindowCoordinates(pos);
mouse->WarpMouse(winPos.x, globalRendering->viewSizeY - winPos.y);
}

// zoom into mouse cursor pos
float newDist = CGround::LineGroundCol(curPos, curPos + mouse->dir * 15000, false);
if (newDist > 0.0f) {
pos = curPos + mouse->dir * newDist;
}
camera->SetPos(GetPos());
camera->Update();
camHandler->CameraTransition(0.25f);

warpMouseStart = spring_gettime();
warpMousePosOld = int2(mouse->lastx, mouse->lasty);
float3 winPos = camera->CalcWindowCoordinates(pos);
winPos.y = globalRendering->viewSizeY - winPos.y;
warpMousePosNew = int2(winPos.x, winPos.y);
} else {
// ZOOM OUT from mid screen
if (KeyInput::GetKeyModState(KMOD_ALT)) {
Expand All @@ -141,6 +147,19 @@ void CSpringController::MouseWheelMove(float move)

void CSpringController::Update()
{
if (warpMouseStart.isTime()) {
const float animSecs = 0.15f;
spring_time now = spring_gettime();
const float a = Clamp((now - warpMouseStart).toSecsf(), 0.f, animSecs) * (1.f / animSecs);
int2 mpos;
mpos.x = mix<int>(warpMousePosOld.x, warpMousePosNew.x, a);
mpos.y = mix<int>(warpMousePosOld.y, warpMousePosNew.y, a);
mouse->WarpMouse(mpos.x, mpos.y);
if (a >= 1.f) {
warpMouseStart = spring_notime;
}
}

pos.ClampInMap();
pos.y = CGround::GetHeightAboveWater(pos.x, pos.z, false) + 5.f;

Expand Down
7 changes: 7 additions & 0 deletions rts/Game/Camera/SpringController.h
Expand Up @@ -4,6 +4,9 @@
#define _SPRING_CONTROLLER_H

#include "CameraController.h"
#include "System/Misc/SpringTime.h"
#include "System/type2.h"


class CSpringController : public CCameraController
{
Expand Down Expand Up @@ -38,6 +41,10 @@ class CSpringController : public CCameraController
float maxDist;
bool zoomBack;
float oldDist;

spring_time warpMouseStart;
int2 warpMousePosOld;
int2 warpMousePosNew;
};

#endif // _SPRING_CONTROLLER_H

0 comments on commit 49484f3

Please sign in to comment.