-
Notifications
You must be signed in to change notification settings - Fork 450
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
Update FlxPoint pivotRadians to proper order of operations #2700
Update FlxPoint pivotRadians to proper order of operations #2700
Conversation
@SeiferTim You mentioned in the discord that this doesn't fix #2698. It seems like there are multiple issues, here. to me this change makes sense but let me know what issues you're seeing, Tim We're in a unique position here, anyone using the old |
also, fun fact I broke this when deprecating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be working completely as I would expect, everything is good except it should say "clockwise" instead of "counter-clockwise"
Screen.Recording.2022-12-15.at.2.19.29.PM.mov
as for Tim's concern:
he problem with the old method was simply that no matter where point is in relation to pivot when you call pivot*, it treats it as if it's at 0 degrees from pivot first...
I'm simply not seeing it, as evident by the example above, for which I'll provide the source:
package states;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
class PivotTestState extends flixel.FlxState
{
var sprite:FlxSprite;
var pivot:FlxPoint;
var p:FlxPoint;
override function create()
{
super.create();
p = FlxPoint.get(0, 50);
pivot = FlxPoint.get(50, 50);
trace('$p @ ${(p - pivot).degrees)}');
for (i in 0...8)
{
p.pivotDegrees(pivot, 45);
trace('$p @ ${(p - pivot).degrees)}');
}
/* output (beautified):
* (x: 0.000 | y: 50.000 ) @ 180
* (x: 85.355 | y: 85.355 ) @ -135
* (x: 50.000 | y: 0.000 ) @ -90
* (x: 14.645 | y: 85.355 ) @ -45
* (x: 100.000 | y: 50.000 ) @ 0
* (x: 14.645 | y: 14.645 ) @ 45
* (x: 50.000 | y: 100.000 ) @ 90
* (x: 85.355 | y: 14.645 ) @ 135
* (x: 0.000 | y: 50.000 ) @ 180
**/
pivot.set(FlxG.width / 2, FlxG.height / 2);
var pivotSprite = new FlxSprite().makeGraphic(6, 6, 0xFF0000ff);
pivotSprite.x = pivot.x - pivotSprite.origin.x;
pivotSprite.y = pivot.y - pivotSprite.origin.y;
add(pivotSprite);
p.set(pivot.x + 100, pivot.y);
sprite = new FlxSprite().makeGraphic(50, 50, 0xFFff0000);
sprite.x = p.x - sprite.origin.x;
sprite.y = p.y - sprite.origin.y;
add(sprite);
}
override function update(elapsed)
{
super.update(elapsed);
p.pivotDegrees(pivot, 360 * elapsed);
sprite.x = p.x - sprite.origin.x;
sprite.y = p.y - sprite.origin.y;
}
}
Updates FlxPoint pivotRadians math which was calculating the rotation point improperly.
Fixes #2698
Old:
point
frompivot
pivot
to resultNew:
pivot
frompoint
pivot
to resultI also updated the doc comments to specify "Counter-clockwise" as the use of cos and sin functions are counter-clockwise. Comparing behavior to the 4.11.0 branch, this is consistent with the behavior there despite that branch also specifying "clockwise"