Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxPoint.pivotRadians is not working correctly #2698

Closed
SeiferTim opened this issue Dec 14, 2022 · 0 comments · Fixed by #2700
Closed

FlxPoint.pivotRadians is not working correctly #2698

SeiferTim opened this issue Dec 14, 2022 · 0 comments · Fixed by #2700

Comments

@SeiferTim
Copy link
Member

  • Haxe version: 4.2.5
  • Flixel version: 5.0.2
  • OpenFL version: 9.2.0
  • Lime version: 8.0.0
  • Affected targets: All

Code snippet reproducing the issue:

public function new()
 {
  super();

  var angle:Float = 0;

  trace("point", "[0, 50]");
  trace("pivot", "[50, 50]");

  for (a in 0...8)
  {
   angle = a * 45;

   trace("angle", angle);

   trace("example", myPivotFunction(FlxPoint.get(0, 50), FlxPoint.get(50, 50), angle));
   trace("flx", FlxPivot(FlxPoint.get(0, 50), FlxPoint.get(50, 50), angle));
   trace("----");
  }
 }

 function myPivotFunction(Point:FlxPoint, Pivot:FlxPoint, Angle:Float):FlxPoint
 {
  var newPoint:FlxPoint = FlxPoint.get();

  newPoint.x = Math.cos(Angle * FlxAngle.TO_RAD) * (Point.x - Pivot.x) - Math.sin(Angle * FlxAngle.TO_RAD) * (Point.y - Pivot.y) + Pivot.x;
  newPoint.y = Math.sin(Angle * FlxAngle.TO_RAD) * (Point.x - Pivot.x) + Math.cos(Angle * FlxAngle.TO_RAD) * (Point.y - Pivot.y) + Pivot.y;

  return newPoint;
 }

 function FlxPivot(Point:FlxPoint, Pivot:FlxPoint, Angle:Float):FlxPoint
 {
  return Point.pivotDegrees(Pivot, Angle);
 }

Observed behavior:

FlxPoint.pivotRadians (and pivotDegrees) is not "rotating a point around a pivot by x amount clockwise", it is SETTING the point's position to x degrees/radians around the pivot.

For example:
If you have a point at (0, 50) and want to rotate it 90 degrees clockwise around a pivot (50, 50) it should end up at (50, 0): at -90 degrees
Instead, pivotDegrees is recalibrating the point to be at (100, 50) before setting it's angle and it ends up at (50, 100): 90 degrees.

Expected behavior:
pivotRadians should not be "resetting" the point to angle = 0 from pivot before applying the new rotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant