Rotating PDC images - Alloy SDK

Hello all, I’ve been struggling with this for the past week and I can’t seem to find a solution. Basically I want to rotate a PDC image around a fixed point. According to the rather limited documentation, rotating a PDC is EASY:

render.drawDCI(pdc.clone().rotate(angle, px, py), x, y)

Where:
pdc is the original PDC file you want to rotate and render
angle is the angle in radians
px is the x pivot point. related to the images coordinates not the screen (I had to learn that on my own)
py is the y pivot point, similar to px
x coordinate passed to drawDCI - normally specified the x coordinate where the drawing will be rendered
y coordinate passed to drawDCI, similar to py

However, as I soon learned, rotating a PDC this way is anything but easy, especially if you want to rotate the image form a specific location in the screen.

First naiive attempt: for my reference watchhand, I want it to stay in the same position but rotated 30 degrees left. I went ahead and used 1/2 * pdc.width for px and pdc.height for py thinking this would result in an image that’s rotated from a pivot point at the half point (horizontally) and lower (vertically) position.

Run the code and it turns out, the PDC rendered outside of the screen’s boundaries!

And how am I so certain the PDC rendered out of bounds and there was NOT an error on my code?
Well, I tried using 0, 0 as px and py values and this is the result:

I made a whole bunch of tests on my github with varying results. I still have no idea how to get the image to rotate just the way I want it to. If you decide to clone my repo, modify the TESTCASE variable to test each of the things I’ve tried so far.

TLDR: You can use PIU to simulate the movement of clockhands for your pebble watchface
me: That’s not what’s being asked, is it?

Any help would be greatly appreciated :slight_smile:

1 Like