From 9040abf97c51cc3c9a0b0ac4320d721f9977f465 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 26 Jun 2025 16:55:13 +0300 Subject: [PATCH] Better code readability. --- 2D GFX/Presentations/AI/AI demo.bas | 45 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/2D GFX/Presentations/AI/AI demo.bas b/2D GFX/Presentations/AI/AI demo.bas index be9f839..138ecaa 100644 --- a/2D GFX/Presentations/AI/AI demo.bas +++ b/2D GFX/Presentations/AI/AI demo.bas @@ -194,44 +194,43 @@ drawEdges: finishPolygon: END SUB - -SUB GetAngle (xOne, yOne, xTwo, yTwo, angleOutput) +SUB GetAngle (point1X, point1Y, point2X, point2Y, angleBetween) ' -' Computes an angle in radians between two points (xOne,yOne) and (xTwo,yTwo). -' The result is stored in angleOutput. Used for 2D rotation or orientation logic. +' Calculates the angle between two 2D points in radians. +' Used for rotation calculations in 3D rendering. ' - IF yOne = yTwo THEN - IF xTwo > xOne THEN - angleOutput = globalPi / 2 + IF point1Y = point2Y THEN + IF point2X > point1X THEN + angleBetween = globalPi / 2 ELSE - angleOutput = globalPi * 1.5 + angleBetween = globalPi * 1.5 END IF - GOTO skipLogic + GOTO skipSpecialCases END IF - IF yTwo > yOne THEN - IF xTwo = xOne THEN - angleOutput = globalPi - GOTO skipLogic + IF point2Y > point1Y THEN + IF point2X = point1X THEN + angleBetween = globalPi + GOTO skipSpecialCases END IF - IF xTwo > xOne THEN - angleOutput = (globalPi * 1) - ATN((xTwo - xOne) / (yTwo - yOne)) + IF point2X > point1X THEN + angleBetween = (globalPi * 1) - ATN((point2X - point1X) / (point2Y - point1Y)) ELSE - angleOutput = globalPi + ATN((xOne - xTwo) / (yTwo - yOne)) + angleBetween = globalPi + ATN((point1X - point2X) / (point2Y - point1Y)) END IF ELSE - IF xTwo = xOne THEN - angleOutput = 0 - GOTO skipLogic + IF point2X = point1X THEN + angleBetween = 0 + GOTO skipSpecialCases END IF - IF xTwo > xOne THEN - angleOutput = ATN((xTwo - xOne) / (yOne - yTwo)) + IF point2X > point1X THEN + angleBetween = ATN((point2X - point1X) / (point1Y - point2Y)) ELSE - angleOutput = globalPi * 2 - ATN((xOne - xTwo) / (yOne - yTwo)) + angleBetween = globalPi * 2 - ATN((point1X - point2X) / (point1Y - point2Y)) END IF END IF -skipLogic: +skipSpecialCases: END SUB -- 2.20.1