Challenge rotating around a point

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Challenge rotating around a point

Post by pgimeno »

darkfrei wrote: Wed Jan 12, 2022 9:22 am And if I need the scale too?
Apply it with the rotation. Doesn't matter if before or after rotating [edit: to clarify, it doesn't matter assuming you're scaling by the same amount in both axes; otherwise it does matter]
JimOfLeisure
Prole
Posts: 9
Joined: Wed Dec 29, 2021 8:01 pm

Re: Challenge rotating around a point

Post by JimOfLeisure »

zorg wrote: Wed Jan 12, 2022 12:49 pmYou move the coordinate system instead of the object, basically; the result of that first transform is going to be that (0,0) will be at the point of rotation; since the rotate function rotates around (0,0), it will now work fine.
I guess I was thinking subsequent translate and rotate statements were expressed in the "new" coordinate system, but they seem to all be in the original coordinate system. Except...
darkfrei wrote: Wed Jan 12, 2022 9:22 am And if I need the scale too?
I just tried it out expecting it to work anywhere, but it only works between the two translations, either before or after the rotation. I just threw in a `scale(2)` for testing.

That confuses me a bit because I thought I just learned that all translate coordinates were in the original coordinate system, but scale would seem to be creating a new coordinate system for subsequent transforms. (Well, new scaling, same origin I think.)

Attaching the updated .love file with the rotation fix and some other improvements if anyone wants to try placing a scale in places in the camera. (It's also updated now in the Itch link I posted earlier.)

Edit: Oh, didn't notice that pgimeno had replied re: the scale, because it went to thread page 2. So cross-posted.
Attachments
bumpy-road.love
(31.22 KiB) Downloaded 40 times
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Challenge rotating around a point

Post by pgimeno »

JimOfLeisure wrote: Wed Jan 12, 2022 6:08 pm That confuses me a bit because I thought I just learned that all translate coordinates were in the original coordinate system, but scale would seem to be creating a new coordinate system for subsequent transforms. (Well, new scaling, same origin I think.)
If you scale e.g. 2x before translating, the translation position needs to be halved in order to be in the same place, so you'd need to compensate by dividing x_offset and y_offset by 2. Remember what Zorg said about the axes. If you scale the axes 2x, the desired position is now at half the original coordinate.
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests