## Creating physics based on image rotation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

### Creating physics based on image rotation

Hi all,

I'm working on a project where a parent object creates children which are its physics. Each child is 16x16 and I loop through the image data of the parent to create their offsets. However, I canot seem to make these children align with their parent's rotation properly at all. I'd rather not hard code any of the rotations so that if I were to add other objects to rotate that it would be universal and easy to deal with.

Attached is the .love file of the game currently.
Attachments
Senior Project.love

ivan
Party member
Posts: 1619
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Creating physics based on image rotation

I don't quite understand your post, but based on the .love file you have,
will assume that you're asking "why isn't the L shape rotating like in the classic Tetris".
One simple thing I would suggest - instead of manually rotating each piece in realtime using math,
just pre-generate all possible rotations and swap them when a key is pressed.

pgimeno
Party member
Posts: 2340
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Creating physics based on image rotation

It seems to me that your problem is the pivot point for the rotation. Is that right?

If so, you probably want to find the centre of the bounding box to use it as the rotation's pivot. In the cases where the bounding box's centre lies on the middle of an edge (which for tetrominoes, is in all cases except the 2x2) you will need first to extend the bounding box so that all sides have the same parity (all odd or all even).

Let me elaborate.
• The bounding box of the "T", the "L" and the "S" tetrominoes is 2x3. 2 and 3 have different parity (2 is even and 3 is odd). In such cases, rotating around the bounding box's centre causes the rotated figure to be misaligned with the grid. That can be corrected by extending the bounding box to be either 2x4 (not recommended) or 3x3 (recommended), so that both dimensions have the same parity.
• Similarly, the "I" tetromino's bounding box is 1x4, and since 1 and 4 have different parity, you need to correct that by extending the bounding box to either 2x4 (not recommended) or 1x5 (recommended), so that both are the same parity.
• The square tetromino is 2x2; since 2 and 2 have the same parity (both even), no adjustment is necessary for that one.
I haven't read your code, but I hope you can figure out how to rotate around a given pivot point.

### Who is online

Users browsing this forum: Google [Bot] and 26 guests