mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Simplify Dyncam and fix #311
This commit is contained in:
parent
ff09eff526
commit
1dddf42cbb
|
@ -61,7 +61,7 @@ void CInput::MouseRelative(float *x, float *y)
|
|||
*y = ny;
|
||||
#else
|
||||
int nx = 0, ny = 0;
|
||||
float Sens = g_Config.m_InpMousesens/100.0f;
|
||||
float Sens = (g_Config.m_ClDyncam ? g_Config.m_ClDyncamMousesens : g_Config.m_InpMousesens) / 100.0f;
|
||||
|
||||
if(g_Config.m_InpGrab)
|
||||
SDL_GetRelativeMouseState(&nx, &ny);
|
||||
|
|
|
@ -64,8 +64,8 @@ void CCamera::OnRender()
|
|||
float l = length(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy]);
|
||||
if(l > 0.0001f) // make sure that this isn't 0
|
||||
{
|
||||
float DeadZone = g_Config.m_ClMouseDeadzone;
|
||||
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
|
||||
float DeadZone = g_Config.m_ClDyncam ? g_Config.m_ClDyncamDeadzone : g_Config.m_ClMouseDeadzone;
|
||||
float FollowFactor = (g_Config.m_ClDyncam ? g_Config.m_ClDyncamFollowFactor : g_Config.m_ClMouseFollowfactor) / 100.0f;
|
||||
float OffsetAmount = max(l-DeadZone, 0.0f) * FollowFactor;
|
||||
|
||||
CameraOffset = normalize(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy])*OffsetAmount;
|
||||
|
@ -85,7 +85,6 @@ void CCamera::OnConsoleInit()
|
|||
Console()->Register("zoom+", "", CFGFLAG_CLIENT, ConZoomPlus, this, "Zoom increase");
|
||||
Console()->Register("zoom-", "", CFGFLAG_CLIENT, ConZoomMinus, this, "Zoom decrease");
|
||||
Console()->Register("zoom", "", CFGFLAG_CLIENT, ConZoomReset, this, "Zoom reset");
|
||||
Console()->Register("toggle_dynamic_camera", "", CFGFLAG_CLIENT, ConToggleDynamic, this, "Turn dynamic camera on/off");
|
||||
}
|
||||
|
||||
const float ZoomStep = 0.866025f;
|
||||
|
@ -127,34 +126,3 @@ void CCamera::ConZoomReset(IConsole::IResult *pResult, void *pUserData)
|
|||
pSelf->Client()->GetServerInfo(&Info);
|
||||
((CCamera *)pUserData)->OnReset();
|
||||
}
|
||||
|
||||
void CCamera::ToggleDynamic()
|
||||
{
|
||||
static int s_OldMousesens = 0;
|
||||
if(g_Config.m_ClMouseDeadzone)
|
||||
{
|
||||
g_Config.m_ClMouseFollowfactor = 0;
|
||||
g_Config.m_ClMouseMaxDistance = g_Config.m_ClDefaultMouseMaxDistance;
|
||||
g_Config.m_ClMouseDeadzone = 0;
|
||||
if(g_Config.m_ClDyncamMousesens && s_OldMousesens)
|
||||
{
|
||||
g_Config.m_InpMousesens = s_OldMousesens;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s_OldMousesens = g_Config.m_InpMousesens;
|
||||
g_Config.m_ClMouseFollowfactor = g_Config.m_ClDyncamFollowFactor;
|
||||
g_Config.m_ClMouseMaxDistance = g_Config.m_ClDyncamMaxDistance;
|
||||
g_Config.m_ClMouseDeadzone = g_Config.m_ClDyncamDeadzone;
|
||||
if(g_Config.m_ClDyncamMousesens)
|
||||
{
|
||||
g_Config.m_InpMousesens = g_Config.m_ClDyncamMousesens;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCamera::ConToggleDynamic(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
ToggleDynamic();
|
||||
}
|
||||
|
|
|
@ -31,12 +31,10 @@ public:
|
|||
virtual void OnConsoleInit();
|
||||
virtual void OnReset();
|
||||
|
||||
static void ToggleDynamic();
|
||||
private:
|
||||
static void ConZoomPlus(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConZoomMinus(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConZoomReset(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConToggleDynamic(IConsole::IResult *pResult, void *pUserData);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -509,8 +509,10 @@ void CControls::ClampMousePos()
|
|||
else
|
||||
{
|
||||
float CameraMaxDistance = 200.0f;
|
||||
float FollowFactor = g_Config.m_ClMouseFollowfactor/100.0f;
|
||||
float MouseMax = min(CameraMaxDistance/FollowFactor + g_Config.m_ClMouseDeadzone, (float)g_Config.m_ClMouseMaxDistance);
|
||||
float FollowFactor = (g_Config.m_ClDyncam ? g_Config.m_ClDyncamFollowFactor : g_Config.m_ClMouseFollowfactor) / 100.0f;
|
||||
float DeadZone = g_Config.m_ClDyncam ? g_Config.m_ClDyncamDeadzone : g_Config.m_ClMouseDeadzone;
|
||||
float MaxDistance = g_Config.m_ClDyncam ? g_Config.m_ClDyncamMaxDistance : g_Config.m_ClMouseMaxDistance;
|
||||
float MouseMax = min(CameraMaxDistance/FollowFactor + DeadZone, MaxDistance);
|
||||
|
||||
if(length(m_MousePos[g_Config.m_ClDummy]) > MouseMax)
|
||||
m_MousePos[g_Config.m_ClDummy] = normalize(m_MousePos[g_Config.m_ClDummy])*MouseMax;
|
||||
|
|
|
@ -72,11 +72,8 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView)
|
|||
|
||||
// dynamic camera
|
||||
Left.HSplitTop(20.0f, &Button, &Left);
|
||||
static int s_DynamicCameraButton = 0;
|
||||
if(DoButton_CheckBox(&s_DynamicCameraButton, Localize("Dynamic Camera"), g_Config.m_ClMouseDeadzone != 0, &Button))
|
||||
{
|
||||
CCamera::ToggleDynamic();
|
||||
}
|
||||
if(DoButton_CheckBox(&g_Config.m_ClDyncam, Localize("Dynamic Camera"), g_Config.m_ClDyncam, &Button))
|
||||
g_Config.m_ClDyncam ^= 1;
|
||||
|
||||
// weapon pickup
|
||||
Left.HSplitTop(5.0f, 0, &Left);
|
||||
|
@ -566,7 +563,7 @@ static CKeyInfo gs_aKeys[] =
|
|||
{ "Fire", "+fire", 0 },
|
||||
{ "Hook", "+hook", 0 },
|
||||
{ "Hook Collisions", "+showhookcoll", 0 },
|
||||
{ "Dynamic Camera", "toggle_dynamic_camera", 0 },
|
||||
{ "Dynamic Camera", "toggle cl_dyncam 0 1", 0 },
|
||||
{ "Hammer", "+weapon1", 0 },
|
||||
{ "Pistol", "+weapon2", 0 },
|
||||
{ "Shotgun", "+weapon3", 0 },
|
||||
|
|
|
@ -64,7 +64,8 @@ void CUI::ConvertMouseMove(float *x, float *y)
|
|||
//*x = *x * 500 / g_Config.m_GfxScreenWidth;
|
||||
//*y = *y * 500 / g_Config.m_GfxScreenHeight;
|
||||
#else
|
||||
float Fac = (float)(g_Config.m_UiMousesens)/g_Config.m_InpMousesens;
|
||||
float Mousesens = g_Config.m_ClDyncam ? g_Config.m_ClDyncamMousesens : g_Config.m_InpMousesens;
|
||||
float Fac = (float)(g_Config.m_UiMousesens)/Mousesens;
|
||||
*x = *x*Fac;
|
||||
*y = *y*Fac;
|
||||
#endif
|
||||
|
|
|
@ -52,8 +52,8 @@ MACRO_CONFIG_INT(ClMouseMaxDistance, cl_mouse_max_distance, 400, 0, 0, CFGFLAG_C
|
|||
MACRO_CONFIG_INT(ClMouseMaxDistance, cl_mouse_max_distance, 800, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "")
|
||||
#endif
|
||||
|
||||
MACRO_CONFIG_INT(ClDyncam, cl_dyncam, 0, 0, 1, CFGFLAG_CLIENT, "Enable dyncam")
|
||||
MACRO_CONFIG_INT(ClDyncamMaxDistance, cl_dyncam_max_distance, 1000, 0, 2000, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Maximal dynamic camera distance")
|
||||
MACRO_CONFIG_INT(ClDefaultMouseMaxDistance, cl_default_mouse_max_distance, 400, 0, 2000, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Default mouse max distance. Dyncam switches back to it")
|
||||
MACRO_CONFIG_INT(ClDyncamMousesens, cl_dyncam_mousesens, 0, 0, 100000, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Mouse sens used when dyncam is toggled on")
|
||||
MACRO_CONFIG_INT(ClDyncamDeadzone, cl_dyncam_deadzone, 300, 1, 1300, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Dynamic camera dead zone")
|
||||
MACRO_CONFIG_INT(ClDyncamFollowFactor, cl_dyncam_follow_factor, 60, 0, 200, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Dynamic camera follow factor")
|
||||
|
|
Loading…
Reference in a new issue