From: Rudolf Polzer Date: Wed, 16 Oct 2013 05:14:58 +0000 (+0200) Subject: Simplify. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=43a61d7b4a8e63e6b7c22592950ffcbf97e68a37;p=xonotic%2Fxonotic-data.pk3dir.git Simplify. --- diff --git a/qcsrc/server/vehicles/spiderbot.qc b/qcsrc/server/vehicles/spiderbot.qc index 89772b77d..b21a05e3a 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, -90, 90); + ad = AnglesTransform_Normalize(ad, -360, 360); //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 03dda94e0..72e5fd49b 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, _pichlimit_min, _pichlimit_max); + vtmp = AnglesTransform_Normalize(vtmp, -360, 360); 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 650cf314b..6aea44591 100644 --- a/qcsrc/warpzonelib/anglestransform.qc +++ b/qcsrc/warpzonelib/anglestransform.qc @@ -94,35 +94,30 @@ 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, float pitchmin, float pitchmax) +vector AnglesTransform_Normalize(vector t, float pitchmin, float pitchmax) { float need_flip; // first, bring all angles in their range... t_x = t_x - 360 * rint(t_x / 360); t_y = t_y - 360 * rint(t_y / 360); t_z = t_z - 360 * rint(t_z / 360); - if(minimize_roll) - need_flip = (t_z > 90 || t_z <= -90); + // 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 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 - } + // Roll is ok. Prefer not flipping. + need_flip = (t_x > pitchmax || t_x < pitchmin); + // for pitch we prefer to allow exactly the border angles degrees for looking straight down } if(need_flip) { diff --git a/qcsrc/warpzonelib/anglestransform.qh b/qcsrc/warpzonelib/anglestransform.qh index f3fdd8320..5294eb374 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, 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_Normalize(vector t, 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/common.qc b/qcsrc/warpzonelib/common.qc index d216b7f0a..83f8e2041 100644 --- a/qcsrc/warpzonelib/common.qc +++ b/qcsrc/warpzonelib/common.qc @@ -515,11 +515,11 @@ vector WarpZone_TransformVAngles(entity wz, vector ang, float pitchmin, float pi ang = AnglesTransform_ApplyToVAngles(wz.warpzone_transform, ang); #ifdef KEEP_ROLL - ang = AnglesTransform_Normalize(ang, TRUE, pitchmin, pitchmax); + ang = AnglesTransform_Normalize(ang, -360, 360); ang = AnglesTransform_CancelRoll(ang); ang_z = roll; #else - ang = AnglesTransform_Normalize(ang, FALSE, pitchmin, pitchmax); + ang = AnglesTransform_Normalize(ang, 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, -90, 90); + ang = AnglesTransform_Normalize(ang, -360, 360); ang = AnglesTransform_CancelRoll(ang); ang_z = roll;