From 57ed4df85eeddad8483d9f099abb2478caee7034 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Aug 2018 20:47:56 +0200 Subject: [PATCH] - fixed FraggleScript's moving camera. The logic here was a bit more complicated than I assumed but it was all buried in a heap of code that tried to deal with angular wraparounds in the BAM format. --- src/fragglescript/t_func.cpp | 58 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 85b6e726d..6e37b7a16 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -2885,44 +2885,62 @@ void FParser::SF_MoveCamera(void) } double targetheight = floatvalue(t_argv[2]); + double movespeed = floatvalue(t_argv[3]); DVector3 campos = cam->Pos(); DVector3 targpos = DVector3(target->Pos(), targetheight); + DVector3 movement = targpos - campos; + double movelen = movement.Length(); + + bool finishedmove = false; + bool finishedangle = false; + + cam->radius = 1 / 8192.; + cam->Height = 1 / 8192.; + if (campos != targpos) { - DVector3 movement = targpos - campos; - double movelen = movement.Length(); - double movespeed = floatvalue(t_argv[3]); DVector3 movepos; - bool finished = (movespeed >= movelen); - if (finished) movepos = targpos; + finishedmove = (movespeed >= movelen); + if (finishedmove) movepos = targpos; else movepos = campos + movement.Resized(movespeed); + cam->SetOrigin(movepos, true); + } - DAngle targetangle = floatvalue(t_argv[4]); + DAngle targetangle = DAngle(floatvalue(t_argv[4])).Normalized360(); + if (cam->Angles.Yaw != targetangle) + { DAngle anglespeed = floatvalue(t_argv[5]); + DAngle anglenow = targetangle; + const DAngle diffangle = deltaangle(cam->Angles.Yaw, targetangle); if (movespeed > 0 && anglespeed == 0.) { - if (!finished) + if (!finishedmove) { - const DAngle diffangle = targetangle - cam->Angles.Yaw; - targetangle = cam->Angles.Yaw + diffangle * movespeed / movelen; + anglenow = cam->Angles.Yaw + diffangle * movespeed / movelen; } + else finishedangle = true; } else { - targetangle = cam->Angles.Yaw + anglespeed; + if (diffangle > 0) + { + anglenow = (cam->Angles.Yaw + anglespeed).Normalized360(); + } + else + { + anglenow = (cam->Angles.Yaw - anglespeed).Normalized360(); + } + const DAngle diffangle2 = deltaangle(anglenow, targetangle); + if (diffangle.Degrees * diffangle2.Degrees <= 0) + { + anglenow = targetangle; + finishedangle = true; + } } - - cam->radius = 1 / 8192.; - cam->Height = 1 / 8192.; - cam->SetOrigin(movepos, true); - cam->SetAngle(targetangle, false); - t_return.value.i = 1; - } - else - { - t_return.value.i = 0; + cam->SetAngle(anglenow, false); } + t_return.value.i = !(finishedmove & finishedangle); t_return.type = svt_int; } }