2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/config.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <base/math.h>
|
|
|
|
#include <game/collision.h>
|
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/client/component.h>
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "camera.h"
|
|
|
|
#include "controls.h"
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-10-17 08:43:27 +00:00
|
|
|
const float ZoomStep = 0.75f;
|
|
|
|
void CCamera::ConZoomPlus(IConsole::IResult *pResult, void *pUserData, int ClientID) {
|
2010-10-29 21:28:15 +00:00
|
|
|
//if(g_Config.m_ClDDRaceCheats == 1 || ((CCamera *)pUserData)->m_pClient->m_IsDDRace)
|
2010-10-17 08:43:27 +00:00
|
|
|
((CCamera *)pUserData)->m_Zoom *= 1/ZoomStep;
|
|
|
|
}
|
|
|
|
void CCamera::ConZoomMinus(IConsole::IResult *pResult, void *pUserData, int ClientID) {
|
2010-10-29 21:28:15 +00:00
|
|
|
//if(g_Config.m_ClDDRaceCheats == 1 || ((CCamera *)pUserData)->m_pClient->m_IsDDRace)
|
2010-10-17 08:43:27 +00:00
|
|
|
((CCamera *)pUserData)->m_Zoom *= ZoomStep;
|
|
|
|
}
|
|
|
|
void CCamera::ConZoomReset(IConsole::IResult *pResult, void *pUserData, int ClientID) {
|
2010-10-29 21:28:15 +00:00
|
|
|
//if(g_Config.m_ClDDRaceCheats == 1 || ((CCamera *)pUserData)->m_pClient->m_IsDDRace)
|
2010-10-17 08:43:27 +00:00
|
|
|
((CCamera *)pUserData)->m_Zoom = 1.0f;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CCamera::CCamera()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-10-17 08:43:27 +00:00
|
|
|
m_Zoom = 1.0f;
|
2010-09-19 14:00:46 +00:00
|
|
|
m_WasSpectator = false;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CCamera::OnRender()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
|
|
|
//vec2 center;
|
2010-10-17 08:43:27 +00:00
|
|
|
|
2010-08-25 14:15:59 +00:00
|
|
|
|
2008-10-14 12:11:42 +00:00
|
|
|
// update camera center
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_pClient->m_Snap.m_Spectate)
|
2010-09-19 14:00:46 +00:00
|
|
|
{
|
2010-09-19 14:12:18 +00:00
|
|
|
if(!m_WasSpectator)
|
|
|
|
{
|
|
|
|
m_pClient->m_pControls->ClampMousePos();
|
|
|
|
m_WasSpectator = true;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Center = m_pClient->m_pControls->m_MousePos;
|
2010-09-19 14:00:46 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
|
|
|
{
|
2010-09-19 14:00:46 +00:00
|
|
|
if(m_WasSpectator)
|
|
|
|
{
|
|
|
|
m_pClient->m_pControls->ClampMousePos();
|
|
|
|
m_WasSpectator = false;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
float l = length(m_pClient->m_pControls->m_MousePos);
|
|
|
|
float DeadZone = g_Config.m_ClMouseDeadzone;
|
|
|
|
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
|
|
|
|
vec2 CameraOffset(0, 0);
|
2010-09-27 19:41:41 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float OffsetAmount = max(l-DeadZone, 0.0f) * FollowFactor;
|
2008-08-27 15:48:50 +00:00
|
|
|
if(l > 0.0001f) // make sure that this isn't 0
|
2010-05-29 07:25:38 +00:00
|
|
|
CameraOffset = normalize(m_pClient->m_pControls->m_MousePos)*OffsetAmount;
|
2010-09-27 19:41:41 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Center = m_pClient->m_LocalCharacterPos + CameraOffset;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-17 08:43:27 +00:00
|
|
|
|
|
|
|
void CCamera::OnConsoleInit()
|
|
|
|
{
|
|
|
|
Console()->Register("zoom+", "", CFGFLAG_CLIENT, ConZoomPlus, this, "Zoom increse", 0);
|
|
|
|
Console()->Register("zoom-", "", CFGFLAG_CLIENT, ConZoomMinus, this, "Zoom decrese", 0);
|
|
|
|
Console()->Register("zoom", "", CFGFLAG_CLIENT, ConZoomReset, this, "Zoom reset", 0);
|
|
|
|
}
|