From 70f6e172a11cd7496de8c254dbf228baec1a743f Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 16 Oct 2013 23:16:39 +0200 Subject: [PATCH] Fix pitch logic. --- qcsrc/warpzonelib/anglestransform.qc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/qcsrc/warpzonelib/anglestransform.qc b/qcsrc/warpzonelib/anglestransform.qc index 6aea44591..a3df93afa 100644 --- a/qcsrc/warpzonelib/anglestransform.qc +++ b/qcsrc/warpzonelib/anglestransform.qc @@ -108,7 +108,25 @@ vector AnglesTransform_Normalize(vector t, float pitchmin, float pitchmax) 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); + + // Want to achieve: + // after t_x' = 180 - t_x or -180: + // t_x' <= pitchmax && t_x' >= pitchmin + // ASSUME t_x >= 0: + // 180 - t_x <= pitchmax && 180 - t_x >= pitchmin + // t_x >= 180-pitchmax && t_x <= 180-pitchmin + // GUARANTEED + // t_x >= 180-pitchmax + // ASSUME t_x < 0: + // -180 - t_x <= pitchmax && -180 - t_x >= pitchmin + // t_x >= -180-pitchmax && t_x <= -180-pitchmin + // GUARANTEED + // t_x <= -180-pitchmin + // So good after flip means: + // t_x >= 0 ? t_x >= 180-pitchmax : t_x <= -180-pitchmin + // t_x outside -180-pitchmin .. 180-pitchmax + + need_flip = (t_x <= -180 - pitchmin || t_x >= 180 - pitchmax); // NOTE: Is this the right decision or should it be > and