From 75456c01566008fc6fffdfcdec502ef6a757ce18 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 16 Oct 2013 06:47:50 +0200 Subject: [PATCH] Nasty warpzone fixes for in_pitch_min/max at nondefault values. NEEDS A LOT OF TESTING ON WARPZONE HEAVY MAPS AND COMPARISON TO PREVIOUS BEHAVIOUR. --- qcsrc/client/View.qc | 2 +- qcsrc/client/autocvars.qh | 2 ++ qcsrc/server/defs.qh | 3 +++ qcsrc/server/miscfunctions.qc | 2 ++ qcsrc/server/vehicles/spiderbot.qc | 2 +- qcsrc/server/vehicles/vehicles.qc | 2 +- qcsrc/warpzonelib/anglestransform.qc | 23 +++++++++++++++++++++-- qcsrc/warpzonelib/anglestransform.qh | 2 +- qcsrc/warpzonelib/client.qc | 8 +++++--- qcsrc/warpzonelib/common.qc | 10 +++++----- qcsrc/warpzonelib/common.qh | 2 +- qcsrc/warpzonelib/server.qc | 4 ++-- 12 files changed, 45 insertions(+), 17 deletions(-) diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 46920a417..d23d12bca 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -517,7 +517,7 @@ void CSQC_UpdateView(float w, float h) } else { setproperty(VF_ORIGIN, trace_endpos); } - setproperty(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles)); + setproperty(VF_ANGLES, WarpZone_TransformVAngles(WarpZone_trace_transform, view_angles, autocvar_in_pitch_min, autocvar_in_pitch_max)); } else if(autocvar_chase_active < 0) // time to disable chase_active if it was set by this code { diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 8175695ab..6975598e5 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -427,3 +427,5 @@ string autocvar__cl_playermodel; float autocvar_cl_deathglow; float autocvar_developer_csqcentities; float autocvar_g_jetpack_attenuation; +float autocvar_in_pitch_min; +float autocvar_in_pitch_max; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index fe41a23fa..12fe8b2ce 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -271,6 +271,9 @@ float default_weapon_alpha; .float cvar_cl_gunalign; .float cvar_cl_noantilag; +.float cvar_in_pitch_min; +.float cvar_in_pitch_max; + .string weaponorder_byimpulse; .float cvar_cl_allow_uid2name; diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 0b5b42781..70fe699f3 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -508,6 +508,8 @@ void GetCvars(float f) GetCvars_handleFloat(s, f, cvar_cl_voice_directional_taunt_attenuation, "cl_voice_directional_taunt_attenuation"); GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share"); GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive"); + GetCvars_handleFloat(s, f, cvar_in_pitch_min, "in_pitch_min"); + GetCvars_handleFloat(s, f, cvar_in_pitch_max, "in_pitch_max"); self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share); self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive); diff --git a/qcsrc/server/vehicles/spiderbot.qc b/qcsrc/server/vehicles/spiderbot.qc index 9dc41952f..89772b77d 100644 --- a/qcsrc/server/vehicles/spiderbot.qc +++ b/qcsrc/server/vehicles/spiderbot.qc @@ -365,7 +365,7 @@ float spiderbot_frame() crosshair_trace(player); ad = vectoangles(normalize(trace_endpos - ad)); ad = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(spider.angles), AnglesTransform_FromAngles(ad))) - spider.tur_head.angles; - ad = AnglesTransform_Normalize(ad, TRUE); + ad = AnglesTransform_Normalize(ad, TRUE, -90, 90); //UpdateAuxiliaryXhair(player, trace_endpos, ('1 0 0' * player.vehicle_reload2) + ('0 1 0' * (1 - player.vehicle_reload2)), 2); // Rotate head diff --git a/qcsrc/server/vehicles/vehicles.qc b/qcsrc/server/vehicles/vehicles.qc index 75fa9407e..03dda94e0 100644 --- a/qcsrc/server/vehicles/vehicles.qc +++ b/qcsrc/server/vehicles/vehicles.qc @@ -1336,7 +1336,7 @@ vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname)); vtmp = vectoangles(normalize(_target - vtag)); vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles; - vtmp = AnglesTransform_Normalize(vtmp, TRUE); + vtmp = AnglesTransform_Normalize(vtmp, TRUE, _pichlimit_min, _pichlimit_max); ftmp = _aimspeed * frametime; vtmp_y = bound(-ftmp, vtmp_y, ftmp); vtmp_x = bound(-ftmp, vtmp_x, ftmp); diff --git a/qcsrc/warpzonelib/anglestransform.qc b/qcsrc/warpzonelib/anglestransform.qc index 3233f6a31..650cf314b 100644 --- a/qcsrc/warpzonelib/anglestransform.qc +++ b/qcsrc/warpzonelib/anglestransform.qc @@ -94,7 +94,7 @@ vector AnglesTransform_LeftDivide(vector from_transform, vector to_transform) return AnglesTransform_Multiply(AnglesTransform_Invert(from_transform), to_transform); } -vector AnglesTransform_Normalize(vector t, float minimize_roll) +vector AnglesTransform_Normalize(vector t, float minimize_roll, float pitchmin, float pitchmax) { float need_flip; // first, bring all angles in their range... @@ -104,7 +104,26 @@ vector AnglesTransform_Normalize(vector t, float minimize_roll) if(minimize_roll) need_flip = (t_z > 90 || t_z <= -90); else - need_flip = (t_x > 90 || t_x < -90); // for pitch we prefer to allow exactly -90 degrees for looking straight down + { + // Smaller values break the math. + pitchmin = min(-90, pitchmin); + pitchmax = max(90, pitchmax); + // And... + if (t_z > 90 || t_z <= -90) + { + // Roll is bad. Prefer flipping, but let's end up in the good range. + need_flip = (t_x >= pitchmin + 180 || t_x <= pitchmax - 180); + // NOTE: Is this the right decision or should it be > and pitchmax || t_x < pitchmin); + // for pitch we prefer to allow exactly the border angles degrees for looking straight down + } + } if(need_flip) { if(t_x >= 0) t_x = 180 - t_x; else t_x = -180 - t_x; diff --git a/qcsrc/warpzonelib/anglestransform.qh b/qcsrc/warpzonelib/anglestransform.qh index b1c8a85e9..f3fdd8320 100644 --- a/qcsrc/warpzonelib/anglestransform.qh +++ b/qcsrc/warpzonelib/anglestransform.qh @@ -18,7 +18,7 @@ vector AnglesTransform_TurnDirectionFR(vector transform); vector AnglesTransform_RightDivide(vector to_transform, vector from_transform); // A B^-1 vector AnglesTransform_LeftDivide(vector from_transform, vector to_transform); // A^-1 B -vector AnglesTransform_Normalize(vector t, float minimize_roll); // makes sure all angles are in their range: yaw in -180..180, pitch in -90..90, roll in -180..180 (or if minimize_roll is set, pitch in -180..180, roll in -90..90) +vector AnglesTransform_Normalize(vector t, float minimize_roll, float pitchmin, float pitchmax); // makes sure all angles are in their range: yaw in -180..180, pitch in -90..90, roll in -180..180 (or if minimize_roll is set, pitch in -180..180, roll in -90..90) vector AnglesTransform_ApplyToAngles(vector transform, vector v); vector AnglesTransform_ApplyToVAngles(vector transform, vector v); diff --git a/qcsrc/warpzonelib/client.qc b/qcsrc/warpzonelib/client.qc index 6f7561234..cd38e35f3 100644 --- a/qcsrc/warpzonelib/client.qc +++ b/qcsrc/warpzonelib/client.qc @@ -145,6 +145,8 @@ void WarpZone_Camera_Read(float isnew) } void CL_RotateMoves(vector ang) = #638; +float autocvar_in_pitch_min; +float autocvar_in_pitch_max; void WarpZone_Teleported_Read(float isnew) { vector v; @@ -155,7 +157,7 @@ void WarpZone_Teleported_Read(float isnew) if(!isnew) return; self.warpzone_transform = v; - setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(self, getpropertyvec(VF_CL_VIEWANGLES))); + setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(self, getpropertyvec(VF_CL_VIEWANGLES), autocvar_in_pitch_min, autocvar_in_pitch_max)); if(checkextension("DP_CSQC_ROTATEMOVES")) CL_RotateMoves(v); //CL_RotateMoves('0 90 0'); @@ -226,7 +228,7 @@ void WarpZone_FixPMove() if(e) { pmove_org = WarpZone_TransformOrigin(e, pmove_org); - input_angles = WarpZone_TransformVAngles(e, input_angles); + input_angles = WarpZone_TransformVAngles(e, input_angles, autocvar_in_pitch_min, autocvar_in_pitch_max); } } @@ -250,7 +252,7 @@ void WarpZone_FixView() if(e) { org = WarpZone_TransformOrigin(e, org); - ang = WarpZone_TransformVAngles(e, ang); + ang = WarpZone_TransformVAngles(e, ang, autocvar_in_pitch_min, autocvar_in_pitch_max); #ifdef WORKAROUND_XON010 dirty = 1; #endif diff --git a/qcsrc/warpzonelib/common.qc b/qcsrc/warpzonelib/common.qc index 386615247..d216b7f0a 100644 --- a/qcsrc/warpzonelib/common.qc +++ b/qcsrc/warpzonelib/common.qc @@ -504,7 +504,7 @@ vector WarpZone_TransformAngles(entity wz, vector v) return AnglesTransform_ApplyToAngles(wz.warpzone_transform, v); } -vector WarpZone_TransformVAngles(entity wz, vector ang) +vector WarpZone_TransformVAngles(entity wz, vector ang, float pitchmin, float pitchmax) { #ifdef KEEP_ROLL float roll; @@ -515,11 +515,11 @@ vector WarpZone_TransformVAngles(entity wz, vector ang) ang = AnglesTransform_ApplyToVAngles(wz.warpzone_transform, ang); #ifdef KEEP_ROLL - ang = AnglesTransform_Normalize(ang, TRUE); + ang = AnglesTransform_Normalize(ang, TRUE, pitchmin, pitchmax); ang = AnglesTransform_CancelRoll(ang); ang_z = roll; #else - ang = AnglesTransform_Normalize(ang, FALSE); + ang = AnglesTransform_Normalize(ang, FALSE, pitchmin, pitchmax); #endif return ang; @@ -548,7 +548,7 @@ vector WarpZone_UnTransformVAngles(entity wz, vector ang) ang_z = 0; ang = AnglesTransform_ApplyToVAngles(AnglesTransform_Invert(wz.warpzone_transform), ang); - ang = AnglesTransform_Normalize(ang, TRUE); + ang = AnglesTransform_Normalize(ang, TRUE, -90, 90); ang = AnglesTransform_CancelRoll(ang); ang_z = roll; @@ -742,7 +742,7 @@ vector WarpZone_RefSys_TransformVAngles(entity from, entity to, vector ang) if(from.WarpZone_refsys) ang = WarpZone_UnTransformVAngles(from.WarpZone_refsys, ang); if(to.WarpZone_refsys) - ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang); + ang = WarpZone_TransformVAngles(to.WarpZone_refsys, ang, -90, 90); return ang; } void WarpZone_RefSys_Copy(entity me, entity from) diff --git a/qcsrc/warpzonelib/common.qh b/qcsrc/warpzonelib/common.qh index c79ee95d6..9b5041212 100644 --- a/qcsrc/warpzonelib/common.qh +++ b/qcsrc/warpzonelib/common.qh @@ -55,7 +55,7 @@ float WarpZone_TargetPlaneDist(entity wz, vector v); vector WarpZone_TransformOrigin(entity wz, vector v); vector WarpZone_TransformVelocity(entity wz, vector v); vector WarpZone_TransformAngles(entity wz, vector v); -vector WarpZone_TransformVAngles(entity wz, vector v); +vector WarpZone_TransformVAngles(entity wz, vector v, float pitchmin, float pitchmax); vector WarpZone_UnTransformOrigin(entity wz, vector v); vector WarpZone_UnTransformVelocity(entity wz, vector v); vector WarpZone_UnTransformAngles(entity wz, vector v); diff --git a/qcsrc/warpzonelib/server.qc b/qcsrc/warpzonelib/server.qc index 25bcd2901..055faf801 100644 --- a/qcsrc/warpzonelib/server.qc +++ b/qcsrc/warpzonelib/server.qc @@ -57,7 +57,7 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1) o10 = o1 = WarpZone_TransformOrigin(wz, o0); v1 = WarpZone_TransformVelocity(wz, v0); if not(IS_NOT_A_CLIENT(player)) - a1 = WarpZone_TransformVAngles(wz, player.v_angle); + a1 = WarpZone_TransformVAngles(wz, player.v_angle, player.cvar_in_pitch_min, player.cvar_in_pitch_max); else a1 = WarpZone_TransformAngles(wz, a0); @@ -897,7 +897,7 @@ void WarpZone_PlayerPhysics_FixVAngle(void) if(self.v_angle_z <= 360) // if not already adjusted if(time - self.ping * 0.001 < self.warpzone_teleport_time) { - self.v_angle = WarpZone_TransformVAngles(self.warpzone_teleport_zone, self.v_angle); + self.v_angle = WarpZone_TransformVAngles(self.warpzone_teleport_zone, self.v_angle, self.cvar_in_pitch_min, self.cvar_in_pitch_max); self.v_angle_z += 720; // mark as adjusted } #endif -- 2.39.2