Page 2 of 2

Re: Challenge rotating around a point

Posted: Wed Jan 12, 2022 2:55 pm
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]

Re: Challenge rotating around a point

Posted: Wed Jan 12, 2022 6:08 pm
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.

Re: Challenge rotating around a point

Posted: Wed Jan 12, 2022 7:02 pm
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.